Adapt for .ssa subtitles with attached fonts

dev
Javanaut 4 days ago
parent 126ba4487c
commit 686239491b

@ -426,7 +426,7 @@ def convert(ctx,
or if the filename has not changed."""
startTime = time.perf_counter()
context = ctx.obj
context['video_encoder'] = VideoEncoder.fromLabel(video_encoder)
@ -633,6 +633,16 @@ def convert(ctx,
sourceMediaDescriptor = mediaFileProperties.getMediaDescriptor()
if ([smd for smd in sourceMediaDescriptor.getSubtitleTracks()
if smd.getCodec() == TrackCodec.ASS]
and [amd for amd in sourceMediaDescriptor.getAttachmentTracks()
if amd.getCodec() == TrackCodec.TTF]):
targetFormat = ''
targetExtension = 'mkv'
#HINT: This is None if the filename did not match anything in database
currentPattern = mediaFileProperties.getPattern() if context['use_pattern'] else None

@ -320,6 +320,13 @@ class MediaDescriptor:
if s.getType() == TrackType.SUBTITLE
]
def getAttachmentTracks(self) -> List[TrackDescriptor]:
return [
s
for s in self.__trackDescriptors
if s.getType() == TrackType.ATTACHMENT
]
def getImportFileTokens(self, use_sub_index: bool = True):
"""Generate ffmpeg import options for external stream files"""
@ -366,12 +373,14 @@ class MediaDescriptor:
stdsi = sortedTrackDescriptors[td.getSourceIndex()].getSubIndex()
trackType = td.getType()
trackCodec = td.getCodec()
if (trackType == TrackType.VIDEO or not only_video):
importedFilePath = td.getExternalSourceFilePath()
if use_sub_index:
if use_sub_index and not (trackType == TrackType.ATTACHMENT and trackCodec == TrackCodec.TTF):
if importedFilePath:
@ -383,16 +392,17 @@ class MediaDescriptor:
else:
if not td.getCodec() in [TrackCodec.PGS, TrackCodec.VOBSUB]:
if not trackCodec in [TrackCodec.PGS, TrackCodec.VOBSUB]:
inputMappingTokens += [
"-map",
f"0:{trackType.indicator()}:{stdsi}",
]
else:
if not td.getCodec() in [TrackCodec.PGS, TrackCodec.VOBSUB]:
if not trackCodec in [TrackCodec.PGS, TrackCodec.VOBSUB]:
inputMappingTokens += ["-map", f"0:{stdi}"]
return inputMappingTokens

@ -16,6 +16,7 @@ class TrackCodec(Enum):
SRT = {'identifier': 'subrip', 'format': 'srt', 'extension': 'srt' , 'label': 'SRT'}
ASS = {'identifier': 'ass', 'format': 'ass', 'extension': 'ass' , 'label': 'ASS'}
TTF = {'identifier': 'ttf', 'format': None, 'extension': 'ttf' , 'label': 'TTF'}
PGS = {'identifier': 'hdmv_pgs_subtitle', 'format': 'sup', 'extension': 'sup' , 'label': 'PGS'}
VOBSUB = {'identifier': 'dvd_subtitle', 'format': None, 'extension': 'mkv' , 'label': 'VobSub'}

@ -5,6 +5,7 @@ class TrackType(Enum):
VIDEO = {'label': 'video', 'index': 1}
AUDIO = {'label': 'audio', 'index': 2}
SUBTITLE = {'label': 'subtitle', 'index': 3}
ATTACHMENT = {'label': 'attachment', 'index': 4}
UNKNOWN = {'label': 'unknown', 'index': 0}

Loading…
Cancel
Save