Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect parameters passed to ffmpeg for some youtube videos when extracting audio #23862

Closed
RasmusMathiesen opened this issue Jan 27, 2020 · 2 comments

Comments

@RasmusMathiesen
Copy link

@RasmusMathiesen RasmusMathiesen commented Jan 27, 2020

Checklist

  • I'm reporting a broken site support
  • I've verified that I'm running youtube-dl version 2020.01.24
  • I've checked that all provided URLs are alive and playable in a browser
  • I've checked that all URLs and arguments with special characters are properly quoted or escaped
  • I've searched the bugtracker for similar bug reports including closed ones
  • I've read bugs section in FAQ

Verbose log

PS C:\Users\rasmu\Desktop\youtube test\ffmpeg test> youtube-dl --format "bestaudio" --extract-audio --audio-format "opus" --audio-quality "32K" -v -k sZlzYzyREAI
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['--format', 'bestaudio', '--extract-audio', '--audio-format', 'opus', '--audio-quality', '32K', '-v', '-k', 'sZlzYzyREAI']
[debug] Encodings: locale cp1252, fs utf-8, out utf-8, pref cp1252
[debug] youtube-dl version 2020.01.24
[debug] Python version 3.8.1 (CPython) - Windows-10-10.0.18362-SP0
[debug] exe versions: ffmpeg 4.2.1, ffprobe 4.2.1
[debug] Proxy map: {}
[youtube] sZlzYzyREAI: Downloading webpage
[youtube] sZlzYzyREAI: Downloading video info webpage
[debug] Invoking downloader on 'https://r2---sn-uqj-j2iz.googlevideo.com/videoplayback?expire=1580151038&ei=ntwuXoDTKouw7ASb2ZioDA&ip=85.129.39.156&id=o-AC8oimTbXK1hrX6ldL4tBRW9GcZQC0Vk7ITr4yuocT6N&itag=251&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-uqj-j2iz%2Csn-5goeen7y&ms=au%2Crdu&mv=m&mvi=1&pcm2cms=yes&pl=24&initcwndbps=1946250&vprv=1&mime=audio%2Fwebm&gir=yes&clen=3052076&dur=179.981&lmt=1577947661429043&mt=1580129298&fvip=2&keepalive=yes&fexp=23842630&c=WEB&txp=6531432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=ALgxI2wwRgIhANZsUUKYO2cMcsbiKeP3rv4oVx6Yo9rdYm0r-0LLjVDlAiEAqq_ZjgmzRFyLzVqoFfDl7F4VM3PUQpsHX0m-tq5JqIM%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpcm2cms%2Cpl%2Cinitcwndbps&lsig=AHylml4wRQIgRrn29VzcA3J6XnDE8v_FMXFTlQqtAlf1vc_vav4clDMCIQD-k0gXKMYC-BEOHCVoKTQkxpIhgakdC5G4gnbcO_FwjA%3D%3D&ratebypass=yes'
[download] Destination: Crew Dragon Animation-sZlzYzyREAI.webm
[download] 100% of 2.91MiB in 00:00
[debug] ffmpeg command line: ffprobe -show_streams "file:Crew Dragon Animation-sZlzYzyREAI.webm"
[ffmpeg] Destination: Crew Dragon Animation-sZlzYzyREAI.opus
[debug] ffmpeg command line: ffmpeg -y -loglevel "repeat+info" -i "file:Crew Dragon Animation-sZlzYzyREAI.webm" -vn -acodec copy "file:Crew Dragon Animation-sZlzYzyREAI.opus"


PS C:\Users\rasmu\Desktop\youtube test\ffmpeg test> youtube-dl --format "bestaudio" --extract-audio --audio-format "opus" --audio-quality "32K" -v -k _yDZY5_u8FQ
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['--format', 'bestaudio', '--extract-audio', '--audio-format', 'opus', '--audio-quality', '32K', '-v', '-k', '_yDZY5_u8FQ']
[debug] Encodings: locale cp1252, fs utf-8, out utf-8, pref cp1252
[debug] youtube-dl version 2020.01.24
[debug] Python version 3.8.1 (CPython) - Windows-10-10.0.18362-SP0
[debug] exe versions: ffmpeg 4.2.1, ffprobe 4.2.1
[debug] Proxy map: {}
[youtube] _yDZY5_u8FQ: Downloading webpage
[youtube] _yDZY5_u8FQ: Downloading video info webpage
[debug] Invoking downloader on 'https://r4---sn-uqj-j2iz.googlevideo.com/videoplayback?expire=1580151130&ei=-twuXs-3C5ijyQX07pHIAg&ip=85.129.39.156&id=o-AMsz9Kozz0cklMoCv5UuZLx2iPbjdTzTY7wBScvUuuGJ&itag=258&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-uqj-j2iz%2Csn-5goeen7y&ms=au%2Crdu&mv=m&mvi=3&pl=24&initcwndbps=1941250&vprv=1&mime=audio%2Fmp4&gir=yes&clen=3266848&dur=67.370&lmt=1579640280116448&mt=1580129455&fvip=4&keepalive=yes&fexp=23842630&c=WEB&txp=1311222&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=ALgxI2wwRgIhAKt9kOSsSg1xjFDzUx-d8oxIMdZauKt6AappqL5PB0M8AiEAhS-6uMZv6qiCHjC3EucyX8ffSXf-LlnU55zgk4IumP8%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRQIgfSn1ClMl4BI0jGOlLNyzay1f56nqF-j6xl-gof9pJkQCIQDs-6cYSmOzhZb4I0XpIOZETk70kIoz78gk8MFZ-PqGGA%3D%3D&ratebypass=yes'
[download] Destination: Why Does Space Inspire Us Elon Musk-_yDZY5_u8FQ.m4a
[download] 100% of 3.12MiB in 00:00
[ffmpeg] Correcting container in "Why Does Space Inspire Us Elon Musk-_yDZY5_u8FQ.m4a"
[debug] ffmpeg command line: ffmpeg -y -loglevel "repeat+info" -i "file:Why Does Space Inspire Us Elon Musk-_yDZY5_u8FQ.m4a" -c copy -f mp4 "file:Why Does Space Inspire Us Elon Musk-_yDZY5_u8FQ.temp.m4a"
[debug] ffmpeg command line: ffprobe -show_streams "file:Why Does Space Inspire Us Elon Musk-_yDZY5_u8FQ.m4a"
[ffmpeg] Destination: Why Does Space Inspire Us Elon Musk-_yDZY5_u8FQ.opus
[debug] ffmpeg command line: ffmpeg -y -loglevel "repeat+info" -i "file:Why Does Space Inspire Us Elon Musk-_yDZY5_u8FQ.m4a" -vn -acodec libopus "-b:a" 32k "file:Why Does Space Inspire Us Elon Musk-_yDZY5_u8FQ.opus"

Description

When youtube-dl is given these options:

--format "bestaudio" --extract-audio --audio-format "opus" --audio-quality "32K" -v -k

The parameters passed to ffmpeg are not the same for every youtube video when the same parameters are expected:

Expected ffmpeg parameters: (-acodec libopus "-b:a" 32k) (youtube-id "_yDZY5_u8FQ")

[debug] ffmpeg command line: ffmpeg -y -loglevel "repeat+info" -i "file:Why Does Space Inspire Us Elon Musk-_yDZY5_u8FQ.m4a" -vn -acodec libopus "-b:a" 32k "file:Why Does Space Inspire Us Elon Musk-_yDZY5_u8FQ.opus"

Unexpected ffmpeg parameters: (-acodec copy) (youtube-id "sZlzYzyREAI")

[debug] ffmpeg command line: ffmpeg -y -loglevel "repeat+info" -i "file:Crew Dragon Animation-sZlzYzyREAI.webm" -vn -acodec copy "file:Crew Dragon Animation-sZlzYzyREAI.opus"
@RasmusMathiesen
Copy link
Author

@RasmusMathiesen RasmusMathiesen commented Jan 27, 2020

I think I have identified the problem to be this line:

if self._preferredcodec == 'best' or self._preferredcodec == filecodec or (self._preferredcodec == 'm4a' and filecodec == 'aac'):

If the codec of the downloaded file (filecodec) is the same as the preferred codec (self._preferredcodec) then it doesn't matter if a preferred quality is specified, ffmpeg will be told to just copy the stream.

I don't think anyone expects this behaviour when passing a preferred quality, but in case someone currently relies on this behavior the best solution may be to add an option to always force re-encoding, and maybe an option to only convert if the downloaded file has a higher bitrate than preferred.

Currently this behaviour is undocumented so I'm not sure if it is intended or not. Regardless, I suggest officially labeling the current behaviour a feature and adding it to the documentation, and then adding a --force-conversion option. Who will make that decision or how can I request a decision be made about that?

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Jan 29, 2020

This is expected behavior. Conversion only happens when source and target formats are different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.