Repository: ytdl-org/youtube-dl

Issue:
Stream to vlc
Streaming video to vlc.



Discussion:
Sorry, I don't understand. Could you [elaborate](https://github.com/rg3/youtube-dl#is-the-description-of-the-issue-itself-sufficient) and [provide some context](https://github.com/rg3/youtube-dl#is-there-enough-context-in-your-bug-report)? You can run vlc just fine on the downloaded files, or output the video to stdout with `-o -`.

if you want to stream youtube directly to vlc, without a temporary file, just use the built in support for it in vlc:
"vlc youtubelink"

for example:
vlc http://www.youtube.com/watch?v=C0DPdy98e4c

If you are running a GNU/Linux system, you can stream videos directly to your favorite media player by using `youtube-dl -o - "http://your.media/url" | mplayer -`

You can also set up a function in your `~/.bash_aliases` file like

```
function streamer() {
youtube-dl -o - "$1" | mplayer - 
}
```

and run it like `streamer http://your.media/url`. You can of course replace mplayer with another player command, like vlc.

_Side note to the devs: maybe this should be made a command line switch? Like `youtube-dl --stream`? Let the user set a favorite player in the confg file, or try a list of known players?_

If you're not interested maybe this ticket can be closed.

[quote]
if you want to stream youtube directly to vlc, without a temporary file, just use the built in support for it in vlc:
"vlc youtubelink"

for example:
vlc http://www.youtube.com/watch?v=C0DPdy98e4c
[/quote]

I believe that you have to use the "real" URL with VLC, not the "Web URL".
So, you have to run youtube-dl with the "-j" option, to translate the web url to the "real" URL, then pass that URL to VLC.

The "point" is to use youtube-dl as a wrapper for streams which uses a token.
@nodiscc made a really a nice solution to manage that!

I second @nodiscc regarding the --stream option, and had a particular use-case in mind.

A --stream option would be great

I'm trying the "-o -" solution, but with some websites (e.g. periscope) it doesn't work: I get the stream saved to a file named "-". Is this expected behaviour (due to limitations of some website or video format), or is it a bug in that particular extractor?

+1 to the last question

This feature indeed needs some extra codes for live streams. (m3u8 from periscope, etc.)

this patch will make them work as well:

``` diff
diff --git a/youtube_dl/downloader/external.py b/youtube_dl/downloader/external.py
index 30277dc..cda39fe 100644
--- a/youtube_dl/downloader/external.py
+++ b/youtube_dl/downloader/external.py
@@ -225,7 +225,7 @@ class FFmpegFD(ExternalFD):

         args += ['-i', url, '-c', 'copy']
         if protocol == 'm3u8':
-            if self.params.get('hls_use_mpegts', False):
+            if self.params.get('hls_use_mpegts', False) or tmpfilename == '-':
                 args += ['-f', 'mpegts']
             else:
                 args += ['-f', 'mp4', '-bsf:a', 'aac_adtstoasc']
@@ -235,7 +235,10 @@ class FFmpegFD(ExternalFD):
             args += ['-f', EXT_TO_OUT_FORMATS.get(info_dict['ext'], info_dict['ext'])]

         args = [encodeArgument(opt) for opt in args]
-        args.append(encodeFilename(ffpp._ffmpeg_filename_argument(tmpfilename), True))
+        if tmpfilename == '-':
+            args.append('pipe:1')
+        else:
+            args.append(encodeFilename(ffpp._ffmpeg_filename_argument(tmpfilename), True))

         self._debug_cmd(args)
```

tested with mplayer, mpv in urls that return encrypted or live m3u8 manifests (should work with others):

```
python __main__.py -q -o - video_url | mplayer -
```


Resolving patch:
diff --git a/youtube_dl/downloader/external.py b/youtube_dl/downloader/external.py
--- a/youtube_dl/downloader/external.py
+++ b/youtube_dl/downloader/external.py
@@ -225,7 +225,7 @@ def _call_downloader(self, tmpfilename, info_dict):
 
         args += ['-i', url, '-c', 'copy']
         if protocol == 'm3u8':
-            if self.params.get('hls_use_mpegts', False):
+            if self.params.get('hls_use_mpegts', False) or tmpfilename == '-':
                 args += ['-f', 'mpegts']
             else:
                 args += ['-f', 'mp4', '-bsf:a', 'aac_adtstoasc']
diff --git a/youtube_dl/postprocessor/ffmpeg.py b/youtube_dl/postprocessor/ffmpeg.py
--- a/youtube_dl/postprocessor/ffmpeg.py
+++ b/youtube_dl/postprocessor/ffmpeg.py
@@ -175,7 +175,8 @@ def _ffmpeg_filename_argument(self, fn):
         # Always use 'file:' because the filename may contain ':' (ffmpeg
         # interprets that as a protocol) or can start with '-' (-- is broken in
         # ffmpeg, see https://ffmpeg.org/trac/ffmpeg/ticket/2127 for details)
-        return 'file:' + fn
+        # Also leave '-' intact in order not to break streaming to stdout.
+        return 'file:' + fn if fn != '-' else fn
 
 
 class FFmpegExtractAudioPP(FFmpegPostProcessor):


Test patch: