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

Fix VOD download trimming and quality selection #936

Merged
merged 4 commits into from
Jan 6, 2024
Merged

Fix VOD download trimming and quality selection #936

merged 4 commits into from
Jan 6, 2024

Conversation

vaindil
Copy link
Contributor

@vaindil vaindil commented Jan 6, 2024

Fixes #935, see that for a more detailed discussion.

This also fixes a separate bug with stream quality selection when downloading VODs. Twitch's Usher endpoint to list stream qualities sometimes returns a 1080p60 stream quality with full framerate info, but sometimes that stream is returned as Source with no framerate info. Because there was no exact match for the stream name between the quality dropdown and the response when downloading, the logic would fall through to this:

_ => streams.MaxBy(x => x.StreamInfo.Resolution.Width * x.StreamInfo.Resolution.Height * x.StreamInfo.Framerate)

However, in this case the framerate is 0 for the Source stream, which breaks this calculation. The other streams in the response do have framerate info when this happens, so the second-best quality would be chosen instead (720p60 in my case). This adds a manual override for these Source streams so they're always selected as the best quality.

Copy link
Collaborator

@ScrubN ScrubN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking with the creation of BestQualityStream

TwitchDownloaderCore/Extensions/M3U8Extensions.cs Outdated Show resolved Hide resolved
@vaindil
Copy link
Contributor Author

vaindil commented Jan 6, 2024

Here's a bit more detail on the second fix.

The usual response from Twitch for the playlist with video qualities in it looks like this:

image

The best-quality stream is named 1080p60, and there's framerate info at the tail end there. When this response is returned, everything is great.

Twitch sometimes returns this response, however:

image

Note that the name is different, and there's no framerate info.

@ScrubN
Copy link
Collaborator

ScrubN commented Jan 6, 2024

Note that the name is different, and there's no framerate info.

Yeah, I ran into this myself at some point when writing M3U8Extensions. If possible, the framerate is assumed via the name when this happens:

} while (true);
// Sometimes Twitch's M3U8 response lacks a Framerate value, among other things. We can just guess the framerate using the Video value.
if (streamInfo.Framerate == 0 && Regex.IsMatch(streamInfo.Video, @"p\d+$", RegexOptions.RightToLeft))
{
var index = streamInfo.Video.LastIndexOf('p');
streamInfo.Framerate = int.Parse(streamInfo.Video.AsSpan(index + 1));
}
return streamInfo;

Edit: I realize now that this code has the possibility to throw if twitch's M3U8 response changes in the future, but even if that was fixed I think M3U8Extensions.GetStreamofQuality would also throw...

@ScrubN
Copy link
Collaborator

ScrubN commented Jan 6, 2024

Awesome, thank you for the fix!

@ScrubN ScrubN merged commit d10fdeb into lay295:master Jan 6, 2024
@vaindil vaindil deleted the bug-fixes branch January 6, 2024 23:47
@Nutri626
Copy link

Nutri626 commented Jan 7, 2024

is update coming soon tho, its really hard to use it properly rn

@ScrubN
Copy link
Collaborator

ScrubN commented Jan 7, 2024

I want to release an update tomorrow at the very latest (north america), but I want to give @lay295 time to decide if he wants to implement the temporary solution for #934 first.

In the meantime, you can download the workflow build from here: https://github.com/lay295/TwitchDownloader/actions/runs/7434637911

Alternatively, if you only crop on 10-second intervals, you will not experience the bad crop issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VOD downloads "Crop Video" function is broken
3 participants