rosenbjerg / FFMpegCore

A .NET FFMpeg/FFProbe wrapper for easily integrating media analysis and conversion into your C# applications
MIT License
1.63k stars 295 forks source link

Join image sequence behaving oddly #425

Open SbiCA opened 1 year ago

SbiCA commented 1 year ago

Hi @rosenbjerg ,

I've tried to use the with a frame rate of 1 but somehow if I put in 3 or 4 images it only takes the first two. I've uploaded a report here https://github.com/SbiCA/ffmpeg-repro (it includes all the assets)

I checked the following things:

None of the things worked šŸ„²

FFMpegCore.FFMpeg.JoinImageSequence("out.mp4", 1, "0.png", "1.png", "2.png", "3.png");

In addition I checked the tests and there is one for this scenario but if I adjust the frame rate from 10 to 5, I would expect the duration to double, right? so it should be 2s. In addition what I don't understand about that test it gets an input of 30 images with a frame rate of 10, so my expectation would be a 3s video in the first place šŸ¤”

[TestMethod, Timeout(2 * BaseTimeoutMilliseconds)]
        public void Video_Join_Image_Sequence()
        {
            var imageSet = new List<string>();
            Directory.EnumerateFiles(TestResources.ImageCollection, "*.png")
                .ToList()
                .ForEach(file =>
                {
                    for (var i = 0; i < 5; i++)
                    {
                        imageSet.Add(file);
                    }
                });
            var imageAnalysis = FFProbe.Analyse(imageSet.First());

            using var outputFile = new TemporaryFile("out.mp4");
            // changed from 10 => 5
            var success = FFMpeg.JoinImageSequence(outputFile, frameRate: 5, images: imageSet.ToArray());
            Assert.IsTrue(success);
            var result = FFProbe.Analyse(outputFile);

            // changed from 1 => 2
            Assert.AreEqual(2, result.Duration.Seconds);
            Assert.AreEqual(imageAnalysis.PrimaryVideoStream!.Width, result.PrimaryVideoStream!.Width);
            Assert.AreEqual(imageAnalysis.PrimaryVideoStream!.Height, result.PrimaryVideoStream.Height);
        }

Cheers

LucasBicaEVR commented 9 months ago

Do you resolved it? I have the same issue.

SbiCA commented 8 months ago

@LucasBicaEVR I ended up doing

// get all the files matching the pattern
 var files = Path.Combine(folderPath, "%02d.png");

// call ffmeg with custom arguments
 await FFMpegArguments
            .FromFileInput(files, false, options =>
            {
                options.WithCustomArgument("-framerate 1");
                options.WithCustomArgument("-pix_fmt yuv420p");

            })
            .OutputToFile(soundlessVideo, true, options =>
            {
                options.WithCustomArgument("-vcodec libx264");
                options.WithCustomArgument("-crf 25");
            })
            .ProcessAsynchronously();

cc @rosenbjerg