[Libav-user] Save frame to jpg with data from avcodec_decode_video2

Alex Cohn alexcohn at netvision.net.il
Tue Jun 26 10:13:48 CEST 2012


On Tue, Jun 26, 2012 at 9:18 AM, Simon Daniels <simondaniels23 at gmail.com> wrote:
> Hey guys,
>
> I'm walking through frames of a video to do some analysis on the pixel data.
> I'd like to save each frame as an image so I can verify the analysis
> algorithm is running on the expected data.
>
> I don't want to use the ffmpeg command-line to save out the frames because
> for some reason the frame counts are not matching. Ffmpeg.exe saves more
> frame jpegs than avcodec_decode_video2 seems to find.
>
> Here's my code:
>
>
> while (av_read_frame(pFormatCtx, &packet) >= 0)
> {
>
> // Is this a packet from the video stream?
> if (packet.stream_index == videoStreamIndex &&
> (frameLocation++ % frameSkip == 0)
> )
> {
> // Decode video frame
> avcodec_decode_video2(pCodecCtx, pFrameYUV, &isFrameFinished, &packet);
>
> // Did we get a video frame?
> if (isFrameFinished) {
>
>              // I'D LIKE TO SAVE FRAME AS A JPEG HERE
>
> }
>
> }
> }
>
>
> This is with ffmpeg 0.11.1.
>
> Thanks!

See an old thread
http://libav-users.943685.n4.nabble.com/Save-AVFrame-to-jpg-file-td2314979.html

BR,
Alex Cohn


More information about the Libav-user mailing list