Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPENCV_FFMPEG_WRITER_OPTIONS aren't executed by ffmpeg backend #24570

Open
4 tasks done
nji9nji9 opened this issue Nov 21, 2023 · 4 comments
Open
4 tasks done

OPENCV_FFMPEG_WRITER_OPTIONS aren't executed by ffmpeg backend #24570

nji9nji9 opened this issue Nov 21, 2023 · 4 comments

Comments

@nji9nji9
Copy link

nji9nji9 commented Nov 21, 2023

System Information

OpenCV version: 4.8.0
Operating System / Platform: Windows 7-64
Compiler & compiler version: mingw-64

CMake
Code::Blocks

Detailed description

Built OpenCV v.4.8.0 with tools as above

Used prebuild ffmpeg backend.
(Detailed description) and this.

Steps to reproduce

Using the VideoWriter, and setting ffmpeg's crf-option before

_putenv ("OPENCV_FFMPEG_WRITER_OPTIONS=crf;18");
VideoWriter VW ("Output.mp4", CAP_FFMPEG, VideoWriter::fourcc('a','v','c','1'), capt.get(CAP_PROP_FPS), refS);

generates always h264 default crf 23.
See lines
[DEBUG:0@0.065] and
[OPENCV:FFMPEG:32] in the following (bolding doesn't seem to work in code):

[DEBUG:0@0.008] global videoio_registry.cpp:218 VideoBackendRegistry VIDEOIO: Builtin backends(8): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930)
[DEBUG:0@0.008] global videoio_registry.cpp:242 VideoBackendRegistry VIDEOIO: Available backends(8): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930)
[ INFO:0@0.008] global videoio_registry.cpp:244 VideoBackendRegistry VIDEOIO: Enabled backends(8, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930)
[OPENCV:FFMPEG:40] Reinit context to 1280x720, pix_fmt: yuv420p
[DEBUG:0@0.061] global cap_ffmpeg_impl.hpp:1182 open FFMPEG: stream[0] is video stream with codecID=27 width=1280 height=720
[DEBUG:0@0.061] global cap_ffmpeg_hw.hpp:934 HWAccelIterator FFMPEG: allowed acceleration types (none): ''
[DEBUG:0@0.065] global cap_ffmpeg_impl.hpp:2773 open Selected pixel format: bgr24
**[DEBUG:0@0.065] global cap_ffmpeg_impl.hpp:2980 open VIDEOIO/FFMPEG: using writer options from environment: crf;18**
[DEBUG:0@0.065] global cap_ffmpeg_hw.hpp:934 HWAccelIterator FFMPEG: allowed acceleration types (none): ''
[OPENCV:FFMPEG:32] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[OPENCV:FFMPEG:32] profile High, level 3.1, 4:2:0, 8-bit
[OPENCV:FFMPEG:32] 264 - core 164 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 **crf=23.0** qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[OPENCV:FFMPEG:40] Reinit context to 1280x720, pix_fmt: yuv420p
[DEBUG:0@0.082] global cap_ffmpeg_impl.hpp:1609 retrieveFrame Input picture format: yuv420p
[DEBUG:0@0.085] global parallel.cpp:107 createDefaultParallelForAPI core(parallel): Initializing parallel backend...
[DEBUG:0@0.085] global registry_parallel.impl.hpp:69 ParallelBackendRegistry core(parallel): Builtin backends(3): ONETBB(1000); TBB(990); OPENMP(980)
[DEBUG:0@0.085] global registry_parallel.impl.hpp:94 ParallelBackendRegistry core(parallel): Available backends(3): ONETBB(1000); TBB(990); OPENMP(980)
[ INFO:0@0.085] global registry_parallel.impl.hpp:96 ParallelBackendRegistry core(parallel): Enabled backends(3, sorted by priority): ONETBB(1000); TBB(990); OPENMP(980)
[DEBUG:0@0.085] global parallel.cpp:65 createParallelForAPI core(parallel): trying backend: ONETBB (priority=1000)
[DEBUG:0@0.085] global plugin_parallel_wrapper.impl.hpp:233 getPluginCandidates Found 2 plugin(s) for ONETBB
[ INFO:0@0.085] global plugin_loader.impl.hpp:67 libraryLoad load D:\Guido\develop\opencv\build\bin\opencv_core_parallel_onetbb480_64.dll => FAILED
[ INFO:0@0.086] global plugin_loader.impl.hpp:67 libraryLoad load opencv_core_parallel_onetbb480_64.dll => FAILED
[DEBUG:0@0.086] global parallel.cpp:65 createParallelForAPI core(parallel): trying backend: TBB (priority=990)
[DEBUG:0@0.086] global plugin_parallel_wrapper.impl.hpp:233 getPluginCandidates Found 2 plugin(s) for TBB
[ INFO:0@0.086] global plugin_loader.impl.hpp:67 libraryLoad load D:\Guido\develop\opencv\build\bin\opencv_core_parallel_tbb480_64.dll => FAILED
[ INFO:0@0.086] global plugin_loader.impl.hpp:67 libraryLoad load opencv_core_parallel_tbb480_64.dll => FAILED
[DEBUG:0@0.086] global parallel.cpp:65 createParallelForAPI core(parallel): trying backend: OPENMP (priority=980)
[DEBUG:0@0.086] global plugin_parallel_wrapper.impl.hpp:233 getPluginCandidates Found 2 plugin(s) for OPENMP
[ INFO:0@0.086] global plugin_loader.impl.hpp:67 libraryLoad load D:\Guido\develop\opencv\build\bin\opencv_core_parallel_openmp480_64.dll => FAILED
[ INFO:0@0.086] global plugin_loader.impl.hpp:67 libraryLoad load opencv_core_parallel_openmp480_64.dll => FAILED
[DEBUG:0@0.086] global parallel.cpp:93 createParallelForAPI core(parallel): fallback on builtin code
[DEBUG:0@0.117] global cap_ffmpeg_impl.hpp:1609 retrieveFrame Input picture format: yuv420p
[DEBUG:0@0.146] global cap_ffmpeg_impl.hpp:1609 retrieveFrame Input picture format: yuv420p
...

(Codec hevc always generated (near) lossless, no matter what crf is set.)

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)
@nji9nji9 nji9nji9 added the bug label Nov 21, 2023
@mshabunin
Copy link
Contributor

Looks like this feature has not been implemented; should be used here:

err = !encode_video ? 0 : avcodec_open2(context, codec, NULL);

This environment variable can be only used to select HW encoders:
std::string getEncoderConfiguration(VideoAccelerationType va_type, AVDictionary *dict)

And default crf for H264 is always set to 23:
av_opt_set(c->priv_data,"crf","23", 0);

@nji9nji9
Copy link
Author

If that turns out to be the case (and it look's like to me, the freshman :) ) it should be added to the documentation.
Myself (and some more ...) searched/ posted/ got wrong answers etc. about that.
So a bug - not in the code - but in the documentation... (?).

@nji9nji9
Copy link
Author

Maybe in the documentation, the note on OPENCV_FFMPEG_WRITER_OPTIONS should be expanded by something like: "Restricted (so far) to ..."?

@mshabunin
Copy link
Contributor

I believe it would be better to implement this functionality, but temporarily it might be mentioned in the documentation, I agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants