Информация об изменениях

Сообщение opencv с поддержкой h264 от 06.05.2022 16:20

Изменено 06.05.2022 16:21 sergey2b

opencv с поддержкой h264
последнии версии opencv имеют поддержку чтения и запись видео в h264
используя ffmpeg для этого

при сборке opencv под windows загружаеться предкомпилированная ffmpeg_xxxx.dll которая поддерживает h264
под ubuntu надо установить вначале libx264-dev libavcodec-dev ffmpeg и собирать opencv но при этом не поддерживаеться запись в mp4 (я думаю libavcodec-dev ffmpeg собранны без подкржки h264)

проблемма существует не только у меня

https://www.martin-riedl.de/2021/11/26/compile-ffmpeg-on-your-own/

Compiling FFmpeg is not that hard. So simply download the latest source code and compile it, right? Same thoughts had I on my first try. And yea, it’s not working. It’s pretty simple so compile it. But then I got a big surprise: Encoding to h264 isn’t working!

Why? The reason is that FFmpeg has no own implementation of a h264 encoder. They are using x264, a project form the VideoLAN organization (known for VLC-Player). So we need to compile x264 first and then FFmpeg. Now FFmpeg works also with the h264 encoding. After copying then the binary to my other MacBook it was again not working.


под ubuntu 20.04

1) поставил libx264-dev libavcodec-dev ffmpeg и посмотрел куда поставились h и либ файлы

2) на чистой ubuntu собрал ffmeg из исходников

ffmpeg version N-106799-g0914e3a14a Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
configuration: --prefix=/home/superuser/ffmpeg_build --extra-cflags=-I/home/superuser/ffmpeg_build/include --extra-ldflags=-L/home/superuser/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/superuser/bin --disable-static --enable-shared --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree
libavutil 57. 24.101 / 57. 24.101
libavcodec 59. 27.100 / 59. 27.100
libavformat 59. 23.100 / 59. 23.100
libavdevice 59. 6.100 / 59. 6.100
libavfilter 8. 37.100 / 8. 37.100
libswscale 6. 6.100 / 6. 6.100
libswresample 4. 6.100 / 4. 6.100
libpostproc 56. 5.100 / 56. 5.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...


3) положил h и lib в фолдеры
/usr/lib/x86_64-linux-gnu/
/usr/include/x86_64-linux-gnu/libavcodec/
/usr/bin/ffmpeg

4) стал собирать opencv по точно рабочей инструкции https://velog.io/@jinhasong/OpenCV-4.4
в результате при работе cmake

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=ON -D BUILD_DOCS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -D BUILD_PACKAGE=OFF -D BUILD_EXAMPLES=OFF -D WITH_TBB=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda -D WITH_CUDA=OFF -D WITH_CUBLAS=ON -D WITH_CUFFT=ON -D WITH_NVCUVID=ON -D WITH_IPP=OFF -D WITH_V4L=ON -D WITH_1394=OFF -D WITH_GTK=ON -D WITH_QT=OFF -D WITH_OPENGL=ON -D WITH_EIGEN=ON -D WITH_FFMPEG=ON -D WITH_GSTREAMER=ON -D BUILD_JAVA=OFF -D BUILD_opencv_python3=ON -D BUILD_opencv_python2=OFF -D BUILD_NEW_PYTHON_SUPPORT=ON -D OPENCV_SKIP_PYTHON_LOADER=ON -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_EXTRA_MODULES_PATH=/home/superuser/Downloads/opencv/opencv_contrib-4.5.0/modules -D WITH_CUDNN=OFF -D OPENCV_DNN_CUDA=OFF ..




TIFF: build (ver 42 — 4.0.10)
-- JPEG 2000: build (ver 2.3.1)
-- OpenEXR: build (ver 2.3.0)
-- HDR: YES
-- SUNRASTER: YES
-- PXM: YES
-- PFM: YES
--
-- Video I/O:
-- FFMPEG: NO
-- avcodec: NO
-- avformat: NO
-- avutil: NO
-- swscale: NO
-- avresample: NO
-- GStreamer: NO
-- v4l/v4l2: YES (linux/videodev2.h)
--
-- Parallel framework: pthreads


те opencv не нашла avcodec



если у кого то был опыт сборки opencv как вы считаете в чем может быть дело
opencv с поддержкой h264
последнии версии opencv имеют поддержку чтения и запись видео в h264
используя ffmpeg для этого

при сборке opencv под windows загружаеться предкомпилированная ffmpeg_xxxx.dll которая поддерживает h264
под ubuntu надо установить вначале libx264-dev libavcodec-dev ffmpeg и собирать opencv но при этом не поддерживаеться запись в mp4

проблемма существует не только у меня

https://www.martin-riedl.de/2021/11/26/compile-ffmpeg-on-your-own/

Compiling FFmpeg is not that hard. So simply download the latest source code and compile it, right? Same thoughts had I on my first try. And yea, it’s not working. It’s pretty simple so compile it. But then I got a big surprise: Encoding to h264 isn’t working!

Why? The reason is that FFmpeg has no own implementation of a h264 encoder. They are using x264, a project form the VideoLAN organization (known for VLC-Player). So we need to compile x264 first and then FFmpeg. Now FFmpeg works also with the h264 encoding. After copying then the binary to my other MacBook it was again not working.


под ubuntu 20.04

1) поставил libx264-dev libavcodec-dev ffmpeg и посмотрел куда поставились h и либ файлы

2) на чистой ubuntu собрал ffmeg из исходников

ffmpeg version N-106799-g0914e3a14a Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
configuration: --prefix=/home/superuser/ffmpeg_build --extra-cflags=-I/home/superuser/ffmpeg_build/include --extra-ldflags=-L/home/superuser/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/superuser/bin --disable-static --enable-shared --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree
libavutil 57. 24.101 / 57. 24.101
libavcodec 59. 27.100 / 59. 27.100
libavformat 59. 23.100 / 59. 23.100
libavdevice 59. 6.100 / 59. 6.100
libavfilter 8. 37.100 / 8. 37.100
libswscale 6. 6.100 / 6. 6.100
libswresample 4. 6.100 / 4. 6.100
libpostproc 56. 5.100 / 56. 5.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...


3) положил h и lib в фолдеры
/usr/lib/x86_64-linux-gnu/
/usr/include/x86_64-linux-gnu/libavcodec/
/usr/bin/ffmpeg

4) стал собирать opencv по точно рабочей инструкции https://velog.io/@jinhasong/OpenCV-4.4
в результате при работе cmake

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=ON -D BUILD_DOCS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -D BUILD_PACKAGE=OFF -D BUILD_EXAMPLES=OFF -D WITH_TBB=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda -D WITH_CUDA=OFF -D WITH_CUBLAS=ON -D WITH_CUFFT=ON -D WITH_NVCUVID=ON -D WITH_IPP=OFF -D WITH_V4L=ON -D WITH_1394=OFF -D WITH_GTK=ON -D WITH_QT=OFF -D WITH_OPENGL=ON -D WITH_EIGEN=ON -D WITH_FFMPEG=ON -D WITH_GSTREAMER=ON -D BUILD_JAVA=OFF -D BUILD_opencv_python3=ON -D BUILD_opencv_python2=OFF -D BUILD_NEW_PYTHON_SUPPORT=ON -D OPENCV_SKIP_PYTHON_LOADER=ON -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_EXTRA_MODULES_PATH=/home/superuser/Downloads/opencv/opencv_contrib-4.5.0/modules -D WITH_CUDNN=OFF -D OPENCV_DNN_CUDA=OFF ..




TIFF: build (ver 42 — 4.0.10)
-- JPEG 2000: build (ver 2.3.1)
-- OpenEXR: build (ver 2.3.0)
-- HDR: YES
-- SUNRASTER: YES
-- PXM: YES
-- PFM: YES
--
-- Video I/O:
-- FFMPEG: NO
-- avcodec: NO
-- avformat: NO
-- avutil: NO
-- swscale: NO
-- avresample: NO
-- GStreamer: NO
-- v4l/v4l2: YES (linux/videodev2.h)
--
-- Parallel framework: pthreads


те opencv не нашла avcodec



если у кого то был опыт сборки opencv как вы считаете в чем может быть дело