Skip to content

Remove obsolete FFMPEG versions support#18146

Merged
alalek merged 14 commits intoopencv:masterfrom
VadimLevin:dev/vlevin/ffmpeg-remove-obsolte-versions-support
Aug 24, 2020
Merged

Remove obsolete FFMPEG versions support#18146
alalek merged 14 commits intoopencv:masterfrom
VadimLevin:dev/vlevin/ffmpeg-remove-obsolte-versions-support

Conversation

@VadimLevin
Copy link
Copy Markdown
Contributor

In order to move further with extending existed functionality and reduce support costs about 3-4 months ago on the OpenCV core team meetings it was decided to limit FFMPEG versions to the versions that are available in the Ubuntu 14.04 LTS release:

- avcodec:       YES (54.35.1)
- avformat:      YES (54.20.4)
- avutil:        YES (52.3.0)
- swscale:       YES (2.1.1)
- avresample:    YES (1.0.1)

I tested using the following Docker container:

# Base image
FROM ubuntu:14.04

# General packages
RUN \
    apt-get update && \
    apt-get install -y --no-install-recommends \
        build-essential \
        software-properties-common \
        pkg-config \
        curl git man make mc vim wget htop

# GCC configuration
# Configure repository
RUN \
    add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
    apt-get update
# Install required version
RUN \
    apt-get install -y --no-install-recommends gcc-6 g++-6
# Substitute default version
RUN \
    update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6

# Verify compilers version
RUN \
    g++ --version && \
    gcc --version

# Actual CMake
# Install dependency
RUN \
    apt-get install -y --no-install-recommends \
        libssl-dev
# Download
RUN \
    wget https://github.com/Kitware/CMake/releases/download/v3.16.5/cmake-3.16.5.tar.gz && \
    tar -xvf cmake-3.16.5.tar.gz
# Configure
RUN \
    cd cmake-3.16.5 && \
    ./bootstrap 
# Build and install
RUN cd cmake-3.16.5 && \
    make -j 4 && \
    make install
# Verify CMake installation
RUN \
    cmake --version

# Install FFMPEG libraries
RUN \
    apt-get install -y --no-install-recommends \
        libavformat-dev libavformat-extra-54 libswscale-dev libavcodec-dev libavresample-dev

# Define entry-point of the container
CMD [ "/bin/bash" ]

The only difference from the default Ubuntu 14.04 setup is newer versions of GCC (6.5) and CMake (3.16).

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@asmorkalov
Copy link
Copy Markdown
Contributor

@mshabunin could you take a look?

@mshabunin
Copy link
Copy Markdown
Contributor

Is this patch applicable to 3.4 or we will keep that branch frozen?

Why GCC 6? Is there a problem with 4.8?

@VadimLevin
Copy link
Copy Markdown
Contributor Author

VadimLevin commented Aug 20, 2020

Is this patch applicable to 3.4 or we will keep that branch frozen?

Why GCC 6? Is there a problem with 4.8?

I think it is better to keep 3.4 in the state as it is, applying bug fixes and without radical (like version increments) changes.

GCC 4.8 does not fully C++11 complaint (some features are missing and not full library support). OpenCV 4.x uses C++11 as default, so I took GCC 6, but it is possible to use GCC 5.1 (full C++11 support). compiler support

@mshabunin
Copy link
Copy Markdown
Contributor

I've checked several FFmpeg versions built from sources on Ubuntu 20 and found one issue:

In file included from /opencv/modules/videoio/src/cap_ffmpeg.cpp:50:
/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In member function 'bool CvCapture_FFMPEG::open(const char*)':
/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:940:35: error: 'AVDISCARD_NONINTRA' was not declared in this scope; did you mean 'AVDISCARD_NONKEY'?
  940 |                 enc->skip_frame = AVDISCARD_NONINTRA;
      |                                   ^~~~~~~~~~~~~~~~~~
      |                                   AVDISCARD_NONKEY

It is reproduced only with several older FFmpeg versions: 1.1.16 - 2.2.16 ; which is strange because this line should not be compiled. Though this issue exists on master branch too, so I it is not a problem of this PR.

@VadimLevin
Copy link
Copy Markdown
Contributor Author

VadimLevin commented Aug 20, 2020

Thanks for validation with interesting results, so the issue is reproducible only for this range of versions, isn't it? I will check them on my own too and come up with possible fix in separe PR. What compiler do you use?

@mshabunin
Copy link
Copy Markdown
Contributor

I tested with default Ubuntu 20 compiler: GCC 9.3.0. See https://github.com/mshabunin/videoio-ffmpeg-check

More cases covered:

  • Same problem with libav-12.3 and libav-11.12 (AVDISCARD_NONINTRA)
  • No problems with libav-9.21
  • Different problem with libav-0.8.21, but I guess we won't support it.
  • And another problem with older ffmpeg-2.7.7
    In file included from /opencv/modules/videoio/src/cap_ffmpeg.cpp:50:
    /opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In function 'AVStream* icv_add_video_stream_FFMPEG(AVFormatContext*, AVCodecID, int, int, int, double, int)':
    /opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1804:21: error: 'AV_CODEC_FLAG_GLOBAL_HEADER' was not declared in this scope; did you mean 'CODEC_FLAG_GLOBAL_HEADER'?
     1804 |         c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
          |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
          |                     CODEC_FLAG_GLOBAL_HEADER
    

@alalek
Copy link
Copy Markdown
Member

alalek commented Aug 20, 2020

Please add some note/comment about minimal handled FFmpeg / libav versions (and their release dates/years)

@alalek
Copy link
Copy Markdown
Member

alalek commented Aug 23, 2020

@tomoaki0705 Could you check that this PR works on your devices? (there is conflict with changes from #18119 )

@VadimLevin
Copy link
Copy Markdown
Contributor Author

@tomoaki0705 Could you check that this PR works on your devices? (there is conflict with changes from #18119 )

It won't work, because I would like to raise minimal libavcodec version up to 54.35.100 (tested) and versions checks to the detect_ffmpeg.cmake . The problem, that #18119 solves, occurs for libavcodec version < 54.25.0 (FFMPEG 0.11.5 release). Should do we need to continue 0.11.5 release support?

@tomoaki0705
Copy link
Copy Markdown
Contributor

@VadimLevin is correct.
Here's my build log.
https://gist.github.com/tomoaki0705/e45f8494280607f16370f352fdab2275

It did fail building, but it didn't come up at cmake stage

--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      YES
--       avcodec:                   YES (53.7.0)
--       avformat:                  YES (53.4.0)
--       avutil:                    YES (51.9.1)
--       swscale:                   YES (2.0.0)
--       avresample:                NO
--     GStreamer:                   NO
--     v4l/v4l2:                    YES (linux/videodev2.h)
 :
-- Generating done
-- Build files have been written to: /home/odroid/opencv-fork/build
 :
In file included from /home/odroid/opencv-fork/modules/videoio/src/cap_ffmpeg.cpp:50:
/home/odroid/opencv-fork/modules/videoio/src/cap_ffmpeg_impl.hpp: In function 'const char* _opencv_avcodec_get_name(CodecID)':
/home/odroid/opencv-fork/modules/videoio/src/cap_ffmpeg_impl.hpp:352:11: error: 'AVCodecDescriptor' does not name a type
  352 |     const AVCodecDescriptor *cd;
      |           ^~~~~~~~~~~~~~~~~
/home/odroid/opencv-fork/modules/videoio/src/cap_ffmpeg_impl.hpp:359:5: error: 'cd' was not declared in this scope; did you mean 'id'?
  359 |     cd = avcodec_descriptor_get(id);
      |     ^~
      |     id

Is this expected ? (your message insists that error should appear in cmake stage)

I don't think we need to support the issue about #18119
The right answer for solving #18119 is to install newer ffmpeg via apt

I vote +1 for raise minimal libavcodec version to something later.

@VadimLevin
Copy link
Copy Markdown
Contributor Author

VadimLevin commented Aug 24, 2020

Not this message, the user should receive a message about what version is detected and what is the minimal version on CMake configuration step. Current behavior is an error during the build if there is missing (or renamed) symbol.
Something like this:

FFMPEG is disabled. Can't find suitable libavcodec library (minimal version: 54.35.1, got 53.7.0)

I'm working on it and it will be ready today.

 - Add verbose message about what FFMPEG libraries are missing.
 - Add minimal versions check set to libav 9.20 release (default ubuntu 14.04) and FFMPEG 1.1.16 release.
   If the check is failed CMake produces user-friendly message instead of build error.
@VadimLevin VadimLevin force-pushed the dev/vlevin/ffmpeg-remove-obsolte-versions-support branch from 3ebb877 to 8b8d32e Compare August 24, 2020 09:54
@VadimLevin
Copy link
Copy Markdown
Contributor Author

VadimLevin commented Aug 24, 2020

I resolved problems with missing #if version guards and @mshabunin script gives expected output for all supported versions (FFMPEG >= 1.1.16 and libav >= 9.20). These versions are checked during CMake configuration step, if one of the library has lower version FFMPEG is disabled.
I will back-port (AV_CODEC_FLAG_GLOBAL_HEADER and AVDISCARD_NONINTRA) guards for 3.4 branch too in other PR.

@VadimLevin VadimLevin requested a review from alalek August 24, 2020 17:08
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thank you 👍

@alalek alalek merged commit 458bd16 into opencv:master Aug 24, 2020
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
…ove-obsolte-versions-support

Remove obsolete FFMPEG versions support

* refactor: removed obsolete FFMPEG version support

 - Oldest available version via official FFMPEG repository mirror has tag v.0.5
 LIBAVFORMAT version for this tag is 52.31.0

* refactor: prefer std::min function to MIN macro

* refactor: use appropriate macro instead of manual version calculation

* refactor: remove macros for versions prior 0.5.15 release

* refactor: remove libavcodec macros for versions < 54.35.1 (default to Ubuntu 14.04)

* refactor: remove libavformat macro for versions < 54.20.4 (default ubuntu 14.04)

* refactor: remove libavutil macro for versions < 52.3.0 (default ubuntu 14.04)

* refactor: remove missed macros for libavcodec and libavformat

* refactor: remove unused _opencv_ffmpeg_free function

* build: add FFMPEG libraries versions checks

 - Add verbose message about what FFMPEG libraries are missing.
 - Add minimal versions check set to libav 9.20 release (default ubuntu 14.04) and FFMPEG 1.1.16 release.
   If the check is failed CMake produces user-friendly message instead of build error.

* fix: libavcodec version guard for AVDISCARD_NONINTRA

* fix: libav check of libavcodec version guard for AVDISCARD_NONINTRA

* fix: version check for AV_CODEC_FLAG_GLOBAL_HEADER

* fix: missing FFMPEG libraries output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants