자막과 동영상 싱크 맞춰주는 오픈소스

자유게시판

자막과 동영상 싱크 맞춰주는 오픈소스

자막과 동영상의 싱크를 맞춰주는 오픈소스가 있어서 소개할려고 합니다.

https://github.com/smacke/subsync

이 오픈소스를 사용할려면 프로그래밍에 대한 이해가 있어야 하며, python에 대해 기본적인 지식이 필요할 수 있습니다.

오픈소스는 아래 명령어로 설치합니다.

pip install git+https://github.com/smacke/subsync

컴퓨터에 먼저 python pip가 설치되어 있어야 합니다.

sunsync를 설치한 다음 아래와 같은 명령어로 싱크를 맞출 수 있습니다.

subsync video.mp4 -i unsynchronized.srt > synchronized.srt

video.mp4, unsynchronized.srt , synchronized.srt는 각각 동영상,싱크맞출 자막파일, 싱크처리된 자막파일입니다.
그러니까 자막과 동영상이 video.mp4, unsynchronized.srt일 때 위 명령어를 실행하면 싱크를 맞춘 synchronized.srt 파일이 생성됩니다.
Facebook Twitter GooglePlus KakaoStory NaverBand 신고
 
22 Comments
16 o지온o  
정보 공유 감사합니다.
싱크를 맞춰준다니 신기하기는 하네요.
한 번 해보려고 했지만, 뭔가를 설치해야 한다고 하셨고..
[이 오픈소스를 사용할려면 프로그래밍에 대한 이해가 있어야 하며, python에 대해 기본적인 지식이 필요할 수 있습니다.]
..에서 기본 지식은 없기 때문에 일단 보류. 뭔가 설치하는 것도 좋아하진 않아서..
S 맨발여행  
영어 이외의 언어에서는 동기화 품질이 떨어진다는 의견이 보이네요.
음성에서 자막 싱크를 추출해주는 유틸도 나오는데, 한국어에는 무리일 거 같습니다.
2 darong  
이 프로그램은 듣기만으로 번역한 자막을 영상과 싱크 맞출 때 유용하지 않을까 합니다.
30 여보밥줘  
궁금해서 한번 해봤는데 아래와 같은 오류만 나오고 안되네요 ㅠㅠ
srt 파일의 인코딩 바꿔도 안되고
C:\>subsync c:\1.mp4 -i c:\1.srt -o 2.srt 로 해도 같은 오류만 나오네요1?
오류메시지는
----------
C:\>subsync c:\1.mp4 -i c:\1.srt > 2.srt
INFO:subsync.subsync:computing alignments...
INFO:subsync.speech_transformers:extracting speech segments from subtitles...
Traceback (most recent call last):
  File "C:\Python\Scripts\subsync-script.py", line 11, in <module>
    load_entry_point('subsync==0.2.4', 'console_scripts', 'subsync')()
  File "c:\python\lib\site-packages\subsync\subsync.py", line 61, in main
    reference_pipe.fit_transform(args.reference)
  File "c:\python\lib\site-packages\sklearn\pipeline.py", line 300, in fit_transform
    return last_step.fit_transform(Xt, y, **fit_params)
  File "c:\python\lib\site-packages\sklearn\base.py", line 464, in fit_transform
    return self.fit(X, **fit_params).transform(X)
  File "c:\python\lib\site-packages\subsync\speech_transformers.py", line 51, in fit
    total_duration = float(ffmpeg.probe(fname)['format']['duration'])
  File "c:\python\lib\site-packages\ffmpeg\_probe.py", line 16, in probe
    p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "c:\python\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "c:\python\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 지정된 파일을 찾을 수 없습니다

--------------설치된 내용은
C:\>pip list
Package      Version
------------- -------
ffmpeg-python 0.1.17
future        0.17.1
numpy        1.16.3
pip          19.1.1
scikit-learn  0.20.3
scipy        1.2.1
setuptools    40.8.0
six          1.12.0
sklearn      0.0
srt          1.10.0
subsync      0.2.4
tqdm          4.31.1
webrtcvad    2.0.10
설치는 정상으로 된것 같은데 제가 빠뜨린게 있나요?
사용환경은 테스트로 VM에 설치한 윈도우10 x64 과 집에서 사용중인 윈10 x64 인데 같은 메시지가 뜨네요ㅠㅠ
2 darong  
아마 ffmpeg가 설치되어 있지 않아서 그럴 겁니다.
ffmpeg를 다운로드 받은 후 실행파일을 path에 지정된 디렉토리에 복사하세요.

where ffprobe
위 명령어를 실행했을 때 파일이 보이면 정상 동작할 것 같습니다.
30 여보밥줘  
혹시 ffmpeg 도 버전에 따라 안되나요? 이미 windows 폴더에 있는데 같은 에러로 안되네요
위에 적어주신 "pip install git+https://github.com/smacke/subsync" 로 설치가 안되서
zip피일을 받아 "pip install subsync-master.zip" 으로 설치했는데 이게 잘못 된걸까요?
아니면 python-3.7.3 버전이 문제일까요?
"pip install --upgrade pip" 으로 업데이트도 되어있는 상태입니다 ㅠㅠ

----ffmpeg 버전입니다
C:\>ffmpeg
ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 7.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
  libavutil      55. 78.100 / 55. 78.100
  libavcodec    57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter    6.107.100 /  6.107.100
  libswscale      4.  8.100 /  4.  8.100
  libswresample  2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

제가 python은 이름만 들었지 아무것도 몰라요ㅠㅠ
2 darong  
python 버전 문제일 수 있습니다. 제 버전은 python 3.65 버전입니다.
pip install git+https://github.com/smacke/subsync 로 설치시 에러가 발생하면 뭔가 라이브러리 간의 버전 문제일 가능성이 있습니다.

ffprobe 가 실행은 되나요?  에러 로그를 봐서는 이 실행 파일이 없어서 발생하는 것 같습니다.

추카추카 17 Lucky Point!

30 여보밥줘  
친절한 답변 고맙습니다.
ffmpeg을 진짜 ffmpeg.exe 파일 1개만 (기존에 이 파일만 사용중) 있으니 안되었네요
ffprobe.exe ffplay.exe 같이 넣으니 작동합니다
pip install git+https://github.com/smacke/subsync 로는 설치가 여전히 안되고요
pip install subsync-master.zip 로 설치 후 작동 확인은 했습니다
이것저것 해보고 저 처럼 처음 해보시는분 위해 댓글이나 새글 게시하겠습니다. 고맙습니다
9 fsfdssf  
그러지마시고 저같은 문외한을 위해서 어떻게 하는지 동영상으로 남겨주시면 안될까요..? 오캠으로 찍어서...?
2 darong  
아쉬지만 제가 동영상을 제작할 능력은 안됩니다.
30 여보밥줘  
5-6개 해 봤는데 신기하게 맞춰지네요 ㅎㅎㅎ 소개해 주셔서 고맙습니다!!!!!!!!!!
3 Hsu7  
이거 해보려다가 이해가 안 돼서 포기했었는데..
써보신 분들 효과가 어느 정돈가요?
영자막이 있는 경우에도 싱크 작업만 영상 시간의 3배는 소모하는데
결과가 만족스럽다면 큰 도움이 될 거 같아요
30 여보밥줘  
한 20여개 정도 해봤는데
어느건 잘 안맞고 어느건 신기할 정도로 잘 맞고 그러네요
잘 안맞더라도 원래꺼 보다는 나은것 같아요
여러개 테스트 해 보고 댓글로 알려 드릴게요
3 Hsu7  
저도 시도해봐야겠네요 감사합니다
30 여보밥줘  
설치방법을 댓글로 적으려다 이미 이 글을 보신 분들이 안보실까봐 새글로 게시했습니다
좋은 정보 알려 주셔서 고맙습니다. BlueAI 사이트도 번창하세요!!!

추카추카 4 Lucky Point!

1 나에게  
안녕하세요! darong 님
쉽고 편한 싱크 조절 검색을 하다 이제야 darong 님의 글을 보고 댓글을 답니다.
우선 파이썬은 정말 아예 모르는 상태에서 여보밥줘님의 설치법으로 겨우 프로그램들을 깔았습니다.
c드라이브 바로 안에 영상 1.mp4, 자막 1.srt를 넣어놨습니다 (즉  c:\1.mp4 ,    c:\1.srt)
여기서 문제가... 이제 파이썬을 열고 명령어를 입력하는 건데
어떤 걸 입력해야 할지 모르겠다는 겁니다...
cmd같은 파이썬 창에서 누르는 건지, idle에서 해야하는 건지...
제 명령어가 잘못됐겠지만 방법만이라두 알려주실 수 있을까요?

이건 IDLE에서의 화면입니다
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> C:\>subsync.py c:\1.mp4 -i c:\1.srt -o 2.srt
SyntaxError: unexpected character after line continuation character
2 darong  
idle창이 아닌 cmd 창에서

subsync  c:\1.mp4 -i c:\1.srt -o 2.srt

명령어을 입력하시면 됩니다.
1 나에게  
우선  darong님 피드백 주셔서 정말 감사합니다!!!
드디어 오류 메시지도 보았습니다.
C드라이브에는 영상 파일 이름 1.mp4
기존 자막 1.srt  (SMI -> srt 형식으로 바꿔놓은것)
혹시 몰라 ffmpeg.exe, ffprobe.exe, ffplay.exe 총 5개 파일만 올려놨습니다.
CMD에 알려주신 subsync c:\1.mp4 -i c:\1.srt -o 2.srt 치자마자 이런 오류가 등장했는데.
정말 죄송하지만 지적만 해주십쇼...

Microsoft Windows [Version 10.0.17763.973]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\windows\system32>subsync c:\1.mp4 -i c:\1.srt -o 2.srt
INFO:subsync.subsync:computing alignments...
INFO:subsync.speech_transformers:extracting speech segments from subtitles...
INFO:subsync.speech_transformers:extracting speech segments from video c:\1.mp4...
100%|█████████████████████████████████████████████████████████████████████▉| 7300.0/7306.2498 [00:17<00:00, 413.69it/s]c:\users\JKDATA\appdata\local\programs\python\python38\lib\site-packages\tqdm\std.py:480: TqdmWarning: clamping frac to range [0, 1]
  full_bar = Bar(
100%|███████████████████████████████████████████████████████████| 7306.517333333333/7306.2498 [00:17<00:00, 410.53it/s]
INFO:subsync.speech_transformers:...done.
INFO:subsync.aligners:computing alignments...
INFO:subsync.aligners:...done
INFO:subsync.subsync:offset seconds: -253.050
Traceback (most recent call last):
  File "C:\Users\JKDATA\AppData\Local\Programs\Python\Python38\Scripts\subsync-script.py", line 11, in <module>
    load_entry_point('subsync==0.2.4', 'console_scripts', 'subsync')()
  File "c:\users\JKDATA\appdata\local\programs\python\python38\lib\site-packages\subsync\subsync.py", line 64, in main
    SrtOffseter(offset_seconds).fit_transform(
  File "c:\users\JKDATA\appdata\local\programs\python\python38\lib\site-packages\subsync\subtitle_parsers.py", line 59, in write_file
    with open(fname or sys.stdout.fileno(), 'w', encoding=self.encoding) as f:
PermissionError: [Errno 13] Permission denied: '2.srt'
2 darong  
에러 메세지를 보니 접근 권한 문제인 것 같네요.
2.srt 저장 경로를 시스템 디렉토리가 아닌 다른 디렉토리로 지정해 보세요.
예를들어 c:/tmp/2.srt 이런 식으로요.
아님 sunsync를 관리자 권한으로 실행시켜야 할 겁니다.
1 나에게  
darong님 2.srt (결과물) 도출에 성공하였습니다!!!
정말 고맙습니다ㅠㅠ!!!
다만 테스트한 영상들의 싱크가 하나도 맞지 않습니다!!!
영상 시간 기준으로 1.mp4 (뉴스)는 00:00:20:000쯤에 뉴스를 시작하고
제가 따로 만든 자막 1.srt는 00:00:40:000쯤에 뉴스를 시작합니다. (즉 "OOO 뉴스 시작합니다 멘트")
CMD로 돌리면 2.srt (도출)가 00:00:20:000쯤으로 바뀌어야 정상인데 시작 싱크값이 하나도 맞지 않습니다... (엉뚱하게 00:00:37:000 이렇게)
한국어이기 때문인지, 제가 잘못 세팅한 게 원인인지, 영어로만 해야 하는 건지 정말 헷갈립니다...(tv광고 때문인지도)
질문만 드려 정말 죄송합니다!

C:\windows\system32>subsync c:\1.mp4 -i c:\1.srt -o c:/ABC/2.srt
INFO:subsync.subsync:computing alignments...
INFO:subsync.speech_transformers:extracting speech segments from subtitles...
INFO:subsync.speech_transformers:extracting speech segments from video c:\1.mp4...
 97%|████████████████████████████████████████████████████████████████████▉  | 1900.0/1957.439 [00:03<00:00, 560.16it/s]c:\users\JKDATA\appdata\local\programs\python\python38\lib\site-packages\tqdm\std.py:480: TqdmWarning: clamping frac to range [0, 1]
  full_bar = Bar(
100%|███████████████████████████████████████████████████████████| 1957.5466666666666/1957.439 [00:03<00:00, 527.75it/s]
INFO:subsync.speech_transformers:...done.
INFO:subsync.aligners:computing alignments...
INFO:subsync.aligners:...done
INFO:subsync.subsync:offset seconds: 4.370
2 darong  
오디오에 음악이나 다른 배경음이 있으면 정확도가 많이 떨어졌던 걸로 기억합니다.
동영상 속 오디오에 따라 결과 품질이 많이 달라질 수 있으니, 이 점 고려해서 사용하셔야 합니다.
1 나에게  
빠른 피드백 정말 감사드립니다!!!
행복한 주말 훈훈하게 보내세요~