pato
pato

Reputation: 355

Play video file and audio file simultaneously from Linux command line

I would like to play a separate video stream and audio stream simultaneously from the Linux command line, using e.g. cvlc or mpv.

More specifically, I would like to play a youtube video in high quality format, using youtube-dl along with a player.


More details:

I am using this command to playback a youtube video on my pc:

youtube-dl -i <youtube.com/url> -o - | mpv -

Lets say I have following formats for a youtube video available:

249          webm       audio only tiny   62k , opus @ 50k (48000Hz), 14.14MiB
251          webm       audio only tiny  158k , opus @160k (48000Hz), 35.68MiB
303          webm       1920x1080  1080p60 4429k , vp9, 60fps, video only, 536.78MiB
299          mp4        1920x1080  1080p60 6901k , avc1.64002a, 60fps, video only, 884.09MiB
22           mp4        1280x720   720p 1339k , avc1.64001F, 30fps, mp4a.40.2@192k (44100Hz) (best)

youtube-dl would automatically choose the last entry of this list, as it is a format that includes video and audio in one file.

Is there a way I can play the formats 303 and 251 on my pc?

If I would like to download them I would use:

youtube-dl -i <youtube.com/url> -f 303+bestaudio

What youtube-dl does in this case is to download the video and the audio file seperately and merges them into one file using ffmpeg. But I can't figure if there is a possibility to playback both streams without first downloading them into a file.

Upvotes: 1

Views: 1382

Answers (1)

pato
pato

Reputation: 355

Alright I think I figured a solution.

The command I use is as follows:

ffmpeg -loglevel quiet -i $(youtube-dl -g youtube.com/url -f 303) -i $(youtube-dl -g youtube.com/url -f bestaudio) -f matroska -c copy - | mpv -

  • The youtube-dl -g option would just return the url to the video or audio stream.
  • In this case it will pass the urls to ffmpeg which is doing the merging process.
  • -f matroska tells ffmpeg to use the mkv container format
  • -c copy says that no re-encoding should be done

edit:
For some reason, on my systemm the input is broken after ffmpeg exits. For now I resolve this by typing reset, until I find a better solution to this issue.

Upvotes: 1

Related Questions