Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

video

I have a video recorded by a camera that had a power interruption. As a result, the MP4 file with H.264 codec it was making is damaged. I want to repair this file in Ubuntu 14.04.1. One approach I have seen suggested is to use untrunc. I am attempting to compile this but have run into an error I do not know how to address. What I have done so far is as follows:

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

On attempting to compile, I am presented with the following error:

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)

Could you suggest a way to address this error?

like image 970
d3pd Avatar asked Aug 06 '14 23:08

d3pd


2 Answers

avcodec_open was deprecated for avcodec_open2. See for instance this note. Reading through the docs for avcodec_open, it appears that the way to do the replacement is to convert:

avcodec_open(a,b);

to

avcodec_open2(a,b,NULL);

This fix is similar to one that was suggested, but not verified in the untrunc library itself, here.

I tried to verify that the fix worked. In practice, it was a single line modification in track.cpp. Take:

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

and replace it with

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

(on commit 3c708a, this change is on line 218). NOTE: I only verified that the code compiled, not that it actually worked the way it was supposed to (I don't have a broken m4v to test on). Let me know if it works, or if you encounter any other problems.

like image 128
Behram Mistree Avatar answered Sep 23 '22 21:09

Behram Mistree


Not the exact solution for your question (compile error), but possibly the solution for you primary problem (broken mp4): http://untrunc.it/

like image 25
Roman Avatar answered Sep 23 '22 21:09

Roman