MCPcopy Create free account
hub / github.com/smacke/ffsubsync / extract_subtitles_from_reference

Function extract_subtitles_from_reference

ffsubsync/ffsubsync.py:403–446  ·  view source on GitHub ↗
(args: argparse.Namespace)

Source from the content-addressed store, hash-verified

401
402
403def extract_subtitles_from_reference(args: argparse.Namespace) -> int:
404 stream = args.extract_subs_from_stream
405 if not stream.startswith("0:s:"):
406 stream = "0:s:{}".format(stream)
407 elif not stream.startswith("0:") and stream.startswith("s:"):
408 stream = "0:{}".format(stream)
409 if not stream.startswith("0:s:"):
410 logger.error(
411 "invalid stream for subtitle extraction: %s", args.extract_subs_from_stream
412 )
413 ffmpeg_args = [
414 ffmpeg_bin_path("ffmpeg", args.gui_mode, ffmpeg_resources_path=args.ffmpeg_path)
415 ]
416 ffmpeg_args.extend(
417 [
418 "-y",
419 "-nostdin",
420 "-loglevel",
421 "fatal",
422 "-i",
423 args.reference,
424 "-map",
425 "{}".format(stream),
426 "-f",
427 "srt",
428 ]
429 )
430 if args.srtout is None:
431 ffmpeg_args.append("-")
432 else:
433 ffmpeg_args.append(args.srtout)
434 logger.info(
435 "attempting to extract subtitles to {} ...".format(
436 "stdout" if args.srtout is None else args.srtout
437 )
438 )
439 retcode = subprocess.call(ffmpeg_args)
440 if retcode == 0:
441 logger.info("...done")
442 else:
443 logger.error(
444 "ffmpeg unable to extract subtitles from reference; return code %d", retcode
445 )
446 return retcode
447
448
449def _detect_srtin_from_reference(reference: str) -> List[str]:

Callers 1

_run_implFunction · 0.85

Calls 1

ffmpeg_bin_pathFunction · 0.90

Tested by

no test coverage detected