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

cv2.VideoWriter crashes with SIGSEGV on unknown fourcc #15088

Closed
dniku opened this issue Jul 18, 2019 · 7 comments
Closed

cv2.VideoWriter crashes with SIGSEGV on unknown fourcc #15088

dniku opened this issue Jul 18, 2019 · 7 comments
Labels
bug category: videoio needs investigation Collect and attach more details (build flags, stacktraces, input dumps, etc)
Milestone

Comments

@dniku
Copy link

dniku commented Jul 18, 2019

System information (version)
  • OpenCV => 4.1.0-2 from Arch repository
  • Operating System / Platform => Manjaro (fully updated)
Detailed description

In the Python wrapper, unknown fourcc causes cv2.VideoWriter to segfault.

Steps to reproduce
import cv2

fourcc = cv2.VideoWriter_fourcc(*'aaaa')
print(fourcc)
writer = cv2.VideoWriter('/tmp/test.avi', fourcc, 30.0, (320, 240))
$ python test.py
1633771873
OpenCV: FFMPEG: tag 0x61616161/'aaaa' is not found (format 'avi / AVI (Audio Video Interleaved)')'
fish: “python test.py” terminated by signal SIGSEGV (Address boundary error)
Desired solution

Python exception should be thrown. There should also be a way to check whether a fourcc is available without triggering the exception.

@alalek
Copy link
Member

alalek commented Jul 18, 2019

Can't reproduce.

Please provide this information:

  1. Collect stack trace via gdb
  2. Dump cv.getBuildInformation()
  3. Run with OPENCV_VIDEOIO_DEBUG=1 environment variable and collect stdout.

@dniku
Copy link
Author

dniku commented Jul 18, 2019

Stacktrace:

#0  0x00007fffed40652d in gst_app_src_end_of_stream () at /usr/lib/libgstapp-1.0.so.0
#1  0x00007ffff2596e93 in  () at /usr/lib/libopencv_videoio.so.4.1
#2  0x00007ffff25977d7 in  () at /usr/lib/libopencv_videoio.so.4.1
#3  0x00007ffff258fd45 in  () at /usr/lib/libopencv_videoio.so.4.1
#4  0x00007ffff2583dc8 in cv::VideoWriter::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int, double, cv::Size_<int>, bool) () at /usr/lib/libopencv_videoio.so.4.1
#5  0x00007ffff258572c in cv::VideoWriter::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, double, cv::Size_<int>, bool) () at /usr/lib/libopencv_videoio.so.4.1
#6  0x00007ffff258582b in cv::VideoWriter::VideoWriter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, double, cv::Size_<int>, bool) () at /usr/lib/libopencv_videoio.so.4.1
#7  0x00007ffff719c79d in  () at /usr/lib/python3.7/site-packages/cv2.cpython-37m-x86_64-linux-gnu.so
#8  0x00007ffff7baa6ea in _PyObject_FastCallKeywords () at /usr/lib/libpython3.7m.so.1.0
#9  0x00007ffff7babdc2 in  () at /usr/lib/libpython3.7m.so.1.0
#10 0x00007ffff7bed6b2 in _PyEval_EvalFrameDefault () at /usr/lib/libpython3.7m.so.1.0
#11 0x00007ffff7b97d18 in _PyEval_EvalCodeWithName () at /usr/lib/libpython3.7m.so.1.0
#12 0x00007ffff7b98aca in PyEval_EvalCodeEx () at /usr/lib/libpython3.7m.so.1.0
#13 0x00007ffff7b98aec in PyEval_EvalCode () at /usr/lib/libpython3.7m.so.1.0
#14 0x00007ffff7c698a5 in  () at /usr/lib/libpython3.7m.so.1.0
#15 0x00007ffff7c69c2b in PyRun_FileExFlags () at /usr/lib/libpython3.7m.so.1.0
#16 0x00007ffff7c6fec7 in PyRun_SimpleFileExFlags () at /usr/lib/libpython3.7m.so.1.0
#17 0x00007ffff7c72022 in  () at /usr/lib/libpython3.7m.so.1.0
#18 0x00007ffff7c721cc in _Py_UnixMain () at /usr/lib/libpython3.7m.so.1.0
#19 0x00007ffff7ddbee3 in __libc_start_main () at /usr/lib/libc.so.6
#20 0x000055555555505e in _start ()

(/usr/lib/libgstapp-1.0.so.0 is owned by gst-plugins-base-libs 1.16.0-3)

Build information

General configuration for OpenCV 4.1.0 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            /build/opencv/src/opencv_contrib-4.1.0/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2019-05-22T18:53:30Z
    Host:                        Linux 5.0.10-arch1-1-ARCH x86_64
    CMake:                       3.14.4
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2
      requested:                 SSE3
      required:                  SSE2
      disabled:                  SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (13 files):         + SSE3 SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (4 files):             + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (27 files):           + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (2 files):      + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                /usr/bin/c++  (ver 8.3.0)
    C++ flags (Release):         -march=x86-64 -mtune=generic -O2 -pipe -fno-plt   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -march=x86-64 -mtune=generic -O2 -pipe -fno-plt   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -fvisibility=hidden -fvisibility-inlines-hidden -g  -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -march=x86-64 -mtune=generic -O2 -pipe -fno-plt   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -march=x86-64 -mtune=generic -O2 -pipe -fno-plt   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -fvisibility=hidden -g  -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now  -Wl,--gc-sections  
    Linker flags (Debug):        -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now  -Wl,--gc-sections  
    ccache:                      NO
    Precompiled headers:         YES
    Extra dependencies:          dl m pthread rt
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc java line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 quality reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab viz xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv js matlab ovis python2 sfm ts
    Applications:                examples apps
    Documentation:               NO
    Non-free algorithms:         YES

  GUI: 
    GTK+:                        YES (ver 3.24.8)
      GThread :                  YES (ver 2.60.3)
      GtkGlExt:                  NO
    OpenGL support:              NO
    VTK support:                 YES (ver 8.2.0)

  Media I/O: 
    ZLib:                        /lib64/libz.so (ver 1.2.11)
    JPEG:                        /lib64/libjpeg.so (ver 80)
    WEBP:                        /lib64/libwebp.so (ver encoder: 0x020e)
    PNG:                         /lib64/libpng.so (ver 1.6.37)
    TIFF:                        /lib64/libtiff.so (ver 42 / 4.0.10)
    JPEG 2000:                   /lib64/libjasper.so (ver 2.0.16)
    OpenEXR:                     /lib64/libImath.so /lib64/libIlmImf.so /lib64/libIex.so /lib64/libHalf.so /lib64/libIlmThread.so (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      YES (2.2.6)
    FFMPEG:                      YES
      avcodec:                   YES (58.35.100)
      avformat:                  YES (58.20.100)
      avutil:                    YES (56.22.100)
      swscale:                   YES (5.3.100)
      avresample:                NO
    GStreamer:                   YES (1.16.0)
    v4l/v4l2:                    YES (linux/videodev2.h)

  Parallel framework:            TBB (ver 2019.0 interface 11005)

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2019.0.0 Gold [2019.0.0]
           at:                   /build/opencv/src/build/3rdparty/ippicv/ippicv_lnx/icv
    Intel IPP IW:                sources (2019.0.0)
              at:                /build/opencv/src/build/3rdparty/ippicv/ippicv_lnx/iw
    Lapack:                      YES (/usr/lib/liblapack.so /usr/lib/libblas.so /usr/lib/libcblas.so)
    Eigen:                       YES (ver 3.3.7)
    Custom HAL:                  NO
    Protobuf:                    build (3.5.1)

  OpenCL:                        YES (no extra features)
    Include path:                /build/opencv/src/opencv-4.1.0/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python 3:
    Interpreter:                 /usr/bin/python3 (ver 3.7.3)
    Libraries:                   /lib64/libpython3.7m.so (ver 3.7.3)
    numpy:                       /usr/lib/python3.7/site-packages/numpy/core/include (ver 1.16.3)
    install path:                /usr/lib/python3.7/site-packages

  Python (for build):            /usr/bin/python3

  Java:                          
    ant:                         /bin/ant (ver 1.10.6)
    JNI:                         /usr/lib/jvm/default/include /usr/lib/jvm/default/include/linux /usr/lib/jvm/default/include
    Java wrappers:               YES
    Java tests:                  NO

  Install to:                    /usr

With OPENCV_VIDEOIO_DEBUG=1:

[ WARN:0] VIDEOIO(FFMPEG): trying writer with filename='/tmp/test.avi' fourcc=0x61616161 fps=30 sz=320x240 isColor=1...
OpenCV: FFMPEG: tag 0x61616161/'aaaa' is not found (format 'avi / AVI (Audio Video Interleaved)')'
[ WARN:0] VIDEOIO(FFMPEG): can't create writer
[ WARN:0] VIDEOIO(GSTREAMER): trying writer with filename='/tmp/test.avi' fourcc=0x61616161 fps=30 sz=320x240 isColor=1...

@alalek
Copy link
Member

alalek commented Jul 18, 2019

I see this message about gst_app_src_end_of_stream:

** (python:21388): CRITICAL **: 21:29:21.178: gst_app_src_end_of_stream: assertion 'GST_IS_APP_SRC (appsrc)' failed

Fedora 29
$ OPENCV_VIDEOIO_DEBUG=1 ./setup_vars.sh python ../test_15088.py 
Setting vars for OpenCV 3.4.7-pre
Append PYTHONPATH: /home/alalek/projects/opencv/build/opencv/python_loader
1633771873
[ INFO:0] VIDEOIO: Enabled backends(6, sorted by priority): FFMPEG(1000); GSTREAMER(990); V4L2(980); CV_IMAGES(970); CV_MJPEG(960); FIREWIRE(950)
[ WARN:0] VIDEOIO(cvCreateVideoWriter_FFMPEG_proxy(filename, fourcc, fps, frameSize, isColor)): trying ...

OpenCV: FFMPEG: tag 0x61616161/'aaaa' is not found (format 'avi / AVI (Audio Video Interleaved)')'
[ WARN:0] VIDEOIO(cvCreateVideoWriter_FFMPEG_proxy(filename, fourcc, fps, frameSize, isColor)): result=(nil)  isOpened=-1...

[ WARN:0] VIDEOIO(cvCreateVideoWriter_GStreamer (filename.c_str(), fourcc, fps, cvSize(frameSize), isColor)): trying ...


(python:21388): GStreamer-CRITICAL **: 21:29:21.178: gst_element_make_from_uri: assertion 'gst_uri_is_valid (uri)' failed
[ WARN:0] OpenCV | GStreamer warning: OpenCV backend does not support passed FOURCC value

** (python:21388): CRITICAL **: 21:29:21.178: gst_app_src_end_of_stream: assertion 'GST_IS_APP_SRC (appsrc)' failed
[ WARN:0] OpenCV | GStreamer warning: Cannot send EOS to GStreamer pipeline
[ WARN:0] VIDEOIO(cvCreateVideoWriter_GStreamer (filename.c_str(), fourcc, fps, cvSize(frameSize), isColor)): result=(nil)...

[ WARN:0] VIDEOIO(createMotionJpegWriter(filename, fourcc, fps, frameSize, isColor)): trying ...

[ WARN:0] VIDEOIO(createMotionJpegWriter(filename, fourcc, fps, frameSize, isColor)): result=(nil)  isOpened=-1...

done

("done" is extra print() statement in the end of code snippet)

but it ends without crash.

Do you have some extra settings like G_DEBUG?

@dniku
Copy link
Author

dniku commented Jul 19, 2019

G_DEBUG=fatal_warnings does not seem to make any difference for me (output and stacktrace are identical). With GST_DEBUG=DEBUG, I get a lot of output which ends with:

0:00:00.537438627 25820 0x55aafef53200 INFO                GST_INIT gst.c:807:init_post: GLib runtime version: 2.60.4
0:00:00.537452130 25820 0x55aafef53200 INFO                GST_INIT gst.c:809:init_post: GLib headers version: 2.60.3
0:00:00.537458943 25820 0x55aafef53200 INFO                GST_INIT gst.c:810:init_post: initialized GStreamer successfully
0:00:00.537471440 25820 0x55aafef53200 DEBUG                default gsttracerutils.c:79:_priv_gst_tracing_init: Initializing GstTracer
0:00:00.537530796 25820 0x55aafef53200 INFO            GST_PIPELINE gstparse.c:337:gst_parse_launch_full: parsing pipeline description '/tmp/test.avi'
0:00:00.537566132 25820 0x55aafef53200 DEBUG           GST_PIPELINE parse.l:160:priv_gst_parse_yylex: flex: URL: /tmp/test.avi
0:00:00.537586367 25820 0x55aafef53200 DEBUG                default types.h:84:gst_parse_unescape: unescaping /tmp/test.avi
0:00:00.537604387 25820 0x55aafef53200 DEBUG                GST_URI gsturi.c:637:gst_element_make_from_uri: type:2, uri:/tmp/test.avi, elementname:(null)
0:00:00.538188377 25820 0x55aafef53200 DEBUG                GST_URI gsturi.c:644:gst_element_make_from_uri: No source for URI '/tmp/test.avi'
0:00:00.538241519 25820 0x55aafef53200 ERROR           GST_PIPELINE grammar.y:971:priv_gst_parse_yyparse: no source element for URI "/tmp/test.avi"
0:00:00.538275275 25820 0x55aafef53200 DEBUG           GST_PIPELINE grammar.y:1190:priv_gst_parse_launch: got 0 elements and 0 links
0:00:00.538298928 25820 0x55aafef53200 DEBUG     GST_PLUGIN_LOADING gstpluginfeature.c:107:gst_plugin_feature_load: loading plugin for feature 0x55aafef99120; 'pipeline'
0:00:00.538310319 25820 0x55aafef53200 INFO     GST_ELEMENT_FACTORY gstelementfactory.c:361:gst_element_factory_create: creating element "pipeline"
0:00:00.538385686 25820 0x55aafef53200 DEBUG                GST_BUS gstbus.c:230:gst_bus_init:<GstBus@0x55aafefa0ad0> created
0:00:00.538437115 25820 0x55aafef53200 DEBUG                    bin gstbin.c:499:gst_bin_init:<GstBin@0x55aaff1d21c0> using bus <bus0> to listen to children
0:00:00.538454637 25820 0x55aafef53200 DEBUG                GST_BUS gstbus.c:230:gst_bus_init:<GstBus@0x55aafefa0ba0> created
0:00:00.538485379 25820 0x55aafef53200 DEBUG               GST_POLL gstpoll.c:681:gst_poll_new: 0x55aaff144ed0: new controllable : 1
0:00:00.538546110 25820 0x55aafef53200 DEBUG               GST_POLL gstpoll.c:848:gst_poll_add_fd_unlocked: 0x55aaff144ed0: fd (fd:3, idx:0)
0:00:00.538566879 25820 0x55aafef53200 DEBUG               GST_POLL gstpoll.c:1015:gst_poll_fd_ctl_read_unlocked: 0x55aaff144ed0: fd (fd:3, idx:0), active : 1
0:00:00.538589723 25820 0x55aafef53200 DEBUG                GST_BUS gstbus.c:284:gst_bus_new:<bus1> created new bus
0:00:00.538612849 25820 0x55aafef53200 DEBUG          GST_PARENTAGE gstelement.c:3346:gst_element_set_bus_func:<GstPipeline@0x55aaff1d21c0> setting bus to 0x55aafefa0ba0
0:00:00.538629845 25820 0x55aafef53200 DEBUG               pipeline gstpipeline.c:233:gst_pipeline_init:<GstPipeline@0x55aaff1d21c0> set bus <bus1> on pipeline
0:00:00.538656886 25820 0x55aafef53200 DEBUG    GST_ELEMENT_FACTORY gstelementfactory.c:389:gst_element_factory_create: created element "pipeline"

@alalek
Copy link
Member

alalek commented Jul 21, 2019

Please try latest code from the master branch.
Let us know if this still doesn't work.

@dniku
Copy link
Author

dniku commented Jul 22, 2019

With the new version I am getting

OpenCV: FFMPEG: tag 0x61616161/'aaaa' is not found (format 'avi / AVI (Audio Video Interleaved)')'
[ WARN:0] global /home/ser/.cache/yay/opencv-git/src/opencv/modules/videoio/src/cap_gstreamer.cpp (1490) open OpenCV | GStreamer warning: OpenCV backend does not support passed FOURCC value
[ WARN:0] global /home/ser/.cache/yay/opencv-git/src/opencv/modules/videoio/src/cap_gstreamer.cpp (1272) close_ OpenCV | GStreamer warning: No source in GStreamer pipeline. Ignore
[ERROR:0] global /home/ser/.cache/yay/opencv-git/src/opencv/modules/videoio/src/cap.cpp (392) open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.1.1-pre) /home/ser/.cache/yay/opencv-git/src/opencv/modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): /tmp/test.avi in function 'icvExtractPattern'

which is certainly better than a segfault. Not sure whether this is nitpicking or not, but the last error does not seem relevant. If this is a problem, I could file a new issue; @alalek, could you comment on this?

@mshabunin
Copy link
Contributor

@Pastafarianist , it is not a problem. VideoWriter tries several different backends and each of them can emit own error message. You can explicitly set backend by providing its ID in constructor or open() method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug category: videoio needs investigation Collect and attach more details (build flags, stacktraces, input dumps, etc)
Projects
None yet
Development

No branches or pull requests

3 participants