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

Twitch ads break recorded audio #21985

Closed
nurupo opened this issue Aug 2, 2019 · 4 comments
Closed

Twitch ads break recorded audio #21985

nurupo opened this issue Aug 2, 2019 · 4 comments

Comments

@nurupo
Copy link

@nurupo nurupo commented Aug 2, 2019

Checklist

  • I'm reporting a broken site support issue
  • I've verified that I'm running youtube-dl version 2019.08.02
  • 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

Not available.

Description

I'm downloading audio-only of a live stream like this:

youtube-dl -ci -o out.m4a --extract-audio --audio-quality 0 --no-part https://twitch.tv/example

This works great when Twitch doesn't insert ads and results in:

$ ffmpeg -i out1.m4a
ffmpeg version 3.2.14-1~deb9u1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
[...]
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out1.m4a':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf57.56.101
  Duration: 06:25:12.96, start: 0.005000, bitrate: 164 kb/s
    Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 163 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

However, when Twitch inserts ads in the beginning, the resulting --extract-audio file has a video (!) stream in it that lasts about 30 seconds that consists of Twitch ads. The actual stream audio after that 30-second segment is all broken -- the audio has silent segments every few milliseconds, i.e. it keeps skipping, as tested in VLC and mpv. VLC and mpv have hard time playing it too, it takes seconds for them to seek in the file, sometimes they even hang. Also, the resulting audio has incorrect frequency set as reported by ffmpeg: 44100 Hz, when it should be 48000 Hz as in the out1.m4a output from above - the streamer streams audio in 48000 Hz. (It might be worth noting that in the first 30 seconds, the Twitch ad part, the audio is fine, it's the stream's audio after that that is broken.) Here is what ffmpeg reporting on it:

$ ffmpeg -i out2.m4a
[...]
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out2.m4a':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.56.101
  Duration: 06:22:54.98, start: 0.000000, bitrate: 170 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, unknown/bt709/unknown), 1920x1080, 3252 kb/s, 30 fps, 30 tbr, 90k tbn, 2k tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 163 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

Video stream duration: 30 seconds:

$ ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1 out2.m4a
duration=30.167333

Audio stream duration: 6+ hours:

$ ffprobe -v error -select_streams a:0 -show_entries stream=duration -of default=noprint_wrappers=1 out2.m4a
duration=22974.978231

The expected behavior is that with --extract-audio the output file will contain only the audio (having audio from the ad is fine) and that the stream audio will not be broken.

@remitamine
Copy link
Collaborator

@remitamine remitamine commented Nov 9, 2019

Post a specific URL where ads are served.

@nurupo
Copy link
Author

@nurupo nurupo commented Nov 9, 2019

There is no such thing as a specific URL where ads are served.

Twitch embeds ads into all live streams (not sure if it also does this for VODs?), so it can happen with any live stream URL, and it does so at random - sometimes there are ads, sometimes there are none. So you can't easily reproduce this. In fact, I have yet to reproduce it again, but then again I don't use youtube-dl that often.

@remitamine
Copy link
Collaborator

@remitamine remitamine commented Nov 9, 2019

if we can't reproduce the problem then how are we supposed to fix it.

@nurupo
Copy link
Author

@nurupo nurupo commented Nov 9, 2019

You can't easily reproduce it. The best way to reproduce it is probably keep restarting youtube-dl on a stream URL until Twitch decided to serve you ads.

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.