"error: 'avcodec_open' was not declared in this scope" when trying to compile untrunc

I have a video recorded by a camera with power interruption. As a result, the MP4 file with the H.264 codec that it created is corrupted. I want to restore this file in Ubuntu 14.04.1. One approach I saw suggested was to use untrunc . I am trying to compile this, but encountered an error, I do not know how to handle it. So far I have done the following:

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 

When trying to compile, I get 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 solve this error?

+6
source share
1 answer

It looks like avcodec_open deprecated for avcodec_open2 . See for example this note. Reading documents in avcodec_open , it looks like the replacement method is to convert:

 avcodec_open(a,b); 

to

 avcodec_open(a,b,NULL); 

This fix is โ€‹โ€‹similar to the one proposed but not tested in the untrunc library itself, here .

I tried to verify the fix works. In practice, it was a one-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) 

(when committing 3c708a, this change is on line 218). NOTE. I only checked that the code was compiled, and not that it really worked as intended (I don't have a broken m4v for testing). Let me know if this works, or if you have other problems.

+6
source

Source: https://habr.com/ru/post/973467/


All Articles