gpt4 book ai didi

c++ - AVFormatContext 错误 : I can't get the AVFormatContext

转载 作者:行者123 更新时间:2023-12-04 23:33:22 25 4
gpt4 key购买 nike

在测试是否设置了 AVFormatContext 时,我从 AVERROR(EONEM) 收到此错误 -12。但我不明白这意味着什么以及该怎么做。在测试 avformat_open_input() 时,我也收到一个数字错误 (12)。
我使用函数 av_strerror() 来获取与这些数字相关的字符串错误,但该函数也会导致错误。所以未定义它。
我应该怎么做才能修复错误?这是我的一段代码。

#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"

string myFile="C:/Users/Username/Downloads/Video/QGRAPHICS.mp4";
char *char_array=&myFile[0];

AVFormatContext *avformat_alloc_context();
AVFormatContext *av_format_ctx=NULL;
/**if av_format_ctx is not null, it means AVFormatContext is allocated**/
if(!av_format_ctx){
cout<<" Format Context allocated "<<endl;
}


/**I still don't understand why the file can't be opened here**/
if(avformat_open_input(&av_format_ctx, &char_array[0],NULL, NULL)!=0){`cout<<" File not opened"<<endl<<endl;
cout<<avformat_open_input(&av_format_ctx, &char_array[0],NULL, NULL)<<endl;
}`
avformat_close_input(&av_format_ctx);
avformat_free_context(av_format_ctx);

最佳答案

不要预分配 av_format_ctx .只需将其设置为 NULL 并让 avformat_open_input分配给你。

AVFormatContext *av_format_ctx = NULL;
int err = 0;
if( err = avformat_open_input(&av_format_ctx, &char_array[0],NULL, NULL)!=0){
cout<<"File successfully opened"<<endl;
return false;
}
else { cout<< err << endl;}

avformat_close_input(&av_format_ctx);
avformat_free_context(av_format_ctx);

关于c++ - AVFormatContext 错误 : I can't get the AVFormatContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68210363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com