News:

--

Main Menu

YouTube HD videos use M4A audio files

Started by smaak, April 11, 2020, 12:38:00 PM

Previous topic - Next topic

smaak

To download 1080 or 1440 videos from YouTube you got to download the mp4 and m4a files separately and mix it together with AVIDM. But AviDemux do not support m4a audio files. So you got to convert it first with VLC to mp3 and then mix it with AVIDM. Is there a m4a plugin for AVIDM anywhere? There are millions of YouTube users who would need it.

eumagga0x2a

Quote from: smaak on April 11, 2020, 12:38:00 PM
To download 1080 or 1440 videos from YouTube you got to download the mp4 and m4a files separately and mix it together with AVIDM.

If you use youtube-dl, it will gladly automate all the steps if ffmpeg is in reach. You need just to pass format IDs joined by "+" (e.g. 137+140) as listed by the option -F as arguments to the option -f.

QuoteBut AviDemux do not support m4a audio files.

Right, Avidemux doesn't support mp4 files without a video track. It can use only raw audio streams as external audio.

QuoteSo you got to convert it first with VLC to mp3

No, this would be a very bad approach. Use ffmpeg in stream copy mode to extract the raw AAC stream from the mp4 container (the extension m4a is just for looks):

ffmpeg -i encapsulatedAAC.m4a -c copy rawAAC.aac

or let youtube-dl neatly automate everything.

QuoteIs there a m4a plugin for AVIDM anywhere? There are millions of YouTube users who would need it.

See above. I don't think a second mp4 demuxer just to accomodate this scenario makes sense, especially as superior solutions are readily available.

dosdan

#2
To expand upon this so you're sure to understand it, I'll work through an example. The following exercise was conducted in the D:\YouTube_dl  directory.

To see a list of formats available for download with youtube-dl.exe, include the "-F" option with the URL. (Options are case-sensitive):

D:\YouTube_dl>YouTube-dl -F https://youtu.be/fMNggEMMs3w

Note: including the full URL is not needed. "fMNggEMMs3w" would have sufficed

[youtube] fMNggEMMs3w: Downloading webpage
[info] Available formats for fMNggEMMs3w:
format code  extension  resolution note
249          webm       audio only tiny   57k , opus @ 50k (48000Hz), 1.71MiB
250          webm       audio only tiny   71k , opus @ 70k (48000Hz), 2.22MiB
140          m4a        audio only tiny  127k , m4a_dash container, mp4a.40.2@128k (44100Hz), 4.53MiB
251          webm       audio only tiny  136k , opus @160k (48000Hz), 4.37MiB
278          webm       256x144    144p  101k , webm container, vp9, 24fps, video only, 3.42MiB
160          mp4        256x144    144p  112k , avc1.4d400c, 24fps, video only, 3.88MiB
242          webm       426x240    240p  231k , vp9, 24fps, video only, 7.83MiB
133          mp4        426x240    240p  250k , avc1.4d4015, 24fps, video only, 8.60MiB
243          webm       640x360    360p  426k , vp9, 24fps, video only, 14.44MiB
134          mp4        640x360    360p  643k , avc1.4d401e, 24fps, video only, 22.27MiB
244          webm       854x480    480p  774k , vp9, 24fps, video only, 26.46MiB
135          mp4        854x480    480p 1191k , avc1.4d401e, 24fps, video only, 40.79MiB
247          webm       1280x720   720p 1569k , vp9, 24fps, video only, 52.85MiB
136          mp4        1280x720   720p 2367k , avc1.4d401f, 24fps, video only, 81.40MiB
248          webm       1920x1080  1080p 2721k , vp9, 24fps, video only, 93.31MiB
137          mp4        1920x1080  1080p 4441k , avc1.640028, 24fps, video only, 151.55MiB
18           mp4        640x360    360p  731k , avc1.42001E, mp4a.40.2@ 96k (44100Hz), 26.08MiB (best)



If we just specify the URL without any switches, youtube_dl will download what it thinks is the best-quality video and audio streams:

D:\YouTube_dl>youtube-dl fMNggEMMs3w

[youtube] fMNggEMMs3w: Downloading webpage
WARNING: Requested formats are incompatible for merge and will be merged into mkv.
[download] Destination: D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.f137.mp4
[download] 100% of 151.55MiB in 00:31
[download] Destination: D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.f251.webm
[download] 100% of 4.37MiB in 00:00
[ffmpeg] Merging formats into "D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.mkv"
Deleting original file D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.f137.mp4 (pass -k to keep)
Deleting original file D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.f251.webm (pass -k to keep)


Note: I've got an output configuration file set up so it puts these d/ls into the D:\youtube_dl\Videos\{session}\ subdirectory. Since there is no "session" associated with this particular file it uses the "NA" (not available) subdirectory.

Here it's selected format 137 (AVC) for the video and format 251 (Opus) for the audio. Since Opus can't be included in a MP4 container, it uses ffmpeg.exe, (situated either in the current directory, or located in a directory which is included in your Windows' environmental variable PATH list), to mux it into the more flexible MKV container.

To get it to d/l the .MPA format instead for the audio, we need to specifically mention it (and the video):

D:\YouTube_dl>youtube-dl -f 137+140 fMNggEMMs3w

[download] Destination: D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.f137.mp4
[download] 100% of 151.55MiB in 00:34
[download] Destination: D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.f140.m4a
[download] 100% of 4.53MiB in 00:00
[ffmpeg] Merging formats into "D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.mp4"
Deleting original file D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.f137.mp4 (pass -k to keep)
Deleting original file D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.f140.m4a (pass -k to keep)


To change the .WEBM stream in an already downloaded file to .MPA, you can download just the .MPA and then use FFMPEG to remux it:

D:\YouTube_dl>youtube-dl -f 140  fMNggEMMs3w

[youtube] fMNggEMMs3w: Downloading webpage
[download] Destination: D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.m4a
[download] 100% of 4.53MiB in 00:00
[ffmpeg] Correcting container in "D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.m4a"


D:\YouTube_dl>ffmpeg -i "D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.mkv" -i "D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.m4a" -codec copy -y -map 0:v:0 -map 1:a:0 "D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video_REMUXED.mp4"


ffmpeg version N-97219-g8beb9e571c Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.2.0 (Rev2, Built by MSYS2 project)
  configuration:  --disable-autodetect --enable-amf --enable-bzlib --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-iconv --enable-lzma --enable-nvenc --enable-schannel --enable-zlib --enable-sdl2 --enable-ffnvcodec --enable-nvdec --enable-cuda-llvm --enable-gmp --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libdav1d --disable-debug --extra-libs=-liconv --enable-gpl --enable-version3
  libavutil      56. 42.102 / 56. 42.102
  libavcodec     58. 77.101 / 58. 77.101
  libavformat    58. 42.100 / 58. 42.100
  libavdevice    58.  9.103 / 58.  9.103
  libavfilter     7. 77.101 /  7. 77.101
  libswscale      5.  6.101 /  5.  6.101
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Input #0, matroska,webm, from 'D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.mkv':
  Metadata:
    COMPATIBLE_BRANDS: iso6avc1mp41
    MAJOR_BRAND     : dash
    MINOR_VERSION   : 0
    ENCODER         : Lavf58.42.100
  Duration: 00:04:59.14, start: -0.007000, bitrate: 4371 kb/s
    Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 24 fps, 24 tbr, 1k tbn, 48 tbc (default)
    Metadata:
      HANDLER_NAME    : VideoHandler
      DURATION        : 00:04:59.084000000
    Stream #0:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
    Metadata:
      DURATION        : 00:04:59.141000000
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.m4a':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.42.100
  Duration: 00:04:59.19, start: 0.000000, bitrate: 126 kb/s
    Stream #1:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Output #0, mp4, to 'D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video_REMUXED.mp4':
  Metadata:
    COMPATIBLE_BRANDS: iso6avc1mp41
    MAJOR_BRAND     : dash
    MINOR_VERSION   : 0
    encoder         : Lavf58.42.100
    Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 24 fps, 24 tbr, 16k tbn, 1k tbc (default)
    Metadata:
      HANDLER_NAME    : VideoHandler
      DURATION        : 00:04:59.084000000
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 7178 fps=0.0 q=-1.0 Lsize=  159944kB time=00:04:59.16 bitrate=4379.7kbits/s speed=1.86e+03x
video:155100kB audio:4587kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.160918%



FFMPEG counts from zero. There are two "-i input_file". So the 1st input file becomes input #0 and the 2nd is input #1. The mapping means:
"From the 1st input file use its video stream as the 1st video stream in output file #0, and from the 2nd input file use its audio for the 1st audio stream in output file #0."

Or, incurring a slight audio quality loss, just transcode the audio stream in the already downloaded file:

D:\YouTube_dl>ffmpeg -i "D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.mkv" -codec:v copy -codec:a aac "D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video_TRANSCODED.mp4"

ffmpeg version N-97219-g8beb9e571c Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.2.0 (Rev2, Built by MSYS2 project)
  configuration:  --disable-autodetect --enable-amf --enable-bzlib --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-iconv --enable-lzma --enable-nvenc --enable-schannel --enable-zlib --enable-sdl2 --enable-ffnvcodec --enable-nvdec --enable-cuda-llvm --enable-gmp --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libdav1d --disable-debug --extra-libs=-liconv --enable-gpl --enable-version3
  libavutil      56. 42.102 / 56. 42.102
  libavcodec     58. 77.101 / 58. 77.101
  libavformat    58. 42.100 / 58. 42.100
  libavdevice    58.  9.103 / 58.  9.103
  libavfilter     7. 77.101 /  7. 77.101
  libswscale      5.  6.101 /  5.  6.101
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Input #0, matroska,webm, from 'D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.mkv':
  Metadata:
    COMPATIBLE_BRANDS: iso6avc1mp41
    MAJOR_BRAND     : dash
    MINOR_VERSION   : 0
    ENCODER         : Lavf58.42.100
  Duration: 00:04:59.14, start: -0.007000, bitrate: 4371 kb/s
    Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 24 fps, 24 tbr, 1k tbn, 48 tbc (default)
    Metadata:
      HANDLER_NAME    : VideoHandler
      DURATION        : 00:04:59.084000000
    Stream #0:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
    Metadata:
      DURATION        : 00:04:59.141000000
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video.m4a':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.42.100
  Duration: 00:04:59.19, start: 0.000000, bitrate: 126 kb/s
    Stream #1:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (opus (native) -> aac (native))
Press [q] to stop, [?] for help
Output #0, mp4, to 'D:\youtube_dl\Videos\NA\Rebirth_of_Slick_Cool_Like_Dat_-_Naturally_7_Official_Video_TRANSCODED.mp4':
  Metadata:
    COMPATIBLE_BRANDS: iso6avc1mp41
    MAJOR_BRAND     : dash
    MINOR_VERSION   : 0
    encoder         : Lavf58.42.100
    Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 24 fps, 24 tbr, 16k tbn, 1k tbc (default)
    Metadata:
      HANDLER_NAME    : VideoHandler
      DURATION        : 00:04:59.084000000
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      DURATION        : 00:04:59.141000000
      encoder         : Lavc58.77.101 aac
frame= 7178 fps=1366 q=-1.0 Lsize=  160002kB time=00:04:59.14 bitrate=4381.6kbits/s speed=56.9x
video:155100kB audio:4668kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.146907%
[aac @ 000002c2e4ec6780] Qavg: 1107.480



Dan.