Skip to content

Commit

Permalink
process-video: copy subtitle format by default and attempt to convert…
Browse files Browse the repository at this point in the history
… if target container does not support it pt.2
  • Loading branch information
chapmanjacobd committed Nov 19, 2024
1 parent 2eeafb8 commit d4bd121
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 7 additions & 0 deletions xklb/data/ffmpeg_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
)
)

unsupported_subtitle_error = re.compile(
"|".join(
r""".*Subtitle codec.*not supported""".splitlines(),
),
flags=re.IGNORECASE,
)

unsupported_error = re.compile(
"|".join(
r""".*at least one.* received no packets
Expand Down
5 changes: 3 additions & 2 deletions xklb/mediafiles/process_ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ def process_path(args, path, include_timecode=False, subtitle_streams_unsupporte
"-movflags",
"use_metadata_tags",
*ff_opts,
# "-copy_unknown",
"-map_metadata",
"0",
"-map_chapters",
Expand All @@ -328,6 +329,7 @@ def process_path(args, path, include_timecode=False, subtitle_streams_unsupporte
processes.cmd(*command)
except subprocess.CalledProcessError as e:
error_log = e.stderr.splitlines()
is_unsupported_subtitle = any(ffmpeg_errors.unsupported_subtitle_error.match(l) for l in error_log)
is_unsupported = any(ffmpeg_errors.unsupported_error.match(l) for l in error_log)
is_file_error = any(ffmpeg_errors.file_error.match(l) for l in error_log)
is_env_error = any(ffmpeg_errors.environment_error.match(l) for l in error_log)
Expand All @@ -337,8 +339,7 @@ def process_path(args, path, include_timecode=False, subtitle_streams_unsupporte
elif is_file_error:
if args.delete_unplayable:
path.unlink()
elif subtitle_stream and is_unsupported and not subtitle_streams_unsupported:
# TODO: match against specific subtitle unsupported errors
elif is_unsupported_subtitle and not subtitle_streams_unsupported:
output_path.unlink(missing_ok=True) # Remove transcode attempt, if any
return process_path(
args, path, include_timecode=include_timecode, subtitle_streams_unsupported=True, **kwargs
Expand Down
4 changes: 1 addition & 3 deletions xklb/mediafiles/process_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ def process_path(args, path):
return path if path.exists else None

output_stats = output_path.stat()
if output_stats.st_size == 0 or (
args.delete_larger and output_stats.st_size > original_stats.st_size
):
if output_stats.st_size == 0 or (args.delete_larger and output_stats.st_size > original_stats.st_size):
output_path.unlink() # Remove transcode
return path

Expand Down

0 comments on commit d4bd121

Please sign in to comment.