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: set max resolution for common video codecs #4470

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ferrarimarco
Copy link

@ferrarimarco ferrarimarco commented Feb 19, 2025

Changes

Instead of relying on the max resolution for the H264 codec decoder as a
global setting when computing device capabilities, set the max supported
resolution for the most common video codecs by querying the decoder.

Video codecs that support this are: AVC (H264), HEVC (H265), AV1.

This change avoids unnecessary transcodings because, on some devices,
the AVC decoder might support a lower maximum resolution compared to
other decoders that the device supports. For example, if the AVC decoder
supports up to 2K resolution decoding, and the HEVC supports up to 4K
resolution decoding, Jellyfin would have transcoded a 4K HEVC media
stream.

I tested this on my setup, and, after this change, 4K HEVC media files all direct play instead of transcoding.

Issues

Fix #4466

@nielsvanvelzen
Copy link
Member

Thanks for digging deeper into the issue. I think it's worth adding the maximum resolution for multiple codecs, although the way you did it is not entirely correct.

A "device profile" is a big JSON document with rules about what the client is able to play and what it is not able to play. It should be device specific, not format specific. By which I mean: instead of detecting the codec type for a given media stream and building a device profile from that, we should always add the maximum resolution for all (common) codecs.

Right now we only have the codecProfile for h264 in this block:

	// Limit video resolution support for older devices
	codecProfile {
		type = CodecType.VIDEO

		conditions {
			ProfileConditionValue.WIDTH lowerThanOrEquals maxResolution.width
			ProfileConditionValue.HEIGHT lowerThanOrEquals maxResolution.height
		}
	}

To make it codec specific we can just add a single line (after the type line):

		codec = Codec.Video.H264

Then we can also add the same block for other codecs.

@ferrarimarco
Copy link
Author

Thanks for the tip.

I'll refactor the pr as you suggest.

@ferrarimarco ferrarimarco force-pushed the feat-dynamic-video-mime-type branch from 264058f to 87649e5 Compare February 20, 2025 07:24
Instead of relying on the max resolution for the H264 codec decoder as a
global setting when computing device capabilities, set the max supported
resolution for the most common video codecs by querying the decoder.

Video codecs that support this are: AVC (H264), HEVC (H265), AV1.

This change avoids unnecessary transcodings because, on some devices,
the AVC decoder might support a lower maximum resolution compared to
other decoders that the device supports. For example, if the AVC decoder
supports up to 2K resolution decoding, and the HEVC supports up to 4K
resolution decoding, Jellyfin would have transcoded a 4K HEVC media
stream.
@ferrarimarco ferrarimarco force-pushed the feat-dynamic-video-mime-type branch from 87649e5 to c47166a Compare February 20, 2025 07:25
@ferrarimarco
Copy link
Author

@nielsvanvelzen thanks for your review. I refactored the PR as you advised. Can you please take another look?

Tested and working.

Thanks

@ferrarimarco ferrarimarco changed the title feat: dynamically set the video stream mime type fix: dynamically set the video stream mime type Feb 20, 2025
@ferrarimarco ferrarimarco changed the title fix: dynamically set the video stream mime type fix: set max resolution for common video codecs Feb 20, 2025
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.

Jellyfin for Android TV uses H264/AVC decoder max resolution for every codec
2 participants