[Libav-user] How can we extract frames from a video stream in MPEG-4 AVC format

Spencer Graffe sgraffe at gmail.com
Thu Apr 7 05:54:03 CEST 2011


The FFmpeg / SDL tutorial on FFmpeg's website on page 8 talks about how to
use sws_scale. sws_scale can convert practically anything to anywhere at any
resolution. MPEG-4 is most likely planar YUV, but in the context of
implementing it, it does not really matter.

To get a what's called a SwsContext, you call this:
swscontext = NULL;
swscontext = sws_getContext(sourceWidth, sourceHeight,
codecContext->pix_fmt, destWidth, destHeight, PIX_FMT_RGB24, SWS_BICUBIC,
NULL, NULL, 0);

Then you call sws_scale with your context. As you can see above, its not
required that you know exactly what the pixel format is of your video
because the codec context has the correct information for you. PIX_FMT_RGB24
is just one of many enum values that you can choose from (A common
alternative is using PIX_FMT_RGBA if you want to add an alpha channel). To
access your newly converted data, just use the allocated buffer you used for
the conversion frame, because whatever changes are made to the frame are
also made to the buffer. Make sure you read the tutorial first, though.



On Wed, Apr 6, 2011 at 7:26 PM, Amir Rouhi-Rmit <amir.rouhi at rmit.edu.au>wrote:

> Hi Grzegorz
> Thanks for introducing the useful links, it takes a little time to see
> weather it useful for my purpose (extracting frames) or not.
> regarding using sws_scale, i just wanted to know does it convert the MPEG-4
> format to raw formats: YUV or RGB? it seems this tools work for converting
> YUV to RGB
> Regards
> Amir
>
>
> On Thu, Apr 7, 2011 at 11:00 AM, Grzegorz Szpetkowski <
> gszpetkowski at gmail.com> wrote:
>
>> I am not FFmpeg API expert, but you can find working example
>> (avcodec_sample.0.5.0.c) at
>>
>> http://web.me.com/dhoerl/Home/Tech_Blog/Entries/2009/1/22_Revised_avcodec_sample.c.html
>>
>> There are also two guides that I know:
>> http://www.inb.uni-luebeck.de/~boehme/using_libavcodec.html (very
>> outdated)
>> http://dranger.com/ffmpeg/tutorial01.html (little outdated)
>>
>> To convert AVFrame from YUV to RGB you need to use sws_scale.
>>
>> Regards
>> Grzegorz Sz.
>>
>> 2011/4/7 Amir Rouhi-Rmit <amir.rouhi at rmit.edu.au>:
>> > Hi
>> >
>> > I would be pleased if somebody guide me how can I extract frames in
>> I-Frame
>> > format from a MPEG-4 AVC (H.264) video stream. The I-Frame can be:
>> >
>> > A- Any selected frame which can be extracted in form of a 1 frame video
>> > file. In this case the only frame of video should be in I-Frame.
>> >
>> > B- Extracting real I-Frames that exist in a video stream in form of  1
>> frame
>> > video files.
>> >
>> >
>> >
>> > I found a method myself for type A, which is based on converting video
>> to
>> > RAW format by YUVTOOLS software(If somebody help me that how can I
>> convert
>> > the video to YUV or RGB by ffmpeg or any free software I would be
>> pleased) ,
>> > and then I select any frame by its number and extract it as a 1 frame
>> video
>> > which is in I-Frame format by JM software. As you have noticed , this
>> method
>> > is very costy and take a long time. I hope by help of you I find a
>> method in
>> > ffmpeg filters to do that.
>> >
>> > Regards
>> >
>> > Amir
>> >
>> > _______________________________________________
>> > Libav-user mailing list
>> > Libav-user at ffmpeg.org
>> > http://ffmpeg.org/mailman/listinfo/libav-user
>> >
>> >
>> _______________________________________________
>> Libav-user mailing list
>> Libav-user at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/libav-user
>>
>
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
>


-- 
Spencer Graffe
- A Guy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20110406/3b610cf8/attachment.html>


More information about the Libav-user mailing list