2026-08-10 15:29:12 +02:00
|
|
|
import '../i18n/strings.g.dart';
|
|
|
|
|
|
2025-12-14 21:03:11 +01:00
|
|
|
/// Utility class for codec-related operations.
|
|
|
|
|
///
|
|
|
|
|
/// Provides centralized codec name mappings, file extension lookups,
|
|
|
|
|
/// and display name formatting.
|
|
|
|
|
class CodecUtils {
|
|
|
|
|
CodecUtils._();
|
|
|
|
|
|
|
|
|
|
static String getSubtitleExtension(String? codec) {
|
|
|
|
|
if (codec == null) return 'srt';
|
|
|
|
|
|
|
|
|
|
switch (codec.toLowerCase()) {
|
|
|
|
|
case 'subrip':
|
|
|
|
|
case 'srt':
|
|
|
|
|
return 'srt';
|
|
|
|
|
case 'ass':
|
|
|
|
|
case 'ssa':
|
2026-02-27 16:51:34 +01:00
|
|
|
return 'ass';
|
2025-12-14 21:03:11 +01:00
|
|
|
case 'webvtt':
|
|
|
|
|
case 'vtt':
|
|
|
|
|
return 'vtt';
|
|
|
|
|
case 'mov_text':
|
|
|
|
|
return 'srt';
|
|
|
|
|
case 'pgs':
|
2026-06-25 17:50:38 +09:00
|
|
|
case 'pgssub':
|
2025-12-14 21:03:11 +01:00
|
|
|
case 'hdmv_pgs_subtitle':
|
|
|
|
|
return 'sup';
|
|
|
|
|
case 'dvd_subtitle':
|
|
|
|
|
case 'dvdsub':
|
2026-06-25 17:50:38 +09:00
|
|
|
case 'vobsub':
|
|
|
|
|
case 'dvb_sub':
|
|
|
|
|
case 'dvb_subtitle':
|
2025-12-14 21:03:11 +01:00
|
|
|
return 'sub';
|
|
|
|
|
default:
|
|
|
|
|
return 'srt';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 17:21:31 +02:00
|
|
|
static bool isTextSubtitleCodec(String? codec) {
|
|
|
|
|
if (codec == null) return false;
|
|
|
|
|
return switch (codec.toLowerCase()) {
|
|
|
|
|
'srt' || 'subrip' || 'ass' || 'ssa' || 'webvtt' || 'vtt' || 'mov_text' => true,
|
|
|
|
|
_ => false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-14 17:05:13 +02:00
|
|
|
/// Image-based (bitmap) subtitle codecs. Plex burns these into the video
|
|
|
|
|
/// when the selected output transport cannot carry a bitmap subtitle
|
|
|
|
|
/// rendition.
|
2026-06-25 17:50:38 +09:00
|
|
|
static bool isImageSubtitleCodec(String? codec) {
|
|
|
|
|
if (codec == null) return false;
|
|
|
|
|
return switch (codec.toLowerCase()) {
|
|
|
|
|
'pgs' ||
|
|
|
|
|
'pgssub' ||
|
|
|
|
|
'hdmv_pgs_subtitle' ||
|
|
|
|
|
'dvd_subtitle' ||
|
|
|
|
|
'dvdsub' ||
|
|
|
|
|
'vobsub' ||
|
|
|
|
|
'dvb_sub' ||
|
2026-08-09 07:30:47 +02:00
|
|
|
// Jellyfin's own spelling, which is what the transcode profile asks it to burn.
|
|
|
|
|
'dvbsub' ||
|
2026-06-25 17:50:38 +09:00
|
|
|
'dvb_subtitle' => true,
|
|
|
|
|
_ => false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-14 17:05:13 +02:00
|
|
|
/// Subtitle codecs Plex can deliver in a transcode. Text codecs can become
|
|
|
|
|
/// segmented HLS WebVTT; image codecs can be burned into the video.
|
|
|
|
|
static bool isTranscodableSubtitleCodec(String? codec) {
|
2026-06-25 17:50:38 +09:00
|
|
|
return isTextSubtitleCodec(codec) || isImageSubtitleCodec(codec);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-14 21:03:11 +01:00
|
|
|
/// Formats a subtitle codec name to a user-friendly display format.
|
|
|
|
|
///
|
|
|
|
|
/// Converts internal codec names like 'SUBRIP' to friendly names like 'SRT'.
|
|
|
|
|
static String formatSubtitleCodec(String codec) {
|
|
|
|
|
final upper = codec.toUpperCase();
|
|
|
|
|
return switch (upper) {
|
|
|
|
|
'SUBRIP' => 'SRT',
|
|
|
|
|
'DVD_SUBTITLE' => 'DVD',
|
|
|
|
|
'WEBVTT' => 'VTT',
|
|
|
|
|
'HDMV_PGS_SUBTITLE' => 'PGS',
|
|
|
|
|
'MOV_TEXT' => 'MOV',
|
|
|
|
|
_ => upper,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Formats a video codec name to a user-friendly display format.
|
|
|
|
|
///
|
|
|
|
|
/// Converts internal codec names like 'hevc' to friendly names like 'HEVC'.
|
|
|
|
|
static String formatVideoCodec(String codec) {
|
|
|
|
|
final lower = codec.toLowerCase();
|
|
|
|
|
return switch (lower) {
|
|
|
|
|
'h264' || 'avc1' || 'avc' => 'H.264',
|
|
|
|
|
'hevc' || 'h265' || 'hev1' => 'HEVC',
|
|
|
|
|
'av1' => 'AV1',
|
|
|
|
|
'vp8' => 'VP8',
|
|
|
|
|
'vp9' => 'VP9',
|
|
|
|
|
'mpeg2video' || 'mpeg2' => 'MPEG-2',
|
|
|
|
|
'mpeg4' => 'MPEG-4',
|
|
|
|
|
'vc1' => 'VC-1',
|
|
|
|
|
_ => codec.toUpperCase(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-12 03:25:34 +02:00
|
|
|
/// Formats an audio channel count as a friendly layout name (2 → 'Stereo',
|
|
|
|
|
/// 6 → '5.1'). Returns null when [channels] is null or not positive.
|
|
|
|
|
static String? formatAudioChannels(int? channels) {
|
|
|
|
|
if (channels == null || channels <= 0) return null;
|
|
|
|
|
return switch (channels) {
|
2026-08-10 15:29:12 +02:00
|
|
|
1 => t.fileInfo.channelsMono,
|
|
|
|
|
2 => t.videoSettings.audioOutputStereo,
|
2026-06-12 03:25:34 +02:00
|
|
|
3 => '3.0',
|
|
|
|
|
4 => '4.0',
|
|
|
|
|
5 => '4.1',
|
|
|
|
|
6 => '5.1',
|
|
|
|
|
7 => '6.1',
|
|
|
|
|
8 => '7.1',
|
|
|
|
|
_ => '${channels}ch',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-14 21:03:11 +01:00
|
|
|
/// Formats an audio codec name to a user-friendly display format.
|
2026-08-13 21:23:08 +02:00
|
|
|
///
|
|
|
|
|
/// Accepts both ffmpeg-style names as reported by mpv and the media
|
|
|
|
|
/// servers ('aac', 'eac3') and RFC 6381 codec IDs as reported by
|
|
|
|
|
/// ExoPlayer's `Format.codecs` ('mp4a.40.2', 'ec-3', 'dtsc').
|
2025-12-14 21:03:11 +01:00
|
|
|
static String formatAudioCodec(String codec) {
|
|
|
|
|
final lower = codec.toLowerCase();
|
2026-08-13 21:23:08 +02:00
|
|
|
// MP4 object types 0x69/0x6B under the mp4a prefix are MPEG layer
|
|
|
|
|
// audio; every other mp4a object type in the wild is an AAC variant.
|
|
|
|
|
if (lower == 'mp4a.69' || lower == 'mp4a.6b') return 'MP3';
|
|
|
|
|
if (lower == 'mp4a' || lower.startsWith('mp4a.')) return 'AAC';
|
|
|
|
|
if (lower == 'ac-4' || lower.startsWith('ac-4.')) return 'AC4';
|
2025-12-14 21:03:11 +01:00
|
|
|
return switch (lower) {
|
|
|
|
|
'aac' => 'AAC',
|
2026-08-13 21:23:08 +02:00
|
|
|
'ac3' || 'ac-3' => 'AC3',
|
|
|
|
|
'eac3' || 'ec3' || 'ec-3' => 'E-AC3',
|
|
|
|
|
'truehd' || 'mlpa' => 'TrueHD',
|
|
|
|
|
'dts' || 'dca' || 'dtsc' || 'dtse' => 'DTS',
|
|
|
|
|
'dtshd' || 'dts-hd' || 'dtsh' || 'dtsl' => 'DTS-HD',
|
|
|
|
|
'dtsx' => 'DTS:X',
|
2025-12-14 21:03:11 +01:00
|
|
|
'flac' => 'FLAC',
|
|
|
|
|
'mp3' || 'mp3float' => 'MP3',
|
|
|
|
|
'opus' => 'Opus',
|
|
|
|
|
'vorbis' => 'Vorbis',
|
|
|
|
|
'pcm_s16le' || 'pcm_s24le' || 'pcm' => 'PCM',
|
|
|
|
|
_ => codec.toUpperCase(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|