Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

Go to top

FFmpeg Tutorial

, 23 Sep 2010
Rate this:
Please Sign up or sign in to vote.
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.)
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:
 
 
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)

Share

About the Author

GPUToaster™
Other
India India
http://gputoaster.wordpress.com/about
Follow on   Twitter

Comments and Discussions

 
Questionswscaler Pinmemberhoseinhero16-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    Rant Rant    Admin Admin   

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 23 Sep 2010
Article Copyright 2010 by GPUToaster™
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid