I've tried numerous things including building from source (both opencv and ffmpeg with codecs) and nothing seems to help. I have a mp4 file that works fine with the python2.7 environment, but fails to load with python 3.5.
I know I have different builds installed, but I can't figure out why opencv fails to load for the python3.5 environment. I've checked paths, etc. I can't find anything amiss.
Python 2.7.12:
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.3.1'
>>> a=cv2.VideoCapture("Serenity.mp4")
>>> a.isOpened()
True
Python 3.5.2:
Python 3.5.2 (default, Sep 14 2017, 22:51:06)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.3.0'
>>> a=cv2.VideoCapture("Serenity.mp4")
>>> a.isOpened()
False
I've done the following:
- Uninstalled python and python3, and opencv
- Checked paths to modules
- video plays fine on vlc and ffmpeg has no problems
- test code using python2.7 plays video fine via opencv
- tried answers found here: Can't open video using opencv
- Tried this too Python OpenCV : VideoCapture differences between Python 2.7 to Python 3.5
Information on video sample:
ffprobe version 3.4 Copyright (c) 2007-2017 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.5) 20160609
configuration: --enable-pic
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3d57b00] stream 0, timescale not set
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Serenity.mp4':
Metadata:
major_brand : isom
minor_version : 1
compatible_brands: isomavc1
creation_time : 2007-05-30T05:20:31.000000Z
genre : Trailer
artist : Universal Pictures
title : Serenity - HD DVD Trailer
date : 2005
Duration: 00:02:19.71, start: 0.000000, bitrate: 4802 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 4674 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
Metadata:
creation_time : 2007-05-30T05:20:31.000000Z
handler_name : GPAC ISO Video Handler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
creation_time : 2007-05-30T05:20:34.000000Z
handler_name : GPAC ISO Audio Handler
Stream #0:2: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 240x240 [SAR 1:1 DAR 1:1], 90k tbr, 90k tbn, 90k tbc
Edit: I've also tried compiling from source using the methods outlined here based on suggestions from the comments (and swapping the .so file): https://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/
solved: After many attempts, I had to just wipe my Lubuntu 16.04.3 system and rebuild it. See detailed answer below.