LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-06-2024, 02:53 PM   #1
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,218
Blog Entries: 6

Rep: Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874
Youtube separate audio and video streams.


I thought that this might be useful for some of you.

Youtube continues to change every few days so that only separate audio and video streams are available. yt-dlp is keeping up with it. I've had to update yt-dlp 4 times in the last 30 days to keep up. And, it may take a couple of days for them to update. I suspect that youtube is going to continue to do that. And for those of you that can't update yt-dlp every week, that might be hacking you off.

In the mean time, waiting for yt-dlp to update, or if you can't, you can use the version of yt-dlp that you have and something like ffmpeg to play those videos. Just get an audio and a video stream, play them both at once.

For example:
https://m.youtube.com/watch?v=M-k_BW8iLkk

Code:
yt-dlp -F https://m.youtube.com/watch?v=M-k_BW8iLkk
sb3     mhtml 48x27        0    │                 mhtml │ images                                  storyboard
sb2     mhtml 80x45        0    │                 mhtml │ images                                  storyboard
sb1     mhtml 160x90       0    │                 mhtml │ images                                  storyboard
sb0     mhtml 320x180      0    │                 mhtml │ images                                  storyboard
233     mp4   audio only        │                 m3u8  │ audio only          unknown             Default
234     mp4   audio only        │                 m3u8  │ audio only          unknown             Default
139-drc m4a   audio only      2 │   2.13MiB   49k https │ audio only          mp4a.40.5   49k 22k low, DRC, m4a_dash
139     m4a   audio only      2 │   2.13MiB   49k https │ audio only          mp4a.40.5   49k 22k low, m4a_dash
140-drc m4a   audio only      2 │   5.66MiB  129k https │ audio only          mp4a.40.2  129k 44k medium, DRC, m4a_dash
140     m4a   audio only      2 │   5.66MiB  129k https │ audio only          mp4a.40.2  129k 44k medium, m4a_dash
602     mp4   256x144     15    │ ~ 3.74MiB   85k m3u8  │ vp09.00.10.08   85k video only
394     mp4   256x144     30    │   3.07MiB   70k https │ av01.0.00M.08   70k video only          144p, mp4_dash
269     mp4   256x144     30    │ ~ 7.16MiB  164k m3u8  │ avc1.4D400C    164k video only
160     mp4   256x144     30    │   2.30MiB   53k https │ avc1.4D400C     53k video only          144p, mp4_dash
603     mp4   256x144     30    │ ~ 7.10MiB  162k m3u8  │ vp09.00.11.08  162k video only
278     webm  256x144     30    │   4.09MiB   94k https │ vp09.00.11.08   94k video only          144p, webm_dash
395     mp4   426x240     30    │   4.62MiB  106k https │ av01.0.00M.08  106k video only          240p, mp4_dash
229     mp4   426x240     30    │ ~13.63MiB  311k m3u8  │ avc1.4D4015    311k video only
133     mp4   426x240     30    │   5.32MiB  122k https │ avc1.4D4015    122k video only          240p, mp4_dash
604     mp4   426x240     30    │ ~12.59MiB  288k m3u8  │ vp09.00.20.08  288k video only
242     webm  426x240     30    │   5.40MiB  124k https │ vp09.00.20.08  124k video only          240p, webm_dash
396     mp4   640x360     30    │   8.04MiB  184k https │ av01.0.01M.08  184k video only          360p, mp4_dash
230     mp4   640x360     30    │ ~27.09MiB  619k m3u8  │ avc1.4D401E    619k video only
134     mp4   640x360     30    │   9.59MiB  220k https │ avc1.4D401E    220k video only          360p, mp4_dash
605     mp4   640x360     30    │ ~24.74MiB  565k m3u8  │ vp09.00.21.08  565k video only
243     webm  640x360     30    │   9.78MiB  224k https │ vp09.00.21.08  224k video only          360p, webm_dash
397     mp4   854x480     30    │  12.12MiB  277k https │ av01.0.04M.08  277k video only          480p, mp4_dash
231     mp4   854x480     30    │ ~36.57MiB  836k m3u8  │ avc1.4D401F    836k video only
135     mp4   854x480     30    │  14.09MiB  323k https │ avc1.4D401F    323k video only          480p, mp4_dash
606     mp4   854x480     30    │ ~31.81MiB  727k m3u8  │ vp09.00.30.08  727k video only
244     webm  854x480     30    │  13.04MiB  299k https │ vp09.00.30.08  299k video only          480p, webm_dash
398     mp4   1280x720    30    │  17.58MiB  402k https │ av01.0.05M.08  402k video only          720p, mp4_dash
232     mp4   1280x720    30    │ ~46.94MiB 1073k m3u8  │ avc1.4D401F   1073k video only
136     mp4   1280x720    30    │  19.14MiB  438k https │ avc1.4D401F    438k video only          720p, mp4_dash
609     mp4   1280x720    30    │ ~48.37MiB 1106k m3u8  │ vp09.00.31.08 1106k video only
247     webm  1280x720    30    │  21.10MiB  483k https │ vp09.00.31.08  483k video only          720p, webm_dash
You see that there are sep video and sep audio streams only. They have removed 18 and 22.

Not a problem.

This example will play format 134 and 140 together.
Code:
agent="Mozilla/5.0 (iPhone; CPU iPhone OS 17_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/119.0.6045.109 Mobile/15E148 Safari/604.1"
prev="https://m.youtube.com/watch?v=M-k_BW8iLkk"
a=$(yt-dlp --user-agent "$agent" -q -g -f 134 "$prev")
b=$(yt-dlp --user-agent "$agent" -q -g -f 140 "$prev")
ffplay pipe &
pid1=$!

ffmpeg -i "$a" -i "$b" -c:a copy -c:v copy -f nut pipe:1 > pipe

while :; do
    read -t 1 -s -n 1 key
    if [[ "$key" = [Qq] ]]; then
        kill "$pid1"
    fi
    exit
done
And I would of course script that, with the bandwidth that you want, with a menu to choose from.

Last edited by teckk; 08-06-2024 at 02:55 PM.
 
Old 08-07-2024, 01:26 AM   #2
lvm_
Senior Member
 
Registered: Jul 2020
Posts: 1,111

Rep: Reputation: 377Reputation: 377Reputation: 377Reputation: 377
If you specify the format as '-f <video>+<audio>' (e.g. -f 134+140 or -f bestvideo+besaudio), yt-dlp will mux it into a single file all by itself.
 
1 members found this post helpful.
Old 08-07-2024, 01:35 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,702

Rep: Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535
Quote:
Originally Posted by lvm_ View Post
If you specify the format as '-f <video>+<audio>' (e.g. -f 134+140 or -f bestvideo+besaudio), yt-dlp will mux it into a single file all by itself.
yes, that's what I wanted to tell also, you can first list all the available audio and video formats and download your preferred set (or use best). If I remember well you can use the same numbers in most cases, so [for example] the mentioned 134+140 usually works. But not always.
 
Old 08-07-2024, 07:31 AM   #4
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,218

Original Poster
Blog Entries: 6

Rep: Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874
If you do it that way, it will download both of them before it starts streaming. You might as well download to file, and then play the file.

The way I posted, it will start playing the video without downloading the whole thing first.

Good for previewing a video. Uses less bandwidth. You can also pause the stream and come back to it.

Edit:
That was for watching a youtube video outside of the web browser. Watching the stream as long as one wishes, and then stopping, without downloading the whole video. Just like a browser does.

Last edited by teckk; 08-07-2024 at 07:34 AM.
 
Old 08-07-2024, 08:01 AM   #5
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,218

Original Poster
Blog Entries: 6

Rep: Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874
When looking through youtube videos, one doesn't know if the video is worth downloading without previewing it. Especially if it is a large video.

I would rather look at a youtube video using the controls of a media player than look at it in a web browser window. Also, if you get the video url, that is all that you get, just the video. After that one can always download the video to have.

You can of course look at it the normal way in the browser window. Watch your system monitor. Takes a lot of bandwidth each time because you are getting more than just the video. Scripts run, ads, images.

Lighter and nicer youtube solution I think. Combined with a smaller light youtube app.

Like this:
https://0x0.st/XVfG.png
 
Old 08-07-2024, 08:07 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,702

Rep: Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535
I hate youtube, it always plays ads instead of the video, so I prefer to download it first.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How To Cast YouTube Videos From Your Phone To Raspberry Pi Using YouTube On TV (youtube.com/tv) LXer Syndicated Linux News 0 04-16-2021 01:30 AM
How do I play separate audio streams through both rear and front jacks? Solitivity Linux - General 6 01-30-2016 04:01 PM
Encoding separate audio channels to separate files omnio Linux - Software 0 06-01-2007 07:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration