Avoid unnecessary transcoding by only transcoding incompatible streams #6450
Description
Describe the bug
This is a meta-bug that causes #6149, #6449 (TODO: look for other bugs relating to this).
If only some of the streams (or the container itself) is unsupported, only transcode the unsupported streams and just copy/mux the other streams.
System (please complete the following information):
- OS: All
- Virtualization: Any
- Clients: All
- Browser: All
- Jellyfin Version: 10.7.6
- Playback: Transcode
- Hardware Acceleration: All
- Installed Plugins: All
- Reverse Proxy: All
- Base URL: All
- Networking: All
- Storage: All
To Reproduce
- Attempt to play a video to a client that supports the video codec but not the audio or container. For example, play a (MKV, VP9, AAC) video on Firefox.
- Notice that transcoding occurs unnecessarily for the video stream as well as the audio stream.
Expected behavior
Only the unsupported the streams should be transcoded and supported streams should be passed through.
Additional context
This exposes a deeper issue with some of the transcoding logic that needs to be fixed.
Refer to MediaBrowser.Model.Dlna.Streambuilder.BuildVideoItem() for a starting reference point for this bug.
For example, something similar to this logic should be used to pick a target transcode output format:
// Can't direct play, find the transcoding profile
TranscodingProfile transcodingProfile = null;
int bestMaxAudioChannels = 0;
foreach (var i in options.Profile.TranscodingProfiles)
{
if (i.Type == playlistItem.MediaType && i.Context == options.Context)
{
int curMaxAudioChannels = 0;
int.TryParse(i.MaxAudioChannels, out curMaxAudioChannels);
if (transcodingProfile == null)
{
transcodingProfile = i;
}
else if (i.VideoCodec == NormalizeSourceCodecToTranscodeCodec(item.VideoStream.Codec) && transcodingProfile.VideoCodec != NormalizeSourceCodecToTranscodeCodec(item.VideoStream.Codec))
{
// Container supports original codec, so pick this profile instead.
transcodingProfile = i;
}
else if (curMaxAudioChannels > bestMaxAudioChannels)
{
// Container supports more audio channels output.
transcodingProfile = i;
}
// Probably add logic about containers that support embedded subtitles.
}
}Then, there should be some indication, perhaps in MediaBrowser.Model.Dlna.StreamInfo, to indicate whether to pass through the audio or video streams to the output container, and the transcoding logic should selectively transcode.
Activity