avcodec_open2错误 -542398533:"外部库中的一般错误"
avcodec_open2 error -542398533 : "Generic error in an external library"
尝试使用avcodec_open2()
打开编解码器时遇到错误。如果在av_guess_format()
函数中指定avi
而不是h264
,我已经尝试过相同的代码,没有任何问题。
我不知道该怎么办。其他人遇到过类似的问题吗?
我使用的库是ffmpeg-20160219-git-98a0053-win32-dev。如果你能帮我摆脱这种困惑,我将不胜感激。
这是我的控制台输出:
视频编码
[libx264@01383460]检测到损坏的ffmpeg默认设置
[libx264@01383460]使用编码预设(例如-vpre介质)
[libx264@01383460]预设用法:-vpre-vpre
[libx264@01383460]速度预设在x264中列出--帮助
[libx264@01383460]配置文件是可选的;x264默认为高
无法打开视频编解码器,-542398533
这是我正在使用的代码:
// Video encoding sample
AVCodec *codec = NULL;
AVCodecContext *codecCtx= NULL;
AVFormatContext *pFormatCtx = NULL;
AVOutputFormat *pOutFormat = NULL;
AVStream * pVideoStream = NULL;;
AVFrame *picture = NULL;;
int i, x, y, ret;
printf("Video encodingn");
// Register all formats and codecs
av_register_all();
// guess format from file extension
pOutFormat = av_guess_format("h264", NULL, NULL);
if (NULL==pOutFormat){
cerr << "Could not guess output format" << endl;
return -1;
}
// allocate context
pFormatCtx = avformat_alloc_context();
pFormatCtx->oformat = pOutFormat;
memcpy(pFormatCtx->filename,filename,
min(strlen(filename), sizeof(pFormatCtx->filename)));
// Add stream to pFormatCtx
pVideoStream = avformat_new_stream(pFormatCtx, 0);
if (!pVideoStream)
{
printf("Cannot add new video streamn");
return -1;
}
// Set stream's codec context
codecCtx = pVideoStream->codec;
codecCtx->codec_id = (AVCodecID)pOutFormat->video_codec;
codecCtx->codec_type = AVMEDIA_TYPE_VIDEO;
codecCtx->frame_number = 0;
// Put sample parameters.
codecCtx->bit_rate = 2000000;
// Resolution must be a multiple of two.
codecCtx->width = 320;
codecCtx->height = 240;
codecCtx->time_base.den = 10;
codecCtx->time_base.num = 1;
pVideoStream->time_base.den = 10;
pVideoStream->time_base.num = 1;
codecCtx->gop_size = 12; // emit one intra frame every twelve frames at most
codecCtx->pix_fmt = AV_PIX_FMT_YUV420P;
if (codecCtx->codec_id == AV_CODEC_ID_H264)
{
// Just for testing, we also add B frames
codecCtx->mb_decision = 2;
}
// Some formats want stream headers to be separate.
if(pFormatCtx->oformat->flags & AVFMT_GLOBALHEADER)
{
codecCtx->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
if(codecCtx->codec_id == AV_CODEC_ID_H264)
av_opt_set(codecCtx->priv_data, "preset", "slow", 0);
// Open the codec.
codec = avcodec_find_encoder(codecCtx->codec_id);
if (codec == NULL) {
fprintf(stderr, "Codec not foundn");
return -1;
}
ret = avcodec_open2(codecCtx, codec, NULL); // returns -542398533 here
if (ret < 0)
{
printf("Cannot open video codec, %dn",ret);
return -1;
}
您的问题是这一行:
codecCtx = pVideoStream->codec;
此AVCodecContext
是使用全局默认值分配的,x264拒绝全局默认值,因为它们不是最佳值。相反,使用avcodec_alloc_context3
来分配它,这将设置x264特定的默认值。在编码结束时,不要忘记avcodec_free_context
返回的指针。
您应该将编解码器参数传递给avformat_new_stream
codec = avcodec_find_encoder(codecCtx->codec_id);
pVideoStream = avformat_new_stream(pFormatCtx, codec);
相关文章:
- 使用外部SDK工具链文件在VisualStudio上生成项目编译错误
- spdlog标头仅与外部fmt一起使用.spdlog错误:'内部':不是'fmt'
- 我收到错误LNK2001:未解析的外部符号(C++代码)
- Visual Studio 2017 中的 QtMetaObject 未解决的外部错误
- 外部"C"拆卸导致奇怪的链接器错误
- C++指针无法在函数外部传递值和分段错误(核心转储)错误
- 在Embarcadero C++ Builder中生成的DLL未解决的外部链接错误
- 可视抽象类 c++(错误 LNK 2001:未解析的外部符号)
- 如何摆脱C++中未解析的外部符号"private: static char"错误?
- 当 lib 已添加到其他依赖项时,如何在 VS 中调试未解析的外部符号错误
- 错误LNK2019未解析的外部符号"public: __thiscall SLinkList<char>::SLinkList<char>(void)"
- 外部函数在 main() 上调用时返回分段错误 11.(C++)
- 引入参数化构造函数后显示 LNK 2019 未解析外部符号的代码错误
- 每次我要使用外部资源时,我都会得到:collect2。exe:错误 ld 返回 1 退出状态
- 链接器错误:切换到unicode生成给出:未解析的外部符号WinMain
- C#WPF和C++/CLI以及C++在C++/CLI中添加外部库错误
- 函数 LNK2019 "int __cdecl __scrt_common_main_seh(void)" 中引用的未解析外部符号主错误 (?__scrt_common_main_seh@@YAHXZ
- C++:在"try"外部创建的类型会导致错误,但在内部不会
- 编译错误外部接口Simulink
- 为什么这会给出多个定义错误:外部 int i;国际 i;.