设为首页 加入收藏

TOP

FFmpeg封装格式处理:视音频复用器(muxer)(二)
2014-11-24 01:03:14 来源: 作者: 【 】 浏览:14
Tags:FFmpeg 封装 格式 处理 音频 复用器 muxer
v, 0)) < 0) {
  • printf( "Failed to retrieve input stream information");
  • goto end;
  • }
  •  
  • if ((ret = avformat_open_input(&ifmt_ctx_a, in_filename_a, 0, 0)) < 0) {
  • printf( "Could not open input file.");
  • goto end;
  • }
  • if ((ret = avformat_find_stream_info(ifmt_ctx_a, 0)) < 0) {
  • printf( "Failed to retrieve input stream information");
  • goto end;
  • }
  • printf("Input Information=====================\n");
  • av_dump_format(ifmt_ctx_v, 0, in_filename_v, 0);
  • av_dump_format(ifmt_ctx_a, 0, in_filename_a, 0);
  • printf("======================================\n");
  • //输出(Output)
  • avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, out_filename);
  • if (!ofmt_ctx) {
  • printf( "Could not create output context\n");
  • ret = AVERROR_UNKNOWN;
  • goto end;
  • }
  • ofmt = ofmt_ctx->oformat;
  • int videoindex_v=-1,videoindex_out=-1;
  • for (i = 0; i < ifmt_ctx_v->nb_streams; i++) {
  • //根据输入流创建输出流(Create output AVStream according to input AVStream)
  • if(ifmt_ctx_v->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
  • videoindex_v=i;
  • AVStream *in_stream = ifmt_ctx_v->streams[i];
  • AVStream *out_stream = avformat_new_stream(ofmt_ctx, in_stream->codec->codec);
  • if (!out_stream) {
  • printf( "Failed allocating output stream\n");
  • ret = AVERROR_UNKNOWN;
  • goto end;
  • }
  • videoindex_out=out_stream->index;
  • //复制AVCodecContext的设置(Copy the settings of AVCodecContext)
  • if (avcodec_copy_context(out_stream->codec, in_stream->codec) < 0) {
  • printf( "Failed to copy context from input to output stream codec context\n");
  • goto end;
  • }
  • out_stream->codec->codec_tag = 0;
  • if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
  • out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
  • break;
  • }
  • }
  •  
  • int audioindex_a=-1,audioindex_out=-1;
  • for (i = 0; i < ifmt_ctx_a->nb_streams; i++) {
  • //根据输入流创建输出流(Create output AVStream according to input AVStream)
  • if(ifmt_ctx_a->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO){
  • audioindex_a=i;
  • AVStream *in_stream = ifmt_ctx_a->streams[i];
  • AVStream *out_stream = avformat_new_stream(ofmt_ctx, in_stream->codec->codec);
  • if (!out_stream) {
  • printf( "Failed allocating output stream\n");
  • ret = AVERROR_UNKNOWN;
  • goto end;
  • }
  • audioindex_out=out_stream->index;
  • //复制AVCodecContext的设置(Copy the settings of AVCodecContext)
  • if (avcodec_copy_context(out_stream->codec, in_stream->codec) < 0) {
  • printf( "Failed to copy context from input to output stream codec context\n");
  • goto end;
  • }
  • out_stream->codec->codec_tag = 0;
  • if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
  • out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
  •  
  • break;
  • }
  • }
  •  
  • //输出一下格式------------------
  • printf("Output Information====================\n");
  • av_dump_format(ofmt_ctx, 0, out_filename, 1);
  • printf("======================================\n");
  • //打开输出文件(Open output file)
  • if (!(ofmt->flags & AVFMT_NOFILE)) {
  • if (avio_open(&ofmt_ctx->pb, out_filename, AVIO_FLAG_WRITE) < 0) {
  • printf( "Could not open output file '%s'", out_filename);
  • goto end;
  • }
  • }
  • //写文件头(Write file header)
  • if (avformat_write_header(ofmt_ctx, NULL) < 0) {
  • printf( "Error occurred when opening output file\n");
  • goto end;
  • }
  • int frame_index=0;
  • int64_t cur_pts_v=0,cur_pts_a=0;
  •  
  • //FIX
  • #if USE_H264BSF
  • AVBitStreamFilt
  • 首页 上一页 1 2 3 下一页 尾页 2/3/3
    】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
    分享到: 
    上一篇工作日计算问题思路和实现 下一篇redis安装配置教程及phpredis扩展..

    评论

    帐  号: 密码: (新用户注册)
    验 证 码:
    表  情:
    内  容: