[Libav-user] Save frame to jpg with data from avcodec_decode_video2
Misha Penkov
misha.penkov at gmail.com
Tue Jun 26 09:10:26 CEST 2012
On 26 June 2012 15:18, 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) {
One thing you could do here would be to link with a JPEG library (like
http://www.ijg.org/) and use that to write your JPEGs. Any other
library that handles JPEG writing will also work. There may be a way
to do it without external libraries, but I've never had to go down
that path.
> }
>
> }
> }
>
>
> This is with ffmpeg 0.11.1.
>
> Thanks!
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
More information about the Libav-user
mailing list