LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-07-2020, 02:56 AM   #1
DynV
Member
 
Registered: Feb 2020
Location: Montreal, Canada
Distribution: Ubuntu 22.04.2
Posts: 51

Rep: Reputation: 1
youtube-dl to decent small size audio


I'm currently using
Quote:
youtube-dl --extract-audio --audio-format opus --audio-quality 8
and when looking at VLC codec info (Ctrl-J) and media statistics (other tab (from same window)) it show it's an Opus 32 bit 48 KHz and I estimate from the content bitrate fluctuation that its average is 150 Kbps (Is there a better way to get its average?) but I'd like something with a smaller file size. When I stream AAC 32 Kbps (radio), I like the (sound) quality; perhaps Opus would be a similar quality at that bitrate, or even better? I tried
Quote:
youtube-dl -f 'bestaudio' --audio-format opus --audio-quality 8
and the result is (sounds) horrible.

I've noticed multiple videos have audio starting from around what I think is 50 Kbps since it's mentioned
Quote:
opus @ 50k
in the resolution note column but if the quality is as good, or better, than AAC, I don't need something that good; as mentioned above AAC 32 Kbps is fine by me.

How can I get a decent small size audio from Youtube?

Thank you kindly

Last edited by DynV; 03-07-2020 at 03:03 AM.
 
Old 03-07-2020, 03:50 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
It sounds confusing.
You want less than 32kbps audio, and NOT opus? Am I understanding this correctly?
Basically youtube-dl works in this way:
  • it looks for all audio/video formats
  • it chooses the best available (possibly with restrictions added on the command line, but be careful, more than 1 restriction quickly leads to no suitable format available!)
  • it downloads the file(s)
  • possibly it muxes the chosen audio & video track together
To my knowledge it does NOT transcode anything by default, but there's a switch '--recode-video' you might want to look at (there's no --recode-audio, strangely. You might need to do that manually after downloading).
You really need to read youtube-dl's extensive man page.

For any of this to work with youtube-dl, a recent ffmpeg is a soft dependency.
 
Old 03-07-2020, 08:56 AM   #3
DynV
Member
 
Registered: Feb 2020
Location: Montreal, Canada
Distribution: Ubuntu 22.04.2
Posts: 51

Original Poster
Rep: Reputation: 1
Considering
Quote:
Originally Posted by DynV View Post
When I stream AAC 32 Kbps (radio), I like the (sound) quality [...] as mentioned above AAC 32 Kbps is fine by me.
(underlining just added) and if
Quote:
Originally Posted by DynV View Post
[...] Opus would be a similar quality at that bitrate, or even better[...]
is the case, then
Quote:
Originally Posted by DynV View Post
I've noticed multiple videos have audio starting from around what I think is [Opus] 50 Kbps [...]
would be at a quality considerably more than I need, and I'd prefer for it to end up at the sufficient quality is it mean it save a non-negligible amount of storage space.

It doesn't seem there's a man page for the program on my system but
Quote:
--help
has a long output, which I tried my best to understand. I forgot to mention in the OP that I attempted multiple #s for the 2nd command and, while the file size do change (depending on the #), they all sounded considerably less (good) than what's sufficient for me (AAC 32 Kbps).

If Opus is indeed better than AAC, I'd like for this process to occur:
  1. if there's an Opus between 24 & 32 Kbps, for it to be downloaded
  2. if there's an AAC between 32 & 48 Kbps, for it to be downloaded
  3. otherwise the best audio be downloaded then converted to the Opus equivalent of AAC 32 Kbps

Last edited by DynV; 03-07-2020 at 09:11 AM.
 
Old 03-07-2020, 10:57 AM   #4
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,140
Blog Entries: 6

Rep: Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828
http://manpages.ubuntu.com/manpages/...tube-dl.1.html

Use the -F switch to find the available formats.
Code:
youtube-dl -F https://www.youtube.com/watch?v=hXZ2AfBkPD4
[youtube] hXZ2AfBkPD4: Downloading webpage
[youtube] hXZ2AfBkPD4: Downloading video info webpage
[youtube] hXZ2AfBkPD4: Downloading MPD manifest
[info] Available formats for hXZ2AfBkPD4:
format code  extension  resolution note
139          m4a        audio only DASH audio   50k , m4a_dash container, mp4a.40.5@ 48k (22050Hz)
140          m4a        audio only DASH audio  130k , m4a_dash container, mp4a.40.2@128k (44100Hz)
251          webm       audio only DASH audio  136k , webm_dash container, opus @160k (48000Hz)
278          webm       256x144    DASH video   95k , webm_dash container, vp9, 30fps, video only
160          mp4        256x144    DASH video  108k , mp4_dash container, avc1.4d400b, 30fps, video only
242          webm       426x240    DASH video  220k , webm_dash container, vp9, 30fps, video only
133          mp4        426x240    DASH video  242k , mp4_dash container, avc1.4d400c, 30fps, video only
243          webm       640x360    DASH video  405k , webm_dash container, vp9, 30fps, video only
134          mp4        640x360    DASH video  508k , mp4_dash container, avc1.4d401e, 30fps, video only
244          webm       854x480    DASH video  752k , webm_dash container, vp9, 30fps, video only
135          mp4        854x480    DASH video 1155k , mp4_dash container, avc1.4d4014, 30fps, video only
247          webm       1280x720   DASH video 1505k , webm_dash container, vp9, 30fps, video only
136          mp4        1280x720   DASH video 1629k , mp4_dash container, avc1.4d401f, 30fps, video only
18           mp4        640x360    360p  374k , avc1.42001E, mp4a.40.2@ 96k (44100Hz), 17.68MiB
22           mp4        1280x720   720p  782k , avc1.64001F, mp4a.40.2@192k (44100Hz) (best)
Format 139, 50k, m4a is the smallest available for that video.
If you want it smaller, lower bitrate, then run it through ffmpeg

Quote:
If Opus is indeed better than AAC, I'd like for this process to occur:
1. if there's an Opus between 24 & 32 Kbps, for it to be downloaded
2. if there's an AAC between 32 & 48 Kbps, for it to be downloaded
3. otherwise the best audio be downloaded then converted to the Opus equivalent of AAC 32 Kbps
Make yourself a bash script to do what you are wanting with ffmpeg then.
youtube-dl is python and it uses ffmpeg as it's backend to reencode.
 
Old 03-07-2020, 12:43 PM   #5
DynV
Member
 
Registered: Feb 2020
Location: Montreal, Canada
Distribution: Ubuntu 22.04.2
Posts: 51

Original Poster
Rep: Reputation: 1
I plan to download playlists so doing it manually, using -F would take a long time. I was hoping for some assistance with automated -f as in the OP 2nd quote. Since youtube-dl has ffmpeg integrated, perhaps there's a way to go through it? I was hoping --audio-format opus --audio-quality 8 would do so.

Also if a bash script would be necessary, perhaps I can get assistance with that? I understand if you don't want to.
 
Old 03-08-2020, 09:32 PM   #6
DynV
Member
 
Registered: Feb 2020
Location: Montreal, Canada
Distribution: Ubuntu 22.04.2
Posts: 51

Original Poster
Rep: Reputation: 1
Is there a way the selection can be done automatically as in post #3 list (at its bottom) ?
 
Old 03-09-2020, 01:34 AM   #7
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
This sounds too convoluted to ask youtube-dl to find the suitable format - consider that not all formats are always available for every download.
I think your best bet is to let youtube-dl do its thing (download best quality available), then convert into whatever it is you want in a second step.
 
Old 03-09-2020, 02:06 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,897

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
Quote:
Originally Posted by DynV View Post
Is there a way the selection can be done automatically as in post #3 list (at its bottom) ?
obviously there is a way to do that:
1. get the list as it was explained
2. select the one you prefer (if you know how to do that and what to do if missing...)
3. run youtube-dl and specify the format you need.

from the other hand you may try to download and install the latest version and see this page: https://github.com/ytdl-org/youtube-...rmat-selection
 
Old 03-09-2020, 03:03 AM   #9
DynV
Member
 
Registered: Feb 2020
Location: Montreal, Canada
Distribution: Ubuntu 22.04.2
Posts: 51

Original Poster
Rep: Reputation: 1
By automatically I meant without doing -F previously, as in -f 'INSERT_APPROPRIATE_STRING_HERE', to do the as in post #3 list (at its bottom).
 
Old 03-09-2020, 06:46 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,897

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
so read the link I posted all the relevant options are listed and explained. You can choose your preferred solution.
 
Old 03-09-2020, 07:10 AM   #11
DynV
Member
 
Registered: Feb 2020
Location: Montreal, Canada
Distribution: Ubuntu 22.04.2
Posts: 51

Original Poster
Rep: Reputation: 1
I did read it even before starting this thread but I don't know how to do what I want (post #3 list). I'd think something like
Quote:
youtube-dl -f 'bestaudio[ext=opus][abr>=24][abr<=32]/bestaudio[ext=aac][abr>=32][abr<=48]/bestaudio'
would work but I'm not confident at all so I asked here.
 
Old 03-09-2020, 08:34 AM   #12
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,610

Rep: Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553
Quote:
Originally Posted by DynV View Post
I'd think something like [example] would work
What happened when you tried it?

 
Old 03-09-2020, 12:09 PM   #13
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,897

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
you can also specify the file size and the tool will choose depending on that....
 
Old 03-09-2020, 12:38 PM   #14
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,140
Blog Entries: 6

Rep: Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828
Oh, never notices that before
Code:
man youtube-dl | grep -A1 "\-filesize"
 
Old 03-09-2020, 07:13 PM   #15
DynV
Member
 
Registered: Feb 2020
Location: Montreal, Canada
Distribution: Ubuntu 22.04.2
Posts: 51

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by boughtonp View Post
What happened when you tried it?
Please note in the following there's a 2nd attempt, which I increased the maximum limit to capture the 50 Kbps Opus
Quote:
me@me-computer:~/Downloads$ youtube-dl -f 'bestaudio[ext=opus][abr>=24][abr<=50]/bestaudio[ext=aac][abr>=32][abr<=48]/bestaudio' https://www.youtube.com/watch?v=oPB4gk-SSEs
[youtube] oPB4gk-SSEs: Downloading webpage
[youtube] oPB4gk-SSEs: Downloading video info webpage
[download] Destination: Lemmy ,Slash & Dave Grohl - Ace Of Spades-oPB4gk-SSEs.webm
[download] 100% of 2.90MiB in 00:00
me@me-computer:~/Downloads$ mediainfo --Inform="General;%BitRate/String%" Lemmy\ \,Slash\ \&\ Dave\ Grohl\ -\ Ace\ Of\ Spades-oPB4gk-SSEs.webm
123 kb/s
me@me-computer:~/Downloads$ youtube-dl -F https://www.youtube.com/watch?v=oPB4gk-SSEs | grep -P '^\d+\s{2,}\w+\s{2,}audio only\s.*$'
249 webm audio only tiny 52k , opus @ 50k (48000Hz), 1.09MiB
250 webm audio only tiny 67k , opus @ 70k (48000Hz), 1.46MiB
140 m4a audio only tiny 128k , m4a_dash container, mp4a.40.2@128k (44100Hz), 2.99MiB
251 webm audio only tiny 130k , opus @160k (48000Hz), 2.90MiB
me@me-computer:~/Downloads$ rm Lemmy\ \,Slash\ \&\ Dave\ Grohl\ -\ Ace\ Of\ Spades-oPB4gk-SSEs.webm
me@me-computer:~/Downloads$ youtube-dl -f 'bestaudio[ext=opus][abr>=24][abr<60]/bestaudio[ext=aac][abr>=32][abr<=48]/bestaudio' https://www.youtube.com/watch?v=oPB4gk-SSEs
[youtube] oPB4gk-SSEs: Downloading webpage
[youtube] oPB4gk-SSEs: Downloading video info webpage
[download] Destination: Lemmy ,Slash & Dave Grohl - Ace Of Spades-oPB4gk-SSEs.webm
[download] 100% of 2.90MiB in 00:01
me@me-computer:~/Downloads$ mediainfo --Inform="General;%BitRate/String%" Lemmy\ \,Slash\ \&\ Dave\ Grohl\ -\ Ace\ Of\ Spades-oPB4gk-SSEs.webm
123 kb/s
I thought mediainfo might not work properly so I opened the file in VLC and in the window Current Media Information tab Statistics tree Input/Read entry Input bitrate, it fluctuated at a bit over 120 Kbps.
Quote:
Originally Posted by pan64 View Post
you can also specify the file size and the tool will choose depending on that....
That would also depend on the duration, and since I plan on downloading playlists, with the vast majority of the time which included videos have varying non-negligable durations, and often with a decent variation (ie: longest >= 150% shortest). The playlist can also contain videos with different audio only, which I assume would affect the file size.

Last edited by DynV; 03-09-2020 at 07:27 PM.
 
  


Reply



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
[SOLVED] No audio from mpg123; audio works from YouTube, ffplay, etc, etc maschelsea Slackware 7 03-03-2020 12:01 PM
[SOLVED] Simple audio player with a decent library feature or fast filesystem browsing Changes Linux - Software 10 11-07-2009 01:59 PM
LXer: Youtube-dl - Download videos from Youtube in openSUSE LXer Syndicated Linux News 1 08-14-2008 08:10 AM
Dual-booters: What's a decent partition size for RH Pcghost Linux - General 5 06-28-2006 08:15 PM
A decent audio player with a "music library" feature. does it exist for linux? martinr Linux - Software 12 04-17-2006 03:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:21 AM.

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