Working with images

Sometimes it is necessary to handle a lot of images and converting images to videos or vice versa. Changing video to images is possible thanks to ExtractEveryNthFrame:

Func outputFileNameBuilder = (number) => { return 'fileNameNo' + number + ".png"; };
IMediaInfo info = await FFmpeg.GetMediaInfo(Resources.MkvWithAudio).ConfigureAwait(false);
IVideoStream videoStream = info.VideoStreams.First()?.SetCodec(VideoCodec.Png);

IConversionResult conversionResult = await FFmpeg.Conversions.New()
    .AddStream(videoStream)
    .ExtractEveryNthFrame(10, outputFileNameBuilder)
    .Start();

Above code extracts every 10th frame from input video and saves it to the files: 'fileNameNo001.png', 'fileNameNo002.png' and so on until every 10th frame is saved. For example, if video has 26 frames, only 2 images is saved.

ExtractNthFrame can be used only if one frame is required:

Func outputFileNameBuilder = (number) => { return 'fileNameNo' + number + ".png"; };
IMediaInfo info = await FFmpeg.GetMediaInfo(Resources.MkvWithAudio).ConfigureAwait(false);
IVideoStream videoStream = info.VideoStreams.First()?.SetCodec(VideoCodec.Png);

IConversionResult conversionResult = await FFmpeg.Conversions.New()
    .AddStream(videoStream)
    .ExtractNthFrame(10, outputFileNameBuilder)
    .Start();

Above example creates file named 'fileNameNo001.png' containing 10th frame of a video.

BuildVideoFromImages is used to do oposite thing - changing collection of images to video:

List files = Directory.EnumerateFiles(Resources.Images).ToList();

await Conversion.New()
    .SetInputFrameRate(1)
    .BuildVideoFromImages(files)
    .SetFrameRate(1)
    .SetOutputPixelFormat(PixelFormat.Yuv420P)
    .SetOutput("outputfile.mp4")
    .Start();