tl;dr: Update ffmpeg
± youtube-dl
.
Including the console output was helpful!
Your inputs are only detected as 5 seconds long
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://r1---sn-j5cax8pnpvo-x1xe6.googlevideo.com/videoplayback?keepalive=yes&source=yt_live_broadcast&pl=24&itag=136&mime=video%2Fmp4&expire=1521354001&c=WEB&sparams=aitags%2Ccmbypass%2Cei%2Cgcr%2Cgir%2Chang%2Cid%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clive%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cnoclen%2Cpl%2Crequiressl%2Csource%2Cexpire&aitags=133%2C134%2C135%2C136%2C160&signature=727E04BDE2851159A8A9327CDBAB503BBDC37267.2168845A24D2FFD5496AA2F5D2D6AACA59BB69D2&cmbypass=yes&ipbits=0&hang=1&beids=%5B9466592%5D&ms=lv&mt=1521331971&mv=u&live=1&key=yt6&ip=152.168.37.75&id=0R0T0mQmx7I.0&gir=yes&mm=32&mn=sn-j5cax8pnpvo-x1xe6&ei=sbCtWvOcLJTWxAS644e4Ag&noclen=1&gcr=ar&requiressl=yes&ratebypass=yes':
Metadata:
...
Duration: 00:00:05.00, start: 0.000000, bitrate: 2419 kb/s
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'https://r1---sn-j5cax8pnpvo-x1xe6.googlevideo.com/videoplayback?ip=152.168.37.75&mm=32&mn=sn-j5cax8pnpvo-x1xe6&expire=1521354004&pl=24&gir=yes&signature=16F13864FDF56FFDF2E08B248355CD1257D2E4FF.C7DBD2A865733005704660CD0EA82A90EFCFC03D&id=0R0T0mQmx7I.0&mt=1521331971&mv=u&ms=lv&hang=1&ipbits=0&itag=140&gcr=ar&requiressl=yes&source=yt_live_broadcast&keepalive=yes&ei=s7CtWsq0Ko7UxQT__pSgBA&noclen=1&sparams=cmbypass%2Ccompress%2Cei%2Cgcr%2Cgir%2Chang%2Cid%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clive%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cnoclen%2Cpl%2Crequiressl%2Csource%2Cexpire&cmbypass=yes&compress=yes&key=yt6&mime=audio%2Fmp4&c=WEB&live=1&ratebypass=yes':
Metadata:
...
Duration: 00:00:04.99, start: 0.000000, bitrate: 130 kb/s
Your ffmpeg
version is quite old
ffmpeg version 2.8.11-0ubuntu0.16.04.1 Copyright (c) 2000-2017 the FFmpeg developers
2.8 dates from around early 2016, from what I can tell. You are strongly suggested to update to the latest ffmpeg
; preferably the latest git HEAD
, but otherwise this PPA might be of use for Ubuntu.
Update your youtube-dl
version as well
I get quite a different output from you for the same URL:
$ youtube-dl --list-formats https://www.youtube.com/watch?v=0R0T0mQmx7I
[youtube] 0R0T0mQmx7I: Downloading webpage
[youtube] 0R0T0mQmx7I: Downloading video info webpage
[youtube] 0R0T0mQmx7I: Extracting video information
[youtube] 0R0T0mQmx7I: Downloading m3u8 information
[youtube] 0R0T0mQmx7I: Downloading MPD manifest
[info] Available formats for 0R0T0mQmx7I:
format code extension resolution note
91 mp4 256x144 HLS 197k , avc1.42c00b, 30.0fps, mp4a.40.5@ 48k
92 mp4 426x240 HLS 338k , avc1.4d4015, 30.0fps, mp4a.40.5@ 48k
93 mp4 640x360 HLS 829k , avc1.4d401e, 30.0fps, mp4a.40.2@128k
94 mp4 854x480 HLS 1380k , avc1.4d401f, 30.0fps, mp4a.40.2@128k
95 mp4 1280x720 HLS 2593k , avc1.4d401f, 30.0fps, mp4a.40.2@256k (best)
$ youtube-dl --version
2018.03.14
With a recent ffmpeg
and youtube-dl
version, you get the expected result:
$ ffmpeg -i $(youtube-dl -f 91 -g https://www.youtube.com/watch?v=0R0T0mQmx7I) \
-i $(youtube-dl -f 95 -g https://www.youtube.com/watch?v=0R0T0mQmx7I) \
-c:v copy -c:a aac -strict experimental -t 00:02:00 output.mp4
(...)
$ ffprobe output.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.83.100
Duration: 00:02:00.02, start: 0.000000, bitrate: 1784 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 1648kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
Metadata:
handler_name : SoundHandler
Example (video) output, resized to fit 2MB upload limit:
Full output from ffmpeg
invocation.
Best Answer
You can't do this directly. I have written a Python script which will download the whole file, process the description file and then split the downloaded file into it's component chapters.
Usage - if you save this into a file called "yt_chapters.py" then run
yt_chapters.py --split "https://www.youtube.com/watch?v=m5lp8S-YgrQ"
You can pass multiple download links and it will loop through the list.
The chapter record will be added to the original downloaded MP4.
Requirements: youtubedl, ffmpeg and MP4Box (GPAC). If you don't want to keep the original MP4, or if you don't care about it having the chapters, you can comment out that section. youtubedl and ffmpeg should be in your system path or else change the code below to include the full path to the executables.