"error: 'avcodec_open' was not declared in this scope"尝试编译untrunc

"error: 'avcodec_open' was not declared in this scope" on attempting to compile untrunc

本文关键字:untrunc this scope in 编译 was error avcodec not open declared      更新时间:2023-10-16

我有一段由电源中断的摄像机录制的视频。因此,它正在制作的H.264编解码器的MP4文件被损坏。我想在Ubuntu 14.04.1中修复这个文件。我看到有人建议使用untrunc。我正试图编译这个,但遇到了一个错误,我不知道如何解决。到目前为止,我所做的如下:

sudo apt-get install libavformat-dev libavcodec-dev libavutil-dev
git clone https://github.com/ponchio/untrunc.git
cd untrunc/
g++ -o untrunc file.cpp main.cpp track.cpp atom.cpp mp4.cpp -L/usr/local/lib -lavformat -lavcodec -lavutil

尝试编译时,出现以下错误:

track.cpp: In member function 'void Track::parse(Atom*, Atom*)':
track.cpp:217:47: error: 'avcodec_open' was not declared in this scope
     if(avcodec_open(codec.context, codec.codec)<0)

你能建议一个解决这个错误的方法吗?

avcodec_open不支持avcodec_open2。请看下面的注释。通读avcodec_open的文档,似乎做替换的方法是转换:

avcodec_open(a,b);

avcodec_open2(a,b,NULL);

这个修复类似于建议的修复,但没有在untrunc库本身中进行验证,在这里。

我试图验证修复是否有效。实际上,这是对track.cpp的单行修改。:

 if(avcodec_open(codec.context, codec.codec)<0)

并替换为

 if(avcodec_open2(codec.context, codec.codec, NULL)<0)

(在commit 3c708a上,这个更改是在第218行)。注意:我只验证了代码编译,而不是它实际上按照它应该的方式工作(我没有一个坏的m4v来测试)。

请告诉我它是否有效,或者如果你遇到任何其他问题。

不是您问题的确切解决方案(编译错误),但可能是您主要问题的解决方案(mp4破碎):http://untrunc.it/