Ask Your Question

How to add ffmpeg support to Opencv in Conda enviroment on Linux?

asked 2019-04-12 06:55:25 -0500

jecs89 gravatar image

updated 2019-04-13 09:41:06 -0500

supra56 gravatar image

I am trying to read a video with OpenCV after I downloaded with youtube-dl, all this on conda enviroment. But always it shows me " Error opening video stream or file". After of looking for a solution, I found many, i.e. ffmpeg support is not available then I tried but it does not work. Maybe there is other solution to read video from OpenCV, I am working with conda enviroment.

##Code to download video from youtube

 from __future__ import unicode_literals

    import cv2

    import youtube_dl

    def my_hook(d):
        if d['status'] == 'finished':
            print('Done downloading, now converting ...')

    ydl_opts = {
        'format': 'bestvideo/best',       
    #     'outtmpl': '%(id)s'+'.avi',
        'noplaylist' : True,        
        'progress_hooks': [my_hook],
    #     'vcodec': 'avi',

    with youtube_dl.YoutubeDL(ydl_opts) as ydl:[''])

##Code to read video with OpenCV

 import cv2
    import numpy as np

    # Create a VideoCapture object and read from input file
    # If the input is the camera, pass 0 instead of the video file name
    cap = cv2.VideoCapture('668.mp4')

    # Check if camera opened successfully
    if (cap.isOpened()== False): 
      print("Error opening video stream or file")

    count = 0

    # Read until video is completed
      # Capture frame-by-frame
      ret, frame =
      if ret == True:

        cv2.imwrite("frame%d.jpg" % count, frame)     # save frame as JPEG file

        # Display the resulting frame

        # Press Q on keyboard to  exit
        if cv2.waitKey(25) & 0xFF == ord('q'):

      # Break the loop
      count = count + 1

    # When everything done, release the video capture object

# Closes all the frames
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2019-04-13 09:44:55 -0500

supra56 gravatar image

updated 2019-04-13 09:45:21 -0500

@jecs89. You're missing ffmpeg. You are geting No, No No, etc. sudo apt-get install ffmpeg

edit flag offensive delete link more

answered 2019-04-12 07:43:25 -0500

mshabunin gravatar image

Looks like opencv in conda has ffmpeg support but not on Windows:

edit flag offensive delete link more


I am working on Linux Mint. When I send: print (cv2.getBuildInformation()) It shows does not have ffmpeg support.

jecs89 gravatar imagejecs89 ( 2019-04-12 09:58:31 -0500 )edit

There are several conda packages for opencv:

The recipie is for this one: - it has version 4.1.0

Try to install it using commands on that page.

mshabunin gravatar imagemshabunin ( 2019-04-12 18:08:38 -0500 )edit

Question Tools



Asked: 2019-04-12 06:55:25 -0500

Seen: 1,980 times

Last updated: Apr 13 '19