How to do YUV resolution conversion-FFMPEG implementation YUV,RGB conversion between various image raw data (Swscale)

Source: Internet
Author: User
the Swscale in FFmpeg provides the video raw data (Yuv420,yuv422,yuv444,rgb24 ... Conversion, resolution transformation and other operations, it is very convenient to use, here to record its usage. The Swscale is primarily used to convert between 2 avframe. Here is a simple video decoding example, this program completed the "Beijing Mobile Developer Conference Coffee break Video 2.flv" (In fact, Youku, a normal video) decoding work, and to save the decoded data as the original data files (such as YUV420,YUV422,RGB24, etc.). It omits a lot of code. Note: Complete code in the article: 100 lines of code to implement the simplest ffmpeg+sdl based video player

[CPP]  View Plain  copy//ffmpeg simple player  //  //Media Resources Retrieval System subsystem   //   //2013  lei Hua  leixiaohua1020@126.com  //Communication University/Digital TV   //   # include  "stdafx.h"       int _tmain (int argc, _tchar* argv[])     {       AVFormatContext *pFormatCtx;        int             i, videoindex;        AVCodecContext  *pCodecCtx;        avcodec         *pcodec;       char  filepath[]= "Beijing Mobile developer Conference tea break Video 2.flv";       av_register_all ();        avformat_network_init ();       pformatctx = avformat_ AlLoc_context ();       if (Avformat_open_input (&pformatctx,filepath,null,null)! = 0) {           printf ("Cannot open file \ n");            return -1;       }               ......                  AVFrame *pFrame,*pFrameYUV;            pframe=avcodec_alloc_frame ();            pframeyuv=avcodec_alloc_frame ();           uint8_ t *out_buffer;              out_buffer=new  uint8_t[avpicture_get_size (pix_fmt_rgb24, pcodecctx->width, pcodecctx->height)];            avpicture_fill ((avpicture *) pframeyuv, out_buffer, pix_ Fmt_rgb24, pcodecctx->width, pcodecctx->height);  /*           out_buffer=new uint8_t[avpicture_get_size (pix_fmt_yuv420p, pcodecctx-> Width, pcodecctx->height)];          avpicture_fill ( avpicture *) pframeyuv, out_buffer, pix_fmt_yuv420p, pcodecctx->width, pcodecctx- >height);*/     /*          out_buffer=new  uint8_t[avpicture_get_size (pix_fmt_uyvy422, pcodecctx->width, pcodecctx->height)];          avpicture_fill (avpicture *) PFrameYUV, out_buffer,  pix_fmt_uyvy422, pcodecctx->width, pcodecctx->height);           Out_buffer=new uint8_t[avpicture_get_size (pix_fmt_yuv422p, pcodecctx->width, pcodecctx-> Height)];          avpicture_fill ((avpicture *) PFrameYUV,  out_buffer, pix_fmt_yuv422p, pcodecctx->width, pcodecctx->height);*/                       ......                       file *output=fopen ("Out.rgb", "wb+");            //------------------------------           while ( Av_read_frame (pformatctx, packet) >=0)            {   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.