日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Invalid data found when processing input

發(fā)布時間:2024/3/12 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Invalid data found when processing input 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

ffmpeg——Invalid data found when processing input

  • 一、問題描述
  • 二、原因
  • 三、解決方案

一、問題描述

流程描述:我把每一幀原始YUV圖像數(shù)據(jù),構(gòu)造成Y4M(YUV4MPEG2)格式的流,然后使用ffmpeg編碼成h264格式進(jìn)行RTMP推流。
ffmpeg執(zhí)行avformat_open_input打開文件和執(zhí)行avformat_find_stream_info探測流都正常,但在執(zhí)行avformat_write_header報錯:Invalid data found when processing input。

二、原因

編碼器參數(shù)設(shè)置錯誤

// 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; }

我這里的編碼器參數(shù)是根據(jù)解碼器里參數(shù)進(jìn)行設(shè)置的,但解碼器取得的部分參數(shù)時不準(zhǔn)確的,推測原因可能和我構(gòu)造的Y4M(YUV4MPEG2)流格式有關(guān)。

三、解決方案

將上面的代碼修改為:

// 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; }

總結(jié)

以上是生活随笔為你收集整理的Invalid data found when processing input的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。