ytdl-org / youtube-dl

Command-line program to download videos from YouTube.com and other video sites
http://ytdl-org.github.io/youtube-dl/
The Unlicense
132.42k stars 10.04k forks source link

Youtube m4a files downloaded with --extract-audio can't play in some players #3681

Closed epitron closed 9 years ago

epitron commented 10 years ago

A number of audio players use libfaad to decode M4A/AAC files, and this library has a shortcoming: it can't play the files that are downloaded from youtube using youtube-dl --extract-audio.

The problem is that youtube's MP4 container has an empty "time-to-sample atom" (a.k.a. seek table).

This can be easily fixed using ffmpeg's remuxer:

$ ffmpeg -i in.m4a -acodec copy -movflags faststart out.m4a

I was thinking that this would be good to add as a postprocessing filter for sites whose audio files have no seek table.

Thoughts?

fogoat commented 10 years ago

I've been told by Winamp support they do not support playing files that are MPEG DASH (m4a).

I use ffmpeg to convert the m4a DASH audio to m4a AAC LC via

ffmpeg -i input.m4a -vn -c:a copy output.m4a

Wondering myself if there's an easier way to achieve this inside youtube-dl. Seems like you have a similar issue...?

hymced commented 9 years ago

Hi,

I have tried to pipe the youtube-dl output directly through ffmeg, but it appears not to be that simple if you want to keep the filenaming scheme of youtube-dl (I am trying to download a 1000 tracks playlist).

From my point of view, the simplier here would be to add an option into youtube-dl script with your command line @sunk818 , allowing to easily retrieve the filenames with internal variables

fogoat commented 9 years ago

This works for me in Windows 7 and will work on a certain file mask (ext) within one folder (fold) and save it to the designated folder (dest).

Save the below as a batch file such as convert.bat Then from the command line, use convert > run.bat This will create a batch file called run.bat Run.bat is the actual script that will perform the convert of the M4A DASH to just M4A.

set fold=c:\music\youtube-dl\ set ext=*.m4a set dest=c:\music\youtube-dl\converted\

for %%f in ("%fold%%ext%") do ECHO ffmpeg -i "%%f" -vn -acodec copy "%dest%%%~nxf"

hymced commented 9 years ago

I am on Mac OS X 10.9.4 :)

fogoat commented 9 years ago

It's not hard to find a unix equivalent. Try superuser.com

On Jan 18, 2015, at 10:39 PM, Ced notifications@github.com wrote:

I am on Mac OS X 10.9.4 :)

— Reply to this email directly or view it on GitHub.

hymced commented 9 years ago

I don't know anything about windows batch files (if that's how it's called...) but do your method allows to execute a conversion immediately after downloading each track, or is it something you run after downloading all the DASH audio tracks ?

fogoat commented 9 years ago

I do it after I download the entire playlist.

On Jan 19, 2015, at 1:31 PM, Ced notifications@github.com wrote:

I don't know anything about windows batch files (if that's how it's called...) but do your method allows to execute a conversion immediately after downloading each track, or is it something you run after downloading all the DASH audio tracks ?

— Reply to this email directly or view it on GitHub.

jaimeMF commented 9 years ago

You can use the --exec option, which runs a shell command for each video. For example: youtube-dl test:youtube --extract-audio --exec 'ffmpeg -y -i {} -vn -c:a copy {}.new.m4a'. If you want to keep the original filename you can just write a script (process-dash-audio.sh):

#!/bin/sh
inputname=$1

tempname=${inputname}.temp.m4a

echo "Processing dash audio: $inputname"
ffmpeg -y -i "$inputname" -vn -c:a copy "$tempname"

mv "$tempname" "$inputname"

Give it executable permissions and you can just run youtube-dl test:youtube --extract-audio --exec './process-dash-audio.sh {}'.

hymced commented 9 years ago

Sounds good ! I'll try that thanks :)

phihag commented 9 years ago

youtube-dl 2015.01.23.4 and newer will automatically correct the header of the m4a file if ffmpeg is present on the system. I am therefore closing this issue. See our FAQ if you need help updating. Thank you for the report!

hymced commented 9 years ago

thanks for this update :) works fine

stephenhartley commented 7 years ago

@phihag I ran youtube-dl version 2017.06.12 on MacOS 10.12.5, with ffmpeg version 3.3.1 on the path, and the header doesn't get corrected, I guess because youtube-dl can't find ffmpeg?

If I run the ffmpeg command given by @sunk818 as a manual step on the download then all is OK, but I thought youtube-dl should invoke this using the PATH location?

Specifying --ffmpeg-location (plus folder path) does not do the header correction.

Bit puzzled here, maybe this in an OSX-specific thing? The permissions of ffmpeg look OK - I deleted the extended attributes on the ffmpeg executables while checking...

Peters-iMac:~ steve$ youtube-dl -v -f bestaudio "http://aod-dash-uk-live.akamaized.net/usp/auth/vod/piff_abr_full_audio/2011d5-b08spht3/vf_b08spht3_1bc5a5b3-a907-49d0-a46c-a13b0c1aa708.ism/pc_hd_abr_v2_uk_dash_master.mpd?__gda__=1497319576_2df07de3fa5ec99bba9667b59d5f6461" -o Texas_with_the_BBC_Scottish_Symphony_Orchestrav6.m4a
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'-v', u'-f', u'bestaudio', u'http://aod-dash-uk-live.akamaized.net/usp/auth/vod/piff_abr_full_audio/2011d5-b08spht3/vf_b08spht3_1bc5a5b3-a907-49d0-a46c-a13b0c1aa708.ism/pc_hd_abr_v2_uk_dash_master.mpd?__gda__=1497319576_2df07de3fa5ec99bba9667b59d5f6461', u'-o', u'Texas_with_the_BBC_Scottish_Symphony_Orchestrav6.m4a']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2017.06.12
[debug] Python version 2.7.10 - Darwin-16.6.0-x86_64-i386-64bit
[debug] exe versions: ffmpeg 3.3.1, ffprobe 3.3.1
[debug] Proxy map: {}
[generic] pc_hd_abr_v2_uk_dash_master: Requesting header
WARNING: Falling back on generic information extractor.
[generic] pc_hd_abr_v2_uk_dash_master: Downloading webpage
[generic] pc_hd_abr_v2_uk_dash_master: Extracting information
[debug] Invoking downloader on u'http://aod-dash-uk-live.akamaized.net/usp/auth/vod/piff_abr_full_audio/2011d5-b08spht3/vf_b08spht3_1bc5a5b3-a907-49d0-a46c-a13b0c1aa708.ism/dash/'
[dashsegments] Total fragments: 626
[download] Destination: Texas_with_the_BBC_Scottish_Symphony_Orchestrav6.m4a
[download] 100% of 153.29MiB in 04:33