Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipe downloading video to opencv #11291

Closed
austinmilt opened this issue Nov 24, 2016 · 6 comments
Closed

Pipe downloading video to opencv #11291

austinmilt opened this issue Nov 24, 2016 · 6 comments

Comments

@austinmilt
Copy link

@austinmilt austinmilt commented Nov 24, 2016

Please follow the guide below

  • You will be asked some questions and requested to provide some information, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your issue (like that [x])
  • Use Preview tab to see how your issue will actually look like

Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2016.11.22. If it's not read this FAQ entry and update. Issues with outdated version will be rejected.

  • [X ] I've verified and I assure that I'm running youtube-dl 2016.11.22

Before submitting an issue make sure you have:

  • [X ] At least skimmed through README and most notably FAQ and BUGS sections
  • [ X] Searched the bugtracker for similar issues including closed ones

What is the purpose of your issue?

  • Bug report (encountered problems with youtube-dl)
  • Site support request (request for adding support for a new site)
  • Feature request (request for a new functionality)
  • [ X] Question
  • Other

The following sections concretize particular purposed issues, you can erase any section (the contents between triple ---) not applicable to your issue

Description of your issue, suggested solution and other information

I am writing a program to analyze the contents of a Youtube video using opencv. Ideally, I would like to be able to analyze the video while it is downloading (i.e. as if it were streaming on Youtube), and then throw away frames that have already been analyzed without ever writing to disk. Is it possible for me to pipe youtube_dl's download directly to another process rather than to disk, or some other workaround that would achieve my aims?

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Nov 27, 2016

Like this:

youtube-dl -o - <the URL> | your_program
@yan12125 yan12125 closed this Nov 27, 2016
@austinmilt
Copy link
Author

@austinmilt austinmilt commented Nov 27, 2016

Thanks for your reply yan12125, but you didnt answer my question. Perhaps I need to be more explicit...

Let's say I have a Youtube URL and I'm interested in analyzing the video without saving it to disk. Further, I am interested in doing this analysis using opencv in Python. In my Python script, I would write:

import cv2, youtube_dl
options = {'outtmpl': #SOMETHING#}
Y = youtube_dl.YoutubeDL(options)
Y.extract_info(r'http://some.url')

Does this make more sense?

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Nov 27, 2016

The youtube_dl Python library doesn't support streaming to Python objects yet, so the current solution is using subprocess.Popen. For YouTube, things are simpler as they serve plain HTTP files, so you can do something like this:

info_dict = Y.extract_info(url, download=False)
video_stream = urllib.request.urlopen(info_dict['url'])
# video_stream is a file-like object with read() method
@austinmilt
Copy link
Author

@austinmilt austinmilt commented Nov 27, 2016

Thanks for your response. I am able to get a stream as you have indicated, but I dont understand what to do with it. How do I decode the stream into a useable format? Others suggest that for live streams you can use opencv's cv2.imdecode and numpy's numpy.fromstring, but I am only getting nonsense from this. Is there further I can do using youtube_dl or do I need to start looking elsewhere after I get the url?

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Nov 27, 2016

YouTube videos are served as mp4 or webm files. Those files are usually compressed, so you need to decompress them first to get frame-by-frame images.

@austinmilt
Copy link
Author

@austinmilt austinmilt commented Nov 27, 2016

Thanks for your help. I'm at a loss for now and can live with downloading the video.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.