Click here to Skip to main content
15,126,221 members
Articles / Programming Languages / C++
Posted 23 Sep 2010

Tagged as


11 bookmarked

FFmpeg Tutorial

Rate me:
Please Sign up or sign in to vote.
4.00/5 (2 votes)
23 Sep 2010CPOL1 min read
Hi,VB 6.0 is dead. And if you want to use them in your VS 2008/2010 Environment then you cannot use(The same is also mentioned in Dranger's Tutorials.)if(frameFinished) { img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24, (AVPicture*)pFrame, pCodecCtx->pix_fmt,...

VB 6.0 is dead. And if you want to use them in your VS 2008/2010 Environment then you cannot use

(The same is also mentioned in Dranger's Tutorials.)
if(frameFinished) {
  img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24,
                (AVPicture*)pFrame, pCodecCtx->pix_fmt, pCodecCtx->width,

img_convert() is deprecated method since FFMPEG 0.5.* builds.

However there is an alternative to it. FFMPEG package comes with a SWScale library. To use swscalar you have to configure your compilation with
./configure --enable-gpl --enable-swscaler ...

About SWScale:
Swscale is mainly used for players, not encoding/decoding. It's necessary if you want to display the video at a different pixel size/aspect ratio than it was encoded at and you don't have hardware video scaling support. Swscale also performs colorspace conversion between various RGB and YUV color formats, and conversion between packed (all channels in a single buffer) and planar (each channel has its own buffer) formats. All of these routines are highly optimized; as far as I know, no faster software implementation presently exists for any of them, at least on x86 and x86_64.

Swscale also may be needed for encoding video, if the source video is not already in the format needed by the encoder. For instance, if your source video is RGB, you'll probably need to convert it to the appropriate YUV planar format, since most codecs work on YUV. This entails both colorspace conversion (an affine transformation of the R,G,B vectors) and actual scaling (resampling), since most YUV formats use half-resolution U and V planes (color planes) compared to the Y plane (luma, i.e. intensity data). Also the SWScaler library is accelerated by MMX instructions.
What is lib Swscale used for by ffmpeg programers?[^]

Here's a sample implementation:

struct  SwsContext *img_convert_ctx = NULL;
AVFormatContext *pFormatCtx = ...;
AVFrame pFrame = ... ;
AVPicture pict = ...;
if(img_convert_ctx == NULL)
                img_convert_ctx = sws_getContext(width,height, pFormatCtx->streams[...]->codec->pix_fmt , w, h, PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);

                if(img_convert_ctx == NULL)
                    fprintf(stderr, "ERROR- %s\n", SDL_GetError());
            sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, is->pFormatCtx->streams[is->videoStream]->codec->height,,pict.linesize);

You must have proper context to do all these operations. Rest is fine.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Comments and Discussions

Questionswscaler Pin
hoseinhero17-Feb-13 0:02
Memberhoseinhero17-Feb-13 0:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.