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

ffmpeg/avconv settings to improve encoding of Twitch streams #9082

Closed
alphapapa opened this issue Apr 4, 2016 · 2 comments
Closed

ffmpeg/avconv settings to improve encoding of Twitch streams #9082

alphapapa opened this issue Apr 4, 2016 · 2 comments

Comments

@alphapapa
Copy link
Contributor

@alphapapa alphapapa commented Apr 4, 2016

I recently discovered that youtube-dl can process Twitch past-broadcast streams with ffmpeg/avconv, which is great. However, with the encoding settings it uses, the resulting file does not allow players to seek or recognize the duration until after the video has been completely downloaded, because the MP4 file does not have fragmentation enabled.

But by using some additional encoding settings, the file can be played immediately, while it is being downloaded and muxed, and players can seek and recognize the increasing duration properly. For example, it works perfectly in VLC 2.2.1.

Here's an example shell command:

avconv -i "$playlist_URL"  -vcodec copy -vf setpts=expr=PTS-STARTPTS -frag_size 1048576 -acodec copy -af asetpts=expr=PTS-STARTPTS "$output_filename.mp4"

This sets the video and audio streams to be copied directly without reencoding, uses the setpts video filter and the asetpts audio filter to synchronize the timestamps, and uses -frag_size 1048576 to set a 1 MB fragment size in the MP4 container, which writes metadata for every 1 MB fragment, rather than writing it at the end of the file (which won't happen until the download is complete).

I just pulled from master and looked through twitch.py and ffmpeg.py but I couldn't find a way to set encoding options just for Twitch. It might be fine to use these for all encoding, because it would probably benefit much more than just Twitch downloads, but I'll leave that decision to you. :)

Thanks for your work on youtube-dl!

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Apr 4, 2016

What you request is achievable with --hls-use-mpegts.

@dstftw dstftw closed this Apr 4, 2016
@alphapapa
Copy link
Contributor Author

@alphapapa alphapapa commented Apr 5, 2016

Thanks for pointing that out, I wasn't aware of that.

That does seem to work well, however the options I mentioned here do have an advantage: VLC can recognize the increasing duration of the file as it plays it, and displays it in the progress bar. Without them, it always displays the duration as 00:00.

So it might be helpful to add these encoding settings to the --hls-use-mpegts option.

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.