Repository: youtube-dl
Issue: Downloading past first ad break on TBS/Adult Swim/other Turner sites
Labels: geo-restricted

## Please follow the guide below

- You will be asked some questions and requested to provide some information, please read them **carefully** and answer honestly
- Put an `x` into all the boxes [ ] relevant to your *issue* (like this: `[x]`)
- Use the *Preview* tab to see what your issue will actually look like

---

### Make sure you are using the *latest* version: run `youtube-dl --version` and ensure your version is *2018.04.03*. If it's not, read [this FAQ entry](https://github.com/rg3/youtube-dl/blob/master/README.md#how-do-i-update-youtube-dl) and update. Issues with outdated version will be rejected.
- [x] I've **verified** and **I assure** that I'm running youtube-dl **2018.04.03** *Although I'm currently testing with master*

### Before submitting an *issue* make sure you have:
- [x] At least skimmed through the [README](https://github.com/rg3/youtube-dl/blob/master/README.md), **most notably** the [FAQ](https://github.com/rg3/youtube-dl#faq) and [BUGS](https://github.com/rg3/youtube-dl#bugs) sections
- [x] [Searched](https://github.com/rg3/youtube-dl/search?type=Issues) the bugtracker for similar issues including closed ones
- [x] Checked that provided video/audio/playlist URLs (if any) are alive and playable in a browser

### What is the purpose of your *issue*?
- [x] Bug report (encountered problems with youtube-dl)
- [ ] Site support request (request for adding support for a new site)
- [ ] Feature request (request for a new functionality)
- [ ] Question
- [ ] Other

---

### The following sections concretize particular purposed issues, you can erase any section (the contents between triple ---) not applicable to your *issue*

---

### If the purpose of this *issue* is a *bug report*, *site support request* or you are not completely sure provide the full verbose output as follows:

Add the `-v` flag to **your command line** you run youtube-dl with (`youtube-dl -v <your command line>`), copy the **whole** output and insert it here. It should look similar to one below (replace it with **your** log inserted between triple ```):

```
% python -m youtube_dl http://www.tbs.com/shows/final-space/season-1/episode-2/chapter-two -v                            :(
[debug] System config: []
[debug] User config: [u'--hls-prefer-native', u'--ap-mso', u'Verizon_HBA', u'--ap-username', u'PRIVATE', u'--ap-password', u'PRIVATE']
[debug] Custom config: []
[debug] Command-line args: [u'http://www.tbs.com/shows/final-space/season-1/episode-2/chapter-two', u'-v']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2018.04.03
[debug] Git HEAD: e8dfecb38
[debug] Python version 2.7.10 (CPython) - Darwin-17.4.0-x86_64-i386-64bit
[debug] exe versions: avconv 12.3, avprobe 12.3, ffprobe 3.4.2, rtmpdump 2.4
[debug] Proxy map: {}
[TBS] chapter-two: Downloading webpage
[TBS] 7bfc76fcbee0c7fd97143b5d217bfdecd3296331: Downloading JSON metadata
[TBS] 7bfc76fcbee0c7fd97143b5d217bfdecd3296331: Downloading XML
[TBS] 7bfc76fcbee0c7fd97143b5d217bfdecd3296331: Downloading m3u8 information
[debug] Default format spec: bestvideo+bestaudio/best
[debug] Invoking downloader on u'https://tve.cdn.turner.com/tbs/c6603793053905abf8861e3a0a22d09e/layer7/layer7_bk.m3u8?hdntl=exp=1522789303~acl=%2ftbs%2fc6603793053905abf8861e3a0a22d09e%2f*~hmac=ef0710e3c8738f1dd478ed769556c0b8cccaec348bbc002da9370e1082eabc92'
[hlsnative] Downloading m3u8 manifest
[hlsnative] Total fragments: 230
[download] Destination: Chapter Two-7bfc76fcbee0c7fd97143b5d217bfdecd3296331.mp4
[download] 100% of 764.22MiB in 00:30
[debug] avconv command line: avprobe -show_streams 'file:Chapter Two-7bfc76fcbee0c7fd97143b5d217bfdecd3296331.mp4'
[ffmpeg] Fixing malformed AAC bitstream in "Chapter Two-7bfc76fcbee0c7fd97143b5d217bfdecd3296331.mp4"
[debug] ffmpeg command line: avconv -y -i 'file:Chapter Two-7bfc76fcbee0c7fd97143b5d217bfdecd3296331.mp4' -c copy -f mp4 '-bsf:a' aac_adtstoasc 'file:Chapter Two-7bfc76fcbee0c7fd97143b5d217bfdecd3296331.temp.mp4'
ERROR: av_interleaved_write_frame(): Invalid argument
Traceback (most recent call last):
  File "youtube_dl/YoutubeDL.py", line 2035, in post_process
    files_to_delete, info = pp.run(info)
  File "youtube_dl/postprocessor/ffmpeg.py", line 546, in run
    self.run_ffmpeg(filename, temp_filename, options)
  File "youtube_dl/postprocessor/ffmpeg.py", line 208, in run_ffmpeg
    self.run_ffmpeg_multiple_files([path], out_path, opts)
  File "youtube_dl/postprocessor/ffmpeg.py", line 204, in run_ffmpeg_multiple_files
    raise FFmpegPostProcessorError(msg)
FFmpegPostProcessorError: av_interleaved_write_frame(): Invalid argument

python -m youtube_dl  -v  12.20s user 2.78s system 42% cpu 35.628 total
```

---

### If the purpose of this *issue* is a *site support request* please provide all kinds of example URLs support for which should be included (replace following example URLs by **yours**):
- Single video: http://www.tbs.com/shows/final-space/season-1/episode-2/chapter-two

Note that **youtube-dl does not support sites dedicated to [copyright infringement](https://github.com/rg3/youtube-dl#can-you-add-support-for-this-anime-video-site-or-site-which-shows-current-movies-for-free)**. In order for site support request to be accepted all provided example URLs should not violate any copyrights.

---

### Description of your *issue*, suggested solution and other information

Attempting to download from TBS because their site is garbage and takes forever to get working.  It used to work fine.  Now I'm having trouble getting it to download past the first commercial.  If I use ffmpeg, I'm guaranteed to only get up to the first commercial.  Other issues suggest using `--hls-prefer-native`, so I switched to that.  I still end up with just the first segment (764.22MiB), but now I get `ERROR: av_interleaved_write_frame(): Invalid argument` on top of that.  The only solution I can find for that issue is to use `--prefer-ffmpeg` (#15010, #9631), which won't work since I'll only get the first segment (up until the ads).

Someone else seems to be encountering the same issue: https://github.com/rg3/youtube-dl/issues/15395#issuecomment-360715386  I get a very similar (enormous) log if I use ffmpeg.  For `seg-0` URLs, it works fine.  For `seg-1` and beyond:

```
[hls,applehttp @ 0x7fc62b002e00] HLS request for url 'https://tve.cdn.turner.com/tbs/c6603793053905abf8861e3a0a22d09e/layer7/seg-3_00039.ts', offset 0, playlist 0
[hls,applehttp @ 0x7fc62b002e00] Opening 'crypto+https://tve.cdn.turner.com/tbs/c6603793053905abf8861e3a0a22d09e/layer7/seg-3_00039.ts' for reading
[mp4 @ 0x7fc62b067c00] Non-monotonous DTS in output stream 0:0; previous: 37274980, current: 21069069; changing to 37274981. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7fc62b067c00] Non-monotonous DTS in output stream 0:0; previous: 37274981, current: 21072072; changing to 37274982. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7fc62b067c00] Non-monotonous DTS in output stream 0:0; previous: 37274982, current: 21075075; changing to 37274983. This may result in incorrect timestamps in the output file.
...
[mp4 @ 0x7fc62b067c00] Non-monotonous DTS in output stream 0:0; previous: 37275140, current: 21549550; changing to 37275141. This may result in incorrect timestamps in the output file.
```

The end of the ffmpeg log, in case it's of any use:

```
No more output streams to write to, finishing.
frame=41301 fps=253 q=-1.0 Lsize=  761354kB time=00:06:54.88 bitrate=15033.1kbits/s speed=2.55x
video:739361kB audio:21533kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.060402%
Input file #0 (https://tve.cdn.turner.com/tbs/c6603793053905abf8861e3a0a22d09e/layer7/layer7_bk.m3u8?hdntl=exp=1522790104~acl=%2ftbs%2fc6603793053905abf8861e3a0a22d09e%2f*~hmac=922d991652baac29a521d4eb6d30bb50ff5b4fa2355f6c148cd0242a273934a7):
  Input stream #0:0 (video): 41301 packets read (757105606 bytes);
  Input stream #0:1 (audio): 59350 packets read (22049785 bytes);
  Total: 100651 packets (779155391 bytes) demuxed
Output file #0 (file:Chapter Two-7bfc76fcbee0c7fd97143b5d217bfdecd3296331.mp4.part):
  Output stream #0:0 (video): 41301 packets muxed (757105606 bytes);
  Output stream #0:1 (audio): 59350 packets muxed (22049785 bytes);
  Total: 100651 packets (779155391 bytes) muxed
[ffmpeg] Downloaded 779626016 bytes
[download] 100% of 743.51MiB in 02:44
```

I tried `--include-ads`, as well; no luck.

The URL I provided as an example doesn't require MSO auth.  For URLs in the same series that require MSO auth, I'm encountering #16084 as well, which should be easier to fix.