두 개의 srt 파일을 병합하는 명령줄 도구가 있습니까?

두 개의 srt 파일을 병합하는 명령줄 도구가 있습니까?

cd1.srt와 cd2.srt라는 두 개의 srt 파일이 있습니다. 불행히도 srtool은 더 이상 어디에서나 사용할 수 없습니다. 이는 몇 년 전에 제기된 동일한 질문에 대한 답변이었습니다.

두 개의 *.srt 파일을 병합하는 방법

하지만 아직 충분하지 않습니다. 나는 노력했다https://tracker.debian.org/pkg/pysrt, srt 파일 결합을 제외한 모든 작업을 수행할 수 있습니다. :(

github도 찾아봤지만 이런 항목만 찾았습니다.

https://github.com/malfroid/merge-srt-subtitles

더 좋은 방법을 아시는 분 계시면 공유 부탁드립니다. 또한 일부 온라인 솔루션도 살펴봤지만 불행히도 모두 성공하지 못했습니다.

답변1

이것이 내가 하는 방법이다:

먼저 첫 번째 srt 파일의 종료 타임스탬프를 확인했습니다. 제 경우에는 두 번째 타임스탬프가 첫 번째 타임스탬프 직후에 시작되었기 때문에 이동 시간 범위를 쉽게 추론할 수 있었습니다.

이를 통해 귀하의 답변에 대한 의견에서 @aviro가 언급했듯이pysrt위에서 유추한 기간과 동일합니다.

pip install pysrt
srt -i shift 1h2m58s cd2.srt

그런 다음 두 srt파일을 병합하기 전에 cd2.srt에서 하위 카운터를 오프셋하여 제대로 작동하도록 해야 합니다.

이를 위해 다음 Python 스크립트를 사용하여 완전한 오프셋을 생성합니다 cd2.srt. ($numX를 (cd1.srt의 자막 합계) + 1로 대체)

# Open the input file for reading
with open('cd2.srt', 'r') as input_file:
  # Open the output file for writing
  with open('cd2.output.srt', 'w') as output_file:
    # Iterate over each line in the input file
    for line in input_file:
      # Check if the line contains a single integer
      if line.strip().isdigit():
        # Convert the line to an integer
        number = int(line)
        # Add $numX to the number
        number += $numX
        # Write the resulting number to the output file
        output_file.write(str(number) + '\n')
      else:
        # Write the original line to the output file
        output_file.write(line)

그런 다음 다음을 통해 최종 병합을 수행합니다.cat cd1.srt cd2.output.srt > final.srt

이제 새로 병합된 비디오 파일에서 자막이 제대로 작동합니다!

관련 정보