Repository: youtube-dl
Issue: [Request] Output format TS (MPEG Transport Stream)
Labels: request

- [x] I've **verified** and **I assure** that I'm running youtube-dl **2016.12.20**
- [x] I've at least skimmed through [README](https://github.com/rg3/youtube-dl/blob/master/README.md) and **most notably** [FAQ](https://github.com/rg3/youtube-dl#faq) and [BUGS](https://github.com/rg3/youtube-dl#bugs) sections
- [x] I've [searched](https://github.com/rg3/youtube-dl/search?type=Issues) the bugtracker for similar issues including closed ones

### The purpose of my *issue* is:
- [x] Feature request (request for a new functionality)
---
I've tried...
```
youtube-dl.exe -vf 18 --external-downloader ffmpeg --external-downloader-args "-bsf:v h264_mp
4toannexb" -o "%(title)s.ts" https://www.youtube.com/watch?v=QgQ-D6bvc1A
[debug] System config: []
[debug] User config: []
[debug] Command-line args: ['-vf', '18', '--external-downloader', 'ffmpeg', '--external-downl
oader-args', '-bsf:v h264_mp4toannexb', '-o', '%(title)s.ts', 'https://www.youtube.com/watch?
v=QgQ-D6bvc1A']
[debug] Encodings: locale cp1252, fs mbcs, out cp437, pref cp1252
[debug] youtube-dl version 2016.12.20
[debug] Python version 3.4.4 - Windows-XP-5.1.2600-SP3
[debug] exe versions: ffmpeg N-82759-g1f5630a-Sherpya
[debug] Proxy map: {}
[youtube] QgQ-D6bvc1A: Downloading webpage
[youtube] QgQ-D6bvc1A: Downloading video info webpage
[youtube] QgQ-D6bvc1A: Extracting video information
[youtube] QgQ-D6bvc1A: Downloading MPD manifest
[debug] Invoking downloader on 'https://r4---sn-mn4vg5aa-5hns.googlevideo.com/videoplayback?i
p=2001%3A980%3A2408%3A1%3Ad66%3Aade4%3A3e76%3Adcf5&pl=35&mt=1482271374&mv=m&ei=36pZWJOJOIXN1g
LdpbGYBg&ms=au&mm=31&mn=sn-mn4vg5aa-5hns&id=o-ALn9mukS3ADDrcWw4-QzPhHBOBg4H6I7S96YrC-PNfMG&up
n=YvoAHAvLx0s&expire=1482293056&itag=18&ratebypass=yes&requiressl=yes&source=youtube&dur=89.6
98&lmt=1482229941216632&gir=yes&key=yt6&signature=CCAD2A6AE4DCA692C41A879FBEF270C33481A0AD.A9
D7304204915767196256A4948F12C8DD8F613D&mime=video%2Fmp4&sparams=clen%2Cdur%2Cei%2Cgir%2Cid%2C
initcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequire
ssl%2Csource%2Cupn%2Cexpire&clen=5668603&ipbits=0&beids=%5B9452307%5D&initcwndbps=2331250'
[download] Destination: Amsterdam - Gewelddadige beroving toerist.ts
[debug] ffmpeg command line: ffmpeg -y -bsf:v h264_mp4toannexb -headers 'Accept-Language: en-
us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
' -i 'https://r4---sn-mn4vg5aa-5hns.googlevideo.com/......' -c copy -f mp4 'file:Amsterdam - 
Gewelddadige beroving toerist.ts.part'

ffmpeg version N-82759-g1f5630a-Sherpya Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 6.2.1 (GCC) 20161118
Option bsf:v (A comma-separated list of bitstream filters) cannot be applied to input file ht
tps://r4---sn-mn4vg5aa-5hns.googlevideo.com/......
-- you are trying to apply an input option to an output file or vice versa. Move this option 
before the file it belongs to.
Error parsing options for input file https://r4---sn-mn4vg5aa-5hns.googlevideo.com/.......
Error opening input files: Invalid argument


ERROR: ffmpeg exited with code 1
  File "__main__.py", line 19, in <module>
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmph8curlv3\build\youtube_d
l\__init__.py", line 444, in main
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmph8curlv3\build\youtube_d
l\__init__.py", line 434, in _real_main
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmph8curlv3\build\youtube_d
l\YoutubeDL.py", line 1791, in download
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmph8curlv3\build\youtube_d
l\YoutubeDL.py", line 705, in extract_info
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmph8curlv3\build\youtube_d
l\YoutubeDL.py", line 751, in process_ie_result
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmph8curlv3\build\youtube_d
l\YoutubeDL.py", line 1435, in process_video_result
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmph8curlv3\build\youtube_d
l\YoutubeDL.py", line 1699, in process_info
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmph8curlv3\build\youtube_d
l\YoutubeDL.py", line 1641, in dl
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmph8curlv3\build\youtube_d
l\downloader\common.py", line 353, in download
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmph8curlv3\build\youtube_d
l\downloader\external.py", line 43, in real_download
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmph8curlv3\build\youtube_d
l\downloader\common.py", line 162, in report_error
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmph8curlv3\build\youtube_d
l\YoutubeDL.py", line 568, in report_error
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmph8curlv3\build\youtube_d
l\YoutubeDL.py", line 530, in trouble
```
but this errors out because `-bsf:v h264_mp4toannexb` is put in front of the input file, when in fact it should be inserted after `' -i 'https://r4---sn-mn4vg5aa-5hns.googlevideo.com/......' -c copy`.
To be clear: to convert MP4 to TS the bitstream filter `-bsf:v h264_mp4toannexb` is needed!

I've also tried without `--external-downloader-args "-bsf:v h264_mp4toannexb"`. Youtube-dl then puts out a TS-file, but only because I forced it to with `-o "%(title)s.ts"`. In the end the video is still a MP4-file, because of the `-f mp4` in the ffmpeg command line, which seems to be hardcoded in the source.

`--recode-video ts` certainly wouldn't be an option, because this doesn't involve a recode/conversion, but just a special remux.
`--merge-output-format ts` could be an option, but there's no merge required for `-f 18` in this case, because it's already a MP4-file.
So I was actually looking for something like `--output-format ts` which then inserts `-f mpegts` instead of `-f mp4`. FFMpeg then automatically inserts `-bsf:v h264_mp4toannexb`.
Better yet: FFMpeg is so smart that as long as you make sure the output file ends with the ts-extension, then `' -i 'https://r4---sn-mn4vg5aa-5hns.googlevideo.com/......' -c copy 'file:Amsterdam - Gewelddadige beroving toerist.ts'` is enough. In the background FFMpeg automatically inserts `-bsf:v h264_mp4toannexb -f mpegts`. (I'm not sure whether `--no-part` should be enabled for this or not)

Why the request for TS as output format in the first place?
Because officially the only way to concatenate H.264 video's is when they're raw (*.h264), or in a MPEG Transport Stream container.