question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[AfreecaTV] Single videos should be merged into a single file, instead of being downloaded as a "playlist" of segments

See original GitHub issue

Checklist

  • I’m reporting a broken site support
  • I’ve verified that I’m running youtube-dl version 2021.03.03
  • 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 issues including closed ones

Verbose log

$ youtube-dl -v "https://vod.afreecatv.com/PLAYER/STATION/46171437"

[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['-v', 'https://vod.afreecatv.com/PLAYER/STATION/46171437']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, pref UTF-8
[debug] youtube-dl version 2021.03.03
[debug] Python version 3.9.2 (CPython) - macOS-10.14.6-x86_64-i386-64bit
[debug] exe versions: ffmpeg 4.3.2, ffprobe 4.3.2, rtmpdump 2.4
[debug] Proxy map: {}
[afreecatv] 46171437: Downloading webpage
[afreecatv] 46171437: Downloading video info XML
[afreecatv] 46171437: Downloading part 1 m3u8 information
[afreecatv] 46171437: Downloading part 2 m3u8 information
[afreecatv] 46171437: Downloading part 3 m3u8 information
[afreecatv] 46171437: Downloading part 4 m3u8 information
[afreecatv] 46171437: Downloading part 5 m3u8 information
[download] Downloading playlist: [생]ASL S8 Ro.16 Group A
[afreecatv] playlist [생]ASL S8 Ro.16 Group A: Collected 5 video ids (downloading 5 of them)
[download] Downloading video 1 of 5
[debug] Default format spec: bestvideo+bestaudio/best
[debug] Invoking downloader on 'http://vod-archive-global-cdn-z01.afreecatv.com/v1/mapped-vod/20190721/596/92E749C3_215850596_1.php/live/0/index-f1-v1-a1.m3u8'
[hlsnative] Downloading m3u8 manifest
[hlsnative] Total fragments: 1200
[download] Destination: [생]ASL S8 Ro.16 Group A (part 1)-20190721_92E749C3_215850596_1.mp4
[download] 100% of 3.49GiB in 04:15
[debug] ffmpeg command line: ffprobe -show_streams 'file:[생]ASL S8 Ro.16 Group A (part 1)-20190721_92E749C3_215850596_1.mp4'
[ffmpeg] Fixing malformed AAC bitstream in "[생]ASL S8 Ro.16 Group A (part 1)-20190721_92E749C3_215850596_1.mp4"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:[생]ASL S8 Ro.16 Group A (part 1)-20190721_92E749C3_215850596_1.mp4' -c copy -f mp4 -bsf:a aac_adtstoasc 'file:[생]ASL S8 Ro.16 Group A (part 1)-20190721_92E749C3_215850596_1.temp.mp4'
[download] Downloading video 2 of 5
[debug] Default format spec: bestvideo+bestaudio/best
[debug] Invoking downloader on 'http://vod-archive-global-cdn-z01.afreecatv.com/v1/mapped-vod/20190721/596/E4421B70_215850596_2.php/live/0/index-f1-v1-a1.m3u8'
[hlsnative] Downloading m3u8 manifest
[hlsnative] Total fragments: 1200
[download] Destination: [생]ASL S8 Ro.16 Group A (part 2)-20190721_E4421B70_215850596_2.mp4
[download] 100% of 3.51GiB in 04:34
[debug] ffmpeg command line: ffprobe -show_streams 'file:[생]ASL S8 Ro.16 Group A (part 2)-20190721_E4421B70_215850596_2.mp4'
[ffmpeg] Fixing malformed AAC bitstream in "[생]ASL S8 Ro.16 Group A (part 2)-20190721_E4421B70_215850596_2.mp4"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:[생]ASL S8 Ro.16 Group A (part 2)-20190721_E4421B70_215850596_2.mp4' -c copy -f mp4 -bsf:a aac_adtstoasc 'file:[생]ASL S8 Ro.16 Group A (part 2)-20190721_E4421B70_215850596_2.temp.mp4'
[download] Downloading video 3 of 5
[debug] Default format spec: bestvideo+bestaudio/best
[debug] Invoking downloader on 'http://vod-archive-global-cdn-z01.afreecatv.com/v1/mapped-vod/20190721/596/E23747A5_215850596_3.php/live/0/index-f1-v1-a1.m3u8'
[hlsnative] Downloading m3u8 manifest
[hlsnative] Total fragments: 1200
[download] Destination: [생]ASL S8 Ro.16 Group A (part 3)-20190721_E23747A5_215850596_3.mp4
[download] 100% of 3.50GiB in 04:35
[debug] ffmpeg command line: ffprobe -show_streams 'file:[생]ASL S8 Ro.16 Group A (part 3)-20190721_E23747A5_215850596_3.mp4'
[ffmpeg] Fixing malformed AAC bitstream in "[생]ASL S8 Ro.16 Group A (part 3)-20190721_E23747A5_215850596_3.mp4"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:[생]ASL S8 Ro.16 Group A (part 3)-20190721_E23747A5_215850596_3.mp4' -c copy -f mp4 -bsf:a aac_adtstoasc 'file:[생]ASL S8 Ro.16 Group A (part 3)-20190721_E23747A5_215850596_3.temp.mp4'
[download] Downloading video 4 of 5
[debug] Default format spec: bestvideo+bestaudio/best
[debug] Invoking downloader on 'http://vod-archive-global-cdn-z01.afreecatv.com/v1/mapped-vod/20190721/596/744219C0_215850596_4.php/live/0/index-f1-v1-a1.m3u8'
[hlsnative] Downloading m3u8 manifest
[hlsnative] Total fragments: 1200
[download] Destination: [생]ASL S8 Ro.16 Group A (part 4)-20190721_744219C0_215850596_4.mp4
[download] 100% of 3.51GiB in 06:25
[debug] ffmpeg command line: ffprobe -show_streams 'file:[생]ASL S8 Ro.16 Group A (part 4)-20190721_744219C0_215850596_4.mp4'
[ffmpeg] Fixing malformed AAC bitstream in "[생]ASL S8 Ro.16 Group A (part 4)-20190721_744219C0_215850596_4.mp4"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:[생]ASL S8 Ro.16 Group A (part 4)-20190721_744219C0_215850596_4.mp4' -c copy -f mp4 -bsf:a aac_adtstoasc 'file:[생]ASL S8 Ro.16 Group A (part 4)-20190721_744219C0_215850596_4.temp.mp4'
[download] Downloading video 5 of 5
[debug] Default format spec: bestvideo+bestaudio/best
[debug] Invoking downloader on 'http://vod-archive-global-cdn-z01.afreecatv.com/v1/mapped-vod/20190721/596/92374B95_215850596_5.php/live/0/index-f1-v1-a1.m3u8'
[hlsnative] Downloading m3u8 manifest
[hlsnative] Total fragments: 165
[download] Destination: [생]ASL S8 Ro.16 Group A (part 5)-20190721_92374B95_215850596_5.mp4
[download] 100% of 490.30MiB in 00:36
[debug] ffmpeg command line: ffprobe -show_streams 'file:[생]ASL S8 Ro.16 Group A (part 5)-20190721_92374B95_215850596_5.mp4'
[ffmpeg] Fixing malformed AAC bitstream in "[생]ASL S8 Ro.16 Group A (part 5)-20190721_92374B95_215850596_5.mp4"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:[생]ASL S8 Ro.16 Group A (part 5)-20190721_92374B95_215850596_5.mp4' -c copy -f mp4 -bsf:a aac_adtstoasc 'file:[생]ASL S8 Ro.16 Group A (part 5)-20190721_92374B95_215850596_5.temp.mp4'
[download] Finished downloading playlist: [생]ASL S8 Ro.16 Group A

Resulting files:

./[생]ASL S8 Ro.16 Group A (part 1)-20190721_92E749C3_215850596_1.mp4
./[생]ASL S8 Ro.16 Group A (part 2)-20190721_E4421B70_215850596_2.mp4
./[생]ASL S8 Ro.16 Group A (part 3)-20190721_E23747A5_215850596_3.mp4
./[생]ASL S8 Ro.16 Group A (part 4)-20190721_744219C0_215850596_4.mp4
./[생]ASL S8 Ro.16 Group A (part 5)-20190721_92374B95_215850596_5.mp4

Description

When downloading videos from AfreecaTV, they end up as multiple hour-long segments instead of being merged into a single video as they should. The handler seems to believe a video is a “playlist”, and then proceeds to download the segments as separate files, without merging them in the end. The way they’re implemented on Afreeca is each video is divided into segments of an hour long, and each one of those segments is divided up into many small pieces. Youtube-dl correctly merges the smaller pieces, but not the larger segments.

For example, downloading this 4:08:14 long video results in five separate files, with the first four being 1 hour long and the last one being 8 minutes long.

The expected result is that the result of the operation is a single >4 hour long video.

Note: this is related to my earlier question: #28396.

Thanks for your attention.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
wlritchicommented, Aug 8, 2022

I recall that a release in late 2021 or early 2022 added a --concat-playlist option to stitch together video files like this. I don’t personally want that for my use case, so I remember turning it off when I noticed - but that implies it’s on by default and works for Afreeca.

Does this option work for you?

1reaction
msikmacommented, Apr 1, 2022

@afterdelight there’s no one-size-fits-all command for it, but you can do it in two steps:

First of all, you need to add playlist_index to your output format when running yt-dlp. For example:

yt-dlp (other options..) --output "./my_filename_%(playlist_index)s.%(ext)s" --merge-output-format "mp4" (url)

This will ensure that all playlist entries get _1, _2, _3, etc. numbers in the filename, and I’m also making sure the extension is always .mp4 so I can easily find the files.

Now you need to merge those using ffmpeg’s concat filter.

find . -name "my_filename_*.mp4" -print0 | sort -z | xargs -r0 printf "file '%s'" > ./"file_merge.txt"
ffmpeg -f concat -safe 0 -i ./"file_merge.txt" -c copy ./"my_filename".mp4 2>&1 | tee ./"my_filename".merge.log
find . -name "file_merge.txt" -delete -depth 1
find . -name "my_filename_*.mp4" -delete -depth 1

The first command creates a merge file with entries for each segment, and then it uses that merge file to generate a single master file.

You’ll want to replace the “my_filename” portion with whatever your title ends up being. In my case I could easily script this because I always knew the output title in advance. If you don’t, you could probably also just select all files ending in _[number].mp4 as long as you always start downloading inside a clean directory.

Read more comments on GitHub >

github_iconTop Results From Across the Web

yt-dlp 2021.9.1
Command-line program to download videos from YouTube.com and many other other ... streams to be merged into a single file --no-audio-multistreams Only one...
Read more >
How to Play Certain Sections and Part of Video and Audio ...
It'll allow you to play only certain parts of a video. This special trick allows you to specify a video file as well...
Read more >
yt-dlp/Changelog.md at master
Channel URLs download all uploads of the channel as multiple playlists, ... Merge youtube-dl: Upto commit/ed5c44e; Add yt-dlp version to infojson ...
Read more >
Command-Line Interface - Streamlink 5.1.2 documentation
Append log output to FILE instead of writing to stdout/stderr. User prompts and download progress won't be written to FILE . A value...
Read more >
[4 Solutions] How to Download HTTP Live Streaming (HLS) ...
This freeware can parse HLS M3U8 master file and merge all fragmented TS videos into a single full-length MP4 file. Download HLS video...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found