FFMPEG implementation of transcoding program __ffmpeg

Source: Internet
Author: User

This example is modified by Ffempg's doc/example example transcode.c, which can be used to convert audio and video codes as needed.


The original example of the role is more similar to the Remux, and did not realize the function of transcoding, only to achieve the format conversion, such as TS to AVI. Can not realize the conversion of audio and video coding format, such as H264 to MPEG2.


There are several ways to implement FFmpeg transcoding:

One way is: Streaming multiplexing-> video + audio streaming-> decoding->YUV/PCM-> video audio coding-> regenerated audio and video stream-> multiplexing-> stream

Another way to rely on Avfilter is to explain how to use it in a few other articles. Although Avfilter may be difficult to learn, but in practical programming applications, relying on avfilter to do transcoding efficiency is higher than the first way, and decoding the CPU and time consumption is much less. Therefore, it is advisable to study this part, after all, I have always felt that FFmpeg's strength is decoding and transcoding.



This example is video MPEG2 turn h264, audio Mpegaudio to g711.

[CPP]  View plain copy print? /*  * based on ffmpeg transcode.c  * modified by tongli  *    #include  <stdio.h>   #include   "snprintf.h"    extern  "C"    {   #include  <libavcodec/avcodec.h>   #include  <libavformat/ avformat.h>   #include  <libavfilter/avfiltergraph.h>   #include  < libavfilter/avcodec.h>   #include  <libavfilter/buffersink.h>   #include   <libavfilter/buffersrc.h>   #include  <libavutil/opt.h>   #include  < libavutil/pixdesc.h>  }   static avformatcontext *ifmt_ctx;   Static  AVFormatContext *ofmt_ctx;   typedef struct filteringcontext {       AVFilterContext *buffersink_ctx;       AVFilterContext *buffersrc_ctx;       avfiltergraph *filter _graph;  } filteringcontext;   static filteringcontext *filter_ctx;       static int open_input_file (const char *filename)    {        int ret;       unsigned int i;           ifmt_ctx = NULL;       if   ((Ret = avformat_open_input (&ifmt_ctx, filename, null, null))  <  0)  {           av_log (Null, av_log_error,   "cannot open input file\n");            return ret;       }          if  ( (Ret =&nbsP;avformat_find_stream_info (ifmt_ctx, null)  < 0)  {            av_log (null, av_log_error,  "cannot find stream information\n") );           return ret;        }          for  (i = 0; i < ifmt_ ctx->nb_streams; i++)  {           AVStream  *stream;           AVCodecContext *codec_ctx;            stream = ifmt_ctx->streams[i];           codec_ctx = stream->codec;  

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.