0

I have created a very simple youtube downloader but I have a problem to decide which format should I label as "the best audio" format.

As a reference I have read ytdl-core sourcecode (youtube downloader written in javascript) and they rank audio formats based on bitrate and encodings with high weight put on bitrate but I am wondering if sampling should also be taken into account.

Is there some golden rule I could use to decide based on bitrate, encoding and sampling which format has the best sound quality?


For example:
Here are two "formats" of the same youtube video. Is it possible to decide based on this data which has better sound quality?
A):

{
  mimeType: 'video/mp4; codecs="avc1.64001F, mp4a.40.2"',
  qualityLabel: '720p',
  bitrate: 1309340,
  audioBitrate: 192,
  itag: 22,
  width: 1280,
  height: 720,
  lastModified: '1617547492322166',
  quality: 'hd720',
  fps: 30,
  projectionType: 'RECTANGULAR',
  audioQuality: 'AUDIO_QUALITY_MEDIUM',
  approxDurationMs: '743201',
  audioSampleRate: '44100',
  audioChannels: 2,
  hasVideo: true,
  hasAudio: true,
  container: 'mp4',
  codecs: 'avc1.64001F, mp4a.40.2',
  videoCodec: 'avc1.64001F',
  audioCodec: 'mp4a.40.2',
  isLive: false,
  isHLS: false,
  isDashMPD: false
}

B)

{
  mimeType: 'audio/webm; codecs="opus"',
  qualityLabel: null,
  bitrate: 145005,
  audioBitrate: 160,
  itag: 251,
  initRange: { start: '0', end: '258' },
  indexRange: { start: '259', end: '1530' },
  lastModified: '1617547286610933',
  contentLength: '9831553',
  quality: 'tiny',
  projectionType: 'RECTANGULAR',
  averageBitrate: 105834,
  audioQuality: 'AUDIO_QUALITY_MEDIUM',
  approxDurationMs: '743161',
  audioSampleRate: '48000',
  audioChannels: 2,
  loudnessDb: -14.280001,
  hasVideo: false,
  hasAudio: true,
  container: 'webm',
  codecs: 'opus',
  videoCodec: null,
  audioCodec: 'opus',
  isLive: false,
  isHLS: false,
  isDashMPD: false
}

A has higher bitrate but B is using better codecs and has higher sample rate. Is it possible to tell which of them has better sound quality?

hdw3
  • 871
  • 10
  • 28
  • 1
    as with many things the values of bit depth and sample rate must be balanced to optimize efficiency in terms of storage requirements .. it makes no sense to have super high of either with a low value of the other .. typical CD quality has a bit depth of 16 bits with a sample rate of 48000 samples per second ... if you plot a raw audio curve and annotate those two attributes on the plot you can better appreciate why an unbalanced pair of those settings will lead to unnecessary storage requirements ... so to your question every bump up or down in sound quality should alter both of those settings – Scott Stensland Apr 07 '21 at 01:24
  • 1
    Reading between the lines, I think what you may be asking is _what is the use case for low / high bitrates_ or even _why would you choose a low sampling rate?_ . The best venue for these questions is dsp.stackexchange.com , but you may find their is an already existing question – fdcpp Apr 07 '21 at 06:58
  • E.g https://dsp.stackexchange.com/questions/17685/why-do-we-choose-44-1-khz-as-recording-sampling-rate/17702?r=SearchResults#17702 – fdcpp Apr 07 '21 at 07:01
  • That said, pragmatically you could take your cues on quality from video quality as well. A quality is _hd720_ and B quality is _tiny_ so you can extrapolate a little from that. – fdcpp Apr 07 '21 at 07:18
  • @fdcpp one of them has only audio (tiny) and the other has both audio and video so I think quality field isn't a good way to compare them but thanks for linking dsp.stack, I will try to look for an answer there – hdw3 Apr 07 '21 at 20:19

0 Answers0