Ask Your Question
0

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:
        ydl.download(['https://www.youtube.com/watch?v=668nUCeBHyY'])

##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
    while(cap.isOpened()):
      # Capture frame-by-frame
      ret, frame = cap.read()
      if ret == True:

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


        # Display the resulting frame
        cv2.imshow('Frame',frame)

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

      # Break the loop
      else: 
        break
      count = count + 1

    # When everything done, release the video capture object
    cap.release()

# Closes all the frames
cv2.destroyAllWindows()
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

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
0

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

mshabunin gravatar image

Looks like opencv in conda has ffmpeg support but not on Windows: https://github.com/conda-forge/opencv...

edit flag offensive delete link more

Comments

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: https://anaconda.org/search?q=opencv

The recipie is for this one: https://anaconda.org/conda-forge/opencv - 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
Login/Signup to Answer

Question Tools

2 followers

Stats

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

Seen: 35 times

Last updated: Apr 13