Search code examples
c#flvkeyframe

Extract keyframe from flv using C#


Is there a way to extract a keyframe from flv file using C#?


Solution

  • Can't find a direct way of doing this.

    However you can use FFmpeg.exe in C#.

    Here you can find a C# wrapper to easily use FFmpeg in C#:

    http://www.ffmpeg-csharp.com/

    The following code is taken from their sample page. Seems like you can extract frames and create thumbnails from them in the following manner:

    CAVConverter converter = new CAVConverter();
    //...
    

    Use converter.AVPrope.Decode(-1) to decode the next frame and converter.AVPrope.CurrentPicture to get the thumbnail picture. Use converter.AVPrope.SaveCurrentFrame(fileName) to save current frame to the file fileName.

    //Load the file
    converter.AVPrope.LoadFile(fileName, "");
    //Decode the frame converter.AVPrope.Decode(-1);
    //Get the thumbnail picture. It is a IPictureDisp object, do something as you need.
    var thumbnail = converter.AVPrope.CurrentPicture;
    //Save current frame to file fileName
    converter.AVPrope.SaveCurrentFrame(fileName);
    

    Hope it helps.