avcodec_send_frame()
作為編碼函數,作用是將AVFrame
送入編碼器。
返回值-22
表示找不到編碼器,并拋出錯誤AVERROR(EINVAL)
。
可以先驗證一下-22是不是AVERROR(EINVAL)
,
int ret = 0;
ret = avcodec_send_frame(encodctx, frame_dst);
if ( ret == AVERROR(EINVAL) ) {
printf("ERROR: no encoder, ret = %d.\n", ret);
}
驗證成功,返回值-22就是AVERROR(EINVAL)
。
那我們接下來可看一下什么情況下會報AVERROR(EINVAL)
這個錯誤,avcodec_send_frame()函數源碼為
int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
{
AVCodecInternal *avci = avctx->internal;
int ret;
// 判斷編碼器有沒打開,是否為編碼器
if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
return AVERROR(EINVAL);
if (avci->draining)
return AVERROR_EOF;
if (avci->buffer_frame->data[0])
return AVERROR(EAGAIN);
if (!frame) {
avci->draining = 1;
} else {
ret = encode_send_frame_internal(avctx, frame);
if (ret < 0)
return ret;
}
if (!avci->buffer_pkt->data && !avci->buffer_pkt->side_data) {
ret = encode_receive_packet_internal(avctx, avci->buffer_pkt);
if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
return ret;
}
return 0;
}
可以看到,函數一上來(第六行)就會檢查編碼器是否打開,以及傳入的AVCodecContext是不是一個編碼器,兩個條件有一個不成立,就返回AVERROR(EINVAL)
。文章來源:http://www.zghlxwxcb.cn/news/detail-521300.html
因此,需要檢查兩個地方:文章來源地址http://www.zghlxwxcb.cn/news/detail-521300.html
- 是不是將
avcodec_find_encoder
寫成了avcodec_find_decoder
; - 是否調用
avcodec_open2
打開編碼器。
到了這里,關于ffmpeg報錯:avcodec_send_frame() 返回 -22的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!