最简单的基于FFMPEG的转码程序 open_output_file函数报错“Cannot open video encoder for stream ...”

本文探讨了在使用Transcoding代码时遇到的'Cannot open video encoder for stream'错误,重点在于如何通过修改open_output_file函数中的编码设置,如选择合适的编码格式和参数调整,以提高视频转码质量和解决编码问题。作者提到将`enc_ctx->qmax`值降低有助于提升编码效率。
摘要由CSDN通过智能技术生成

转载 https://blog.csdn.net/Spada_k/article/details/83007163
雷神的 https://blog.csdn.net/leixiaohua1020/article/details/26838535
文章后附的代码,报错:Cannot open video encoder for stream
在transcoding.c中的open_output_file函数中,修改的部分如下(只增加了13-17行):

if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
                enc_ctx->height = dec_ctx->height;
                enc_ctx->width = dec_ctx->width;
                enc_ctx->sample_aspect_ratio = dec_ctx->sample_aspect_ratio;
                /* take first format from list of supported formats */
                if (encoder->pix_fmts)
                    enc_ctx->pix_fmt = encoder->pix_fmts[0];
                else
                    enc_ctx->pix_fmt = dec_ctx->pix_fmt;
                /* video time_base can be set to whatever is handy and supported by encoder */
                enc_ctx->time_base = dec_ctx->time_base;
 
                enc_ctx->me_range = 16; 
                enc_ctx->max_qdiff = 4;
                enc_ctx->qmin = 10; 
                enc_ctx->qmax = 51; 
                enc_ctx->qcompress = 0.6;
 
            } else {
                enc_ctx->sample_rate = dec_ctx->sample_rate;
                enc_ctx->channel_layout = dec_ctx->channel_layout;
                enc_ctx->channels = av_get_channel_layout_nb_channels(enc_ctx->channel_layout);
                /* take first format from list of supported formats */
                enc_ctx->sample_fmt = encoder->sample_fmts[0];
                enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate};
            } 

在这里插入图片描述
其中enc_ctx->qmax = 51; 可以改小提高转码后视频质量。

非常感谢!!!愿雷神彼生平安幸福唉

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值