简体   繁体   中英

Anaconda and Opencv does not open mp4

im trying to read an mp4 file in my python script with Opencv3 (which is installed in conda env) on ubuntu. But get following message :

Unable to stop the stream: Inappropriate ioctl for device

I found that Opencv does not support mp4 out of the box. Is it possible to install extra libs on my machine to make video work without rebuilding Opencv? Some configuration maybe?

Here comes the code :

def workOnVideoFile(path) : 
    print('Reading the video from ' + path )
    cap = cv2.VideoCapture(path)

    print('Is video opened?  ' + str(cap.isOpened()) )
    while(cap.isOpened()):

        ret, frame = cap.read()
        print('Frame has been read ' + str(ret))
        workOnFrame(frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    print('Releasing the video' + str(cap))
    cap.release()


#img = cv2.imread('car.jpg')



if __name__ == "__main__":
    if (os.path.isfile(videoFile)) :
        workOnVideoFile(videoFile)
    else : 
        print('File ' + videoFile + ' is not found')


cv2.destroyAllWindows()

I think its probably ubuntu which is not supporting MP4 out of the box - this is because MP4 has some patent issues.

The usual approach is to add support for MP4 in a standard way to an Ubuntu install like this:

sudo apt-get install ubuntu-restricted-extras

This name maybe looks a little odd but its more or less standard practice - see the help article here to reassure you:

Many people who want to just play back video simply install VideoLan which takes care of all this, so they don't have to do the step above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM