자막과 동영상 싱크 맞춰주는 오픈소스
darong
22
4144
2
2019.05.06 23:18
자막과 동영상의 싱크를 맞춰주는 오픈소스가 있어서 소개할려고 합니다.
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 파일이 생성됩니다.
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 파일이 생성됩니다.
22 Comments
궁금해서 한번 해봤는데 아래와 같은 오류만 나오고 안되네요 ㅠㅠ
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 인데 같은 메시지가 뜨네요ㅠㅠ
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 인데 같은 메시지가 뜨네요ㅠㅠ
혹시 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은 이름만 들었지 아무것도 몰라요ㅠㅠ
위에 적어주신 "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은 이름만 들었지 아무것도 몰라요ㅠㅠ
python 버전 문제일 수 있습니다. 제 버전은 python 3.65 버전입니다.
pip install git+https://github.com/smacke/subsync 로 설치시 에러가 발생하면 뭔가 라이브러리 간의 버전 문제일 가능성이 있습니다.
ffprobe 가 실행은 되나요? 에러 로그를 봐서는 이 실행 파일이 없어서 발생하는 것 같습니다.
pip install git+https://github.com/smacke/subsync 로 설치시 에러가 발생하면 뭔가 라이브러리 간의 버전 문제일 가능성이 있습니다.
ffprobe 가 실행은 되나요? 에러 로그를 봐서는 이 실행 파일이 없어서 발생하는 것 같습니다.
추카추카 17 Lucky Point!
친절한 답변 고맙습니다.
ffmpeg을 진짜 ffmpeg.exe 파일 1개만 (기존에 이 파일만 사용중) 있으니 안되었네요
ffprobe.exe ffplay.exe 같이 넣으니 작동합니다
pip install git+https://github.com/smacke/subsync 로는 설치가 여전히 안되고요
pip install subsync-master.zip 로 설치 후 작동 확인은 했습니다
이것저것 해보고 저 처럼 처음 해보시는분 위해 댓글이나 새글 게시하겠습니다. 고맙습니다
ffmpeg을 진짜 ffmpeg.exe 파일 1개만 (기존에 이 파일만 사용중) 있으니 안되었네요
ffprobe.exe ffplay.exe 같이 넣으니 작동합니다
pip install git+https://github.com/smacke/subsync 로는 설치가 여전히 안되고요
pip install subsync-master.zip 로 설치 후 작동 확인은 했습니다
이것저것 해보고 저 처럼 처음 해보시는분 위해 댓글이나 새글 게시하겠습니다. 고맙습니다
안녕하세요! 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
쉽고 편한 싱크 조절 검색을 하다 이제야 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
우선 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'
드디어 오류 메시지도 보았습니다.
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'
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
정말 고맙습니다ㅠㅠ!!!
다만 테스트한 영상들의 싱크가 하나도 맞지 않습니다!!!
영상 시간 기준으로 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