rsnk96 / Ubuntu-Setup-Scripts

Scripts to help you set up your Ubuntu quickly, especially if you're in any subfield of Data Science or AI!
Apache License 2.0
126 stars 76 forks source link

Segmentation fault while using cv2.VideoCapture #66

Closed rajat2004 closed 4 years ago

rajat2004 commented 4 years ago
14thApostle commented 4 years ago

Just tried to open a video file with Videocapture, got the seg fault, tried tracing it back

(gdb) run video.py 
Starting program: /opt/anaconda3/bin/python video.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff3d0b700 (LWP 11538)]
[New Thread 0x7ffff350a700 (LWP 11539)]
[New Thread 0x7ffff0d09700 (LWP 11540)]
[New Thread 0x7fffee508700 (LWP 11541)]
[New Thread 0x7fffebd07700 (LWP 11542)]
[New Thread 0x7fffe9506700 (LWP 11543)]
[New Thread 0x7fffe4d05700 (LWP 11544)]
[New Thread 0x7fffe2504700 (LWP 11545)]
[New Thread 0x7fffdfd03700 (LWP 11546)]
[New Thread 0x7fffdd502700 (LWP 11547)]
[New Thread 0x7fffdad01700 (LWP 11548)]
[New Thread 0x7fffb65ae700 (LWP 11549)]
[New Thread 0x7fffb5dad700 (LWP 11550)]
[New Thread 0x7fffb35ac700 (LWP 11551)]
[New Thread 0x7fffb0dab700 (LWP 11552)]
[New Thread 0x7fffac5aa700 (LWP 11553)]
[New Thread 0x7fffabda9700 (LWP 11554)]
[New Thread 0x7fffa75a8700 (LWP 11555)]
[New Thread 0x7fffa4da7700 (LWP 11556)]
[New Thread 0x7fffa25a6700 (LWP 11557)]
[New Thread 0x7fff9fda5700 (LWP 11558)]
[New Thread 0x7fff9d5a4700 (LWP 11559)]

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
0x00007fffc3242fc1 in av_buffer_unref () from /opt/ffmpeg-build-script/workspace/lib/libavutil.so.56

(gdb) backtrace
0  0x00007fffc3242fc1 in av_buffer_unref () at /opt/ffmpeg-build-script/workspace/lib/libavutil.so.56
1  0x00007fffc324eea2 in av_frame_unref () at /opt/ffmpeg-build-script/workspace/lib/libavutil.so.56
2  0x00007fffcf046349 in CvCapture_FFMPEG::close() () at /usr/local/lib/libopencv_videoio.so.4.2
3  0x00007fffcf046660 in CvCapture_FFMPEG::open(char const*) () at /usr/local/lib/libopencv_videoio.so.4.2
4  0x00007fffcf04974f in cv::cvCreateFileCapture_FFMPEG_proxy(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () at /usr/local/lib/libopencv_videoio.so.4.2
5  0x00007fffcf01e9c6 in cv::StaticBackend::createCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const () at /usr/local/lib/libopencv_videoio.so.4.2
6  0x00007fffceffa077 in cv::VideoCapture::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) () at /usr/local/lib/libopencv_videoio.so.4.2
7  0x00007fffceffc9f5 in cv::VideoCapture::VideoCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) () at /usr/local/lib/libopencv_videoio.so.4.2
8  0x00007fffd560cdd3 in pyopencv_cv_VideoCapture_VideoCapture(pyopencv_VideoCapture_t*, _object*, _object*) ()
    at /opt/anaconda3/lib/python3.7/site-packages/cv2/python-3.7/cv2.cpython-37m-x86_64-linux-gnu.so
9  0x00005555556c0588 in type_call (kwds=0x0, args=0x7ffff7f80bd0, type=<optimized out>)
    at /tmp/build/80754af9/python_1565725737370/work/Objects/typeobject.c:971
10 0x00005555556c0588 in _PyObject_FastCallKeywords (callable=0x7fffd5a02a20 <pyopencv_VideoCapture_TypeXXX>, stack=0x7ffff7ef95c8, nargs=<optimized out>, kwnames=0x0)
    at /tmp/build/80754af9/python_1565725737370/work/Objects/call.c:199
11 0x00005555557246e8 in call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>)
    at /tmp/build/80754af9/python_1565725737370/work/Python/ceval.c:4619
12 0x00005555557246e8 in _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>)
    at /tmp/build/80754af9/python_1565725737370/work/Python/ceval.c:3093
13 0x0000555555668539 in _PyEval_EvalCodeWithName (_co=0x7ffff7f2af60, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>, kwnames=0x0, kwargs=0x0, kwcount=<optimized out>, kwstep=2, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0)
    at /tmp/build/80754af9/python_1565725737370/work/Python/ceval.c:3930
14 0x0000555555669424 in PyEval_EvalCodeEx (_co=<optimized out>, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0) at /tmp/build/80754af9/python_1565725737370/work/Python/ceval.c:3959
15 0x000055555566944c in PyEval_EvalCode (co=<optimized out>, globals=<optimized out>, locals=<optimized out>)
    at /tmp/build/80754af9/python_1565725737370/work/Python/ceval.c:524
16 0x000055555577eb74 in run_mod (mod=<optimized out>, filename=<optimized out>, globals=0x7ffff7f5bcd0, locals=0x7ffff7f5bcd0, flags=<optimized out>, arena=<optimized out>)
    at /tmp/build/80754af9/python_1565725737370/work/Python/pythonrun.c:1035
17 0x0000555555788eb1 in PyRun_FileExFlags (fp=0x555555909ca0, filename_str=<optimized out>, start=<optimized out>, globals=0x7ffff7f5bcd0, locals=0x7ffff7f5bcd0, closeit=1, flags=0x7fffffffdc20)
    at /tmp/build/80754af9/python_1565725737370/work/Python/pythonrun.c:988
18 0x00005555557890a3 in PyRun_SimpleFileExFlags (fp=0x555555909ca0, filename=<optimized out>, closeit=1, flags=0x7fffffffdc20) at /tmp/build/80754af9/python_1565725737370/work/Python/pythonrun.c:429
19 0x000055555578a195 in pymain_run_file (p_cf=0x7fffffffdc20, filename=0x5555558c0720 L"video.py", fp=0x555555909ca0) at /tmp/build/80754af9/python_1565725737370/work/Modules/main.c:433
20 0x000055555578a195 in pymain_run_filename (cf=0x7fffffffdc20, pymain=0x7fffffffdd30)
    at /tmp/build/80754af9/python_1565725737370/work/Modules/main.c:1612
21 0x000055555578a195 in pymain_run_python (pymain=0x7fffffffdd30)
    at /tmp/build/80754af9/python_1565725737370/work/Modules/main.c:2873
22 0x000055555578a195 in pymain_main (pymain=0x7fffffffdd30)
    at /tmp/build/80754af9/python_1565725737370/work/Modules/main.c:3413
rajat2004 commented 4 years ago

The problem is probably due to ffmpeg-build-script, might need to test some older commit of that repo

rsnk96 commented 4 years ago

@14thApostle can you link the video which you are trying to read? Will help reproduce the error

14thApostle commented 4 years ago

It's failing with every video I have tried, but this is the specific video that I tried here

rajat2004 commented 4 years ago

I'm not sure what more can be done, ran tests with FFmpeg 4.2.2 plus master branch of OpenCV and FFmpeg as well, but nothing worked Next thing probably will be to run OpenCV's videoio tests, plus some FFmpeg tests, maybe test some older versions of OpenCV as well, then maybe comment on an existing issue or open a new one at the OpenCV repo

Updates: Nasm source build, OpenCV 3 also doesn't work, then maybe it's a recent bug in FFmpeg?

rajat2004 commented 4 years ago

Using the apt installed FFmpeg does work, should we temporarily use them instead of the source built one until this problem is figured out?

rajat2004 commented 4 years ago

Using APT installed FFmpeg seems to be the easy and fast solution to me right now, while trying to figure out the correct solution for this The last commit can be reverted back when it's working correctly again

Edit: Any additional comments or notes in the Readme required?

rajat2004 commented 4 years ago

@rsnk96 This seems to be the simplest way to fix the scripts currently, will run tests and try to figure this out locally, while a PR to revert the last commit can be made if this goes in, and then keep testing it frequently. Some changes might be needed in the ffmpeg-build-script also

Let me know your thoughts on this or if there are better ways to fix

rajat2004 commented 4 years ago

@rsnk96 Thanks for the review and the commit! I've squashed the commits, will merge this after one final Travis build, and open a PR for reverting the last commit

rajat2004 commented 4 years ago

73 for reverting the commit