Click here to Skip to main content
15,881,757 members
Articles / Programming Languages / C++
Alternative
Tip/Trick

FFmpeg Tutorial

Rate me:
Please Sign up or sign in to vote.
4.00/5 (2 votes)
23 Sep 2010CPOL1 min read 26.7K   11   1
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,...
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.)
C#
if(frameFinished) {
  img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24,
                (AVPicture*)pFrame, pCodecCtx->pix_fmt, pCodecCtx->width,
                pCodecCtx->height);


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:

C#
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());
                    exit(1);
                }
            }
            sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, is->pFormatCtx->streams[is->videoStream]->codec->height, pict.data,pict.linesize);


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

License

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


Written By
India India
http://gputoaster.wordpress.com/about

Comments and Discussions

 
Questionswscaler Pin
hoseinhero16-Feb-13 23:02
hoseinhero16-Feb-13 23:02 
Hello. how can I configure swscaler in vs2012?

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.