gazebosim / gazebo-classic

Gazebo classic. For the latest version, see https://github.com/gazebosim/gz-sim
http://classic.gazebosim.org/
Other
1.21k stars 484 forks source link

Fails to build with ffmpeg 5.0 #3180

Closed sebastinas closed 2 years ago

sebastinas commented 2 years ago

gazebo is not compatible with ffmpeg 5.0:

/<<PKGBUILDDIR>>/gazebo/common/AudioDecoder.cc: In member function ‘bool gazebo::common::AudioDecoder::Decode(uint8_t**, unsigned int*)’:                      
/<<PKGBUILDDIR>>/gazebo/common/AudioDecoder.cc:100:17: warning: ‘void av_init_packet(AVPacket*)’ is deprecated [-Wdeprecated-declarations]                     
  100 |   av_init_packet(&packet);                                                                                                                             
      |   ~~~~~~~~~~~~~~^~~~~~~~~                                                                                                                              
In file included from /usr/include/x86_64-linux-gnu/libavcodec/avcodec.h:45,                                                                                   
                 from /<<PKGBUILDDIR>>/gazebo/common/ffmpeg_inc.h:32,                                                                                          
                 from /<<PKGBUILDDIR>>/gazebo/common/AudioDecoder.cc:21:                                                                                       
/usr/include/x86_64-linux-gnu/libavcodec/packet.h:506:6: note: declared here                                                                                   
  506 | void av_init_packet(AVPacket *pkt);                                                                                                                    
      |      ^~~~~~~~~~~~~~                                                                                                                                    
/<<PKGBUILDDIR>>/gazebo/common/AudioDecoder.cc:116:24: error: ‘avcodec_decode_audio4’ was not declared in this scope; did you mean ‘avcodec_decode_subtitle2’? 
  116 |         bytesDecoded = avcodec_decode_audio4(this->codecCtx, decodedFrame,                                                                             
      |                        ^~~~~~~~~~~~~~~~~~~~~                                                                                                           
      |                        avcodec_decode_subtitle2                                                                                                        
/<<PKGBUILDDIR>>/gazebo/common/AudioDecoder.cc: In member function ‘bool gazebo::common::AudioDecoder::SetFile(const string&)’:                                
/<<PKGBUILDDIR>>/gazebo/common/AudioDecoder.cc:217:38: error: ‘AVStream’ {aka ‘struct AVStream’} has no member named ‘codec’                                   
  217 |     if (this->formatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)                                                                          
      |                                      ^~~~~                                                                                                             
/<<PKGBUILDDIR>>/gazebo/common/AudioDecoder.cc:241:59: error: ‘AVStream’ {aka ‘struct AVStream’} has no member named ‘codec’                                   
  241 |   this->codecCtx = this->formatCtx->streams[audioStream]->codec;                                                                                       
      |                                                           ^~~~~                                                                                        
/<<PKGBUILDDIR>>/gazebo/common/AudioDecoder.cc:247:37: error: invalid conversion from ‘const AVCodec*’ to ‘AVCodec*’ [-fpermissive]                            
  247 |   this->codec = avcodec_find_decoder(codecCtx->codec_id);                                                                                              
      |                 ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~                                                                                               
      |                                     |                                                                                                                  
      |                                     const AVCodec*      
traversaro commented 2 years ago

Related issue (it was on the deprecated function that eventually were removed): https://github.com/osrf/gazebo/issues/2002

traversaro commented 2 years ago

A bit of info on replacements extracted from ffmpeg:

traversaro commented 2 years ago

For the usual #if preprocessor magic, in libavformat/version.h the macro LIBAVFORMAT_VERSION_MAJOR is defined, that is:

traversaro commented 2 years ago

Strictly related issue: https://github.com/ignitionrobotics/ign-common/issues/306 (as the affected classes are the same that as some point were copied there).

KenwoodFox commented 2 years ago

I also have this issue on manjaro linux

vebjornjr commented 2 years ago

@KenwoodFox, did you manage to fix it? I experience the same on Manjaro when trying to build ros-noetic-desktop-full. I don't understand how to fix this myself, @traversaro.

traversaro commented 2 years ago

Basically we need to substitute the function that were removed from ffmpeg API with the one that are still existing, see https://github.com/osrf/gazebo/issues/3180#issuecomment-1053641133 . If you want to try to fix it, perhaps it is a good idea to first get a basic idea of how the ffmpeg API works, for example reading the examples in https://github.com/FFmpeg/FFmpeg/tree/870bfe16a12bf09dca3a4ae27ef6f81a2de80c40/doc/examples . Once you got the general idea, I guess it may be easier to fix the code in Gazebo. Furthermore, a possible easier stepping stone may be fixing ffmpeg support in https://github.com/ignitionrobotics/ign-common/issues/306 .

KenwoodFox commented 2 years ago

@KenwoodFox, did you manage to fix it? I experience the same on Manjaro when trying to build ros-noetic-desktop-full. I don't understand how to fix this myself, @traversaro.

I have not yet, I fail building ignition due to ffmpeg deps, this may take a PR to solve I'll look into learning the API

JorgeEdGG commented 2 years ago

@vebjornjr @traversaro @KenwoodFox Hi guys, the workaround that work for me was first unistall ffmpeg then install gazebo using ffmpeg4.4, finaly reinstall ffmpeg, i hope it works for you.

sudo pacman -Rd --nodeps ffmpeg (and any other ffmpeg you have installed, like the git version) sudo pacman -S ffmpeg4.4 yay -S gazebo sudo pacman -S ffmpeg

KenwoodFox commented 2 years ago

@vebjornjr @traversaro @KenwoodFox Hi guys, the workaround that work for me was first unistall ffmpeg then install gazebo using ffmpeg4.4, finaly reinstall ffmpeg, i hope it works for you.

sudo pacman -Rd --nodeps ffmpeg (and any other ffmpeg you have installed, like the git version) sudo pacman -S ffmpeg4.4 yay -S gazebo sudo pacman -S ffmpeg

This worked!

vebjornjr commented 2 years ago

@vebjornjr @traversaro @KenwoodFox Hi guys, the workaround that work for me was first unistall ffmpeg then install gazebo using ffmpeg4.4, finaly reinstall ffmpeg, i hope it works for you.

sudo pacman -Rd --nodeps ffmpeg (and any other ffmpeg you have installed, like the git version) sudo pacman -S ffmpeg4.4 yay -S gazebo sudo pacman -S ffmpeg

Thank you, it worked for me too.

traversaro commented 2 years ago

"Need to be substituted" is a bit generic. I found the relevant commit that change the ffmpeg examples to understand how they can be substituted:

traversaro commented 2 years ago

For avcodec_decode_video2 this ign-common commit is strictly related: https://github.com/ignitionrobotics/ign-common/commit/e2f6a84100f39fe29d5ffc49447e12c1f6c4196d .

traversaro commented 2 years ago

I guess that backporting:

Should fix the problem also for Classic Gazebo.

traversaro commented 2 years ago

A fix for this issue is provided in https://github.com/osrf/gazebo/pull/3195 .

scpeters commented 2 years ago

Fixed by https://github.com/osrf/gazebo/pull/3195.