ffmpeg——Invalid data found when processing input

  • 一、问题描述
  • 二、原因
  • 三、解决方案

一、问题描述

流程描述:我把每一帧原始YUV图像数据,构造成Y4M(YUV4MPEG2)格式的流,然后使用ffmpeg编码成h264格式进行RTMP推流。
ffmpeg执行avformat_open_input打开文件和执行avformat_find_stream_info探测流都正常,但在执行avformat_write_header报错:Invalid data found when processing input。

二、原因

编码器参数设置错误

// enc_ctx编码器上下文,dec_ctx解码器上下文
AVCodecContext *dec_ctx, *enc_ctx;
...
dec_ctx = pFormatCtx->streams[i]->codec;
...
if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {LOGD_DEBUG("height = %d, width = %d, sample_aspect_ratio = %d/%d, pix_fmt = %d, framerate = %d/%d, time_base = %d/%d",dec_ctx->height, dec_ctx->width,dec_ctx->sample_aspect_ratio.num,dec_ctx->sample_aspect_ratio.den,dec_ctx->pix_fmt,dec_ctx->framerate.num, dec_ctx->framerate.den,dec_ctx->time_base.num, dec_ctx->time_base.den);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];elseenc_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->framerate;enc_ctx->codec_type = AVMEDIA_TYPE_VIDEO;
}

我这里的编码器参数是根据解码器里参数进行设置的,但解码器取得的部分参数时不准确的,推测原因可能和我构造的Y4M(YUV4MPEG2)流格式有关。

三、解决方案

将上面的代码修改为:

// enc_ctx编码器上下文,dec_ctx解码器上下文
AVCodecContext *dec_ctx, *enc_ctx;
...
dec_ctx = pFormatCtx->streams[i]->codec;
...
if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {LOGD_DEBUG("height = %d, width = %d, sample_aspect_ratio = %d/%d, pix_fmt = %d, framerate = %d/%d, time_base = %d/%d",dec_ctx->height, dec_ctx->width,dec_ctx->sample_aspect_ratio.num,dec_ctx->sample_aspect_ratio.den,dec_ctx->pix_fmt,dec_ctx->framerate.num, dec_ctx->framerate.den,dec_ctx->time_base.num, dec_ctx->time_base.den);enc_ctx->height = dec_ctx->height;enc_ctx->width = dec_ctx->width;enc_ctx->sample_aspect_ratio = {476, 477};//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];elseenc_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 = av_inv_q({25, 1});//dec_ctx->framerate);enc_ctx->codec_type = AVMEDIA_TYPE_VIDEO;
}

Invalid data found when processing input相关推荐

  1. arm ffmpeg报错:Invalid data found when processing input(没解决)(在ubuntu上能正常运行)(重新交叉编译后问题解决)

    文章目录 报错 原因分析 报错 如图,运行ffmpeg指令时,报错: ffmpeg -i 1e1fee9790f26fa3_20221421292.264 -vcodec copy -f mp4 te ...

  2. avformat_open_input返回-1094995529 “Invalid data found when processing input“

    avformat_open_input返回-1094995529 avformat_open_input() 返回"Invalid data found when processing in ...

  3. FFmpeg Invalid data found when processing input

    说一下自己用ffmpeg合并视频出现的bug吧   直接上代码 /*** 批量转换某文件夹的视频 转换为ts文件 并生成txt文件* */String videoPathList = "C: ...

  4. av_interleaved_write_frame错误 Invalid data found when processing input

    问题描述: 调用av_interleaved_write_frame接口发送AAC格式的音频数据时,报错:Invalid data found when processing input. 解决方案: ...

  5. FFMPEG学习遇到avformat_open_input Invalid data found when processing input

    按顺序调用 av_register_all(); avcodec_register_all(); avformat_network_init(); 调用 avformat_open_input() 打 ...

  6. ijkplayer使用ffmpeg为视频添加水印avfilter_graph_parse_ptr返回Invalid data found when processing input

    在确定代码逻辑和流程没有问题过后返回这个问题,通过多方验证确定是avfilter_graph_parse_ptr第二个参数导致的,此处我的输入参数是 const char *strFilter=&qu ...

  7. 07-----关于ffmpeg Invalid data found when processing input错误

    1 关于ffmpeg Invalid data found when processing input错误 ffmpeg库不支持,例如ffmpeg -i 1.mkv -vcodec lib264 2. ...

  8. pyav Invalid data found when processing input (libav.h264: no frame!)

    for packet in video.demux(stream):if(packet.size<60):continue

  9. ffmpeg合并m3u8 ts key文件 解决Invalid data found when processing input错误

    首先我先说明一下我的使用场景和错误原因: 我使用IDM从网站中批量下载ts文件,然后下载对应的一个.m3u8文件(ts文件列表和加密信息的描述)和一个key.key文件(秘钥).以上文件全部保存在同一 ...

最新文章

  1. 如何学习修改linux系统固件,基于Linux的固件,如何实现更新的好方法?
  2. pcl中PrincipalCurvatures 和 Normal中的curvature的区别
  3. Citrix_XenServer-6.1安装过程详解(转)
  4. $Android自定义控件在不同状态下的属性
  5. 基于BISS0001构成的热释电红外延时照明控制器电路图
  6. 面试官问我:平常如何对你的 Java 程序进行调优?
  7. win10时间和linux不同步时间,ubuntu16和windows10的时间同步问题
  8. UOJ#419. 【集训队作业2018】圆形(格林公式)
  9. 看数据手册上的注意事项
  10. QT5.14.2+VS2019安装配置教程Windows
  11. 软件测试师和网络工程师,【软件测试工程师(科技部)网络工程师面试题目|面试经验】-看准网...
  12. 计算机应用软件弹窗消除,去除电脑弹窗广告的4种方法
  13. python人民币小写转大写_python人民币小写转大写辅助工具
  14. android ios 微信 备份通讯录备份通讯录备份通讯录,苹果手机怎么备份通讯录?手机通讯录微信联系人备份教程...
  15. 常见多变量/多元统计分析方法分类图
  16. wgc84 笛卡尔_从经纬度到笛卡尔坐标的转换
  17. java圈子_从JAVA入了这个圈子,有多少老司机和他一样?
  18. Java实现十字形开关问题(“飞行员兄弟“)
  19. Js获取图片主色调,近似色,互补色,以及根据图片颜色获取主题配色方案详解、插件。
  20. 老铁是要塞里最出名的铁匠大师,小铁是老铁的儿子,老铁希望小铁能传承他的衣钵为要塞的骑士们锻造护甲。经近一段时间的学习,小铁逐渐掌握了打铁的技术,但是他很快发现,每一天手臂的力量总是不如前一天

热门文章

  1. 杭州市拥北发展是否是最优解,拥江发展处于何种地位
  2. c语言知识地图,【程序设计论文】C语言程序设计翻转课堂研究(共3546字)
  3. 闲人闲谈PS之一项目库存跨公司业务STO解决方案--SAP闲人的开篇
  4. jpanel麻将自动打牌,碰牌,杠牌
  5. 计算机软件实施自我评价,软件实施工程师简历自我评价怎么写
  6. 自然语言处理(NLP)任务中常用的分词工具及底层算法支持
  7. C-DOCSIS PHS,服务组
  8. 移动端seo如何优化,需要做单独的m域名移动端googleseo优化吗?
  9. 修改Cisco交换机ntp服务器,如何配置Brocade和Cisco光纤交换机的NTP服务器
  10. Android开发入门与实战之Android应用安装卸载