ffmpeg를 사용하여 텍스트 자막 추가
ffmpeg를 사용하여 .mp4 컨테이너에 텍스트 자막을 추가하려고합니다.
ffmpeg -i input.mp4 -i input.srt -map 0.0 -map 0.1 -map 1.0 output.mp4
이 줄을 실행하려고 할 때 오류가 발생합니다.
스트림 맵 수는 출력 스트림 수와 일치해야합니다.
mp4를 mkv로 변경하려고하면 (MP4는 텍스트 자막을 지원하지만) 다음과 같이됩니다.
ffmpeg -i input.mp4 -i input.srt -map 0.0 -map 0.1 -map 1.0 output.mkv
스트림을 올바르게 매핑하지만 오류가 발생합니다.
출력 스트림 # 0.2에 대한 인코더 (코덱 ID 94210)를 찾을 수 없습니다.
내가 시작할 때
ffmpeg -codecs
srt 코덱이 디코더 및 인코더로 지원된다는 것을 알 수 있지만 mp4 및 mkv subs 인코딩에 사용되는 것이 무엇인지, 스위치를 켜거나 별도로 컴파일해야하는지 확실하지 않습니다.
ffmpeg -i infile.mp4 -i infile.srt -c copy -c:s mov_text outfile.mp4
-vf subtitles=infile.srt
함께 작동하지 않습니다 -c copy
순서 -c copy -c:s mov_text
가 중요합니다. FFmpeg에게 말하고 있습니다.
- 비디오 : 복사, 오디오 : 복사, 부제 : 복사
- 부제 : mov_text
반전하면 FFmpeg에 다음과 같이 말합니다.
- 부제 : mov_text
- 비디오 : 복사, 오디오 : 복사, 부제 : 복사
또는 -c:v copy -c:a copy -c:s mov_text
어떤 순서로든 사용할 수 있습니다 .
libass
라이브러리를 사용하십시오 (ffmpeg 설치에 구성에 라이브러리가 있는지 확인하십시오 --enable-libass
).
먼저 자막을 .ass
형식으로 변환하십시오 .
ffmpeg -i subtitles.srt subtitles.ass
그런 다음 비디오 필터를 사용하여 추가합니다.
ffmpeg -i mymovie.mp4 -vf ass=subtitles.ass mysubtitledmovie.mp4
자막을 자막 스트림으로 다중화하려고합니다. 간단하지만 MP4 (또는 M4V)와 MKV에는 다른 구문이 사용됩니다. 두 경우 모두 비디오 및 오디오 코덱을 지정하거나 자막 만 추가하려는 경우 스트림 만 복사해야합니다.
MP4 :
ffmpeg -i input.mp4 -f srt -i input.srt \
-map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy \
-c:s mov_text output.mp4
MKV :
ffmpeg -i input.mp4 -f srt -i input.srt \
-map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy \
-c:s srt output.mkv
MKV 컨테이너는 거의 모든 비디오 및 오디오 코덱을 지원하며 자막 및 DVD 메뉴도 지원합니다. 따라서 자막이있는 MKV 컨테이너를 사용하여 입력 비디오에서 출력 비디오로 코덱을 복사 할 수 있습니다. 먼저 SRT를 ASS 자막 형식으로 변환해야합니다.
ffmpeg -i input.srt input.ass
비디오에 ASS 자막 포함
ffmpeg -i input.mp4 -i input.ass -c:v copy -c:a copy -c:s copy -map 0:0 -map 0:1 -map 1:0 -y out.mkv
VMW 파일로도 작업했습니다.
ffmpeg -i input.wmv -i input.ass -c:v copy -c:a copy -c:s copy -map 0:0 -map 0:1 -map 1:0 -y out.mkv
위키 페이지 참조 컨테이너 형식 비교
ffmpeg는 mov_text
MP4 컨테이너에서 지원되고 iTunes, Quicktime, iOS 등에서 재생할 수있는 유일한 자막 인코더를 지원합니다 .
귀하의 라인은 다음과 같습니다.
ffmpeg -i input.mp4 -i input.srt -map 0:0 -map 0:1 -map 1:0 -c:s mov_text output.mp4
이 작업에 MP4Box를 사용해 보았지만 내가 다루고있는 M4V를 처리 할 수 없었습니다. 다음 명령 줄을 사용하여 ffmpeg를 사용하여 SRT를 소프트 자막으로 삽입하는 데 성공했습니다.
ffmpeg -i input.m4v -i input.srt -vcodec copy -acodec copy -scodec copy -map 0:0 -map 0:1 -map 1:0 -y output.mkv
당신처럼 MKV 출력 파일을 사용해야했습니다. M4V 파일을 만들 수 없었습니다.
I will provide a simple and general answer that works with any number of audios and srt subtitles and respects the metadata that may include the mkv container. So it will even add the images the matroska may include as attachments (though not another types AFAIK) and convert them to tracks; you will not be able to watch but they will be there (you can demux them). Ah, and if the mkv has chapters the mp4 too.
ffmpeg -i <mkv-input> -c copy -map 0 -c:s mov_text <mp4-output>
As you can see, it's all about the -map 0
, that tells FFmpeg to add all the tracks, which includes metadata, chapters, attachments, etc. If there is an unrecognized "track" (mkv allows to attach any type of file), it will end with an error.
You can create a simple batch mkv2mp4.bat
, if you usually do this, to create an mp4 with the same name as the mkv. It would be better with error control, a different output name, etc., but you get the point.
@ffmpeg -i %1 -c copy -map 0 -c:s mov_text "%~n1.mp4"
Now you can simply run
mkv2mp4 "Video with subtitles etc.mkv"
And it will create "Video with subtitles etc.mp4" with the maximum of information included.
Simple Example:
videoSource=test.mp4
videoEncoded=test2.mp4
videoSubtitle=test.srt
videoFontSize=24
ffmpeg -i "$videoSource" -vf subtitles="$videoSubtitle":force_style='Fontsize="$videoFontSize"' "$videoEncoded"
Only replace the linux variables
This is the reason why mkv is such a good container, especially now that it's mature:
mkvmerge -o output.mkv video.mp4 subtitle.srt
참고URL : https://stackoverflow.com/questions/8672809/use-ffmpeg-to-add-text-subtitles
'IT박스' 카테고리의 다른 글
폴더에 파일이 있는지 확인하는 방법은 무엇입니까? (0) | 2020.08.20 |
---|---|
신속한 사운드 생성 및 재생 (0) | 2020.08.20 |
Laravel의 MassAssignmentException (0) | 2020.08.20 |
특정 시간 동안 일시 중지하는 방법은 무엇입니까? (0) | 2020.08.20 |
Angular2 튜토리얼 (Tour of Heroes) : 'angular2-in-memory-web-api'모듈을 찾을 수 없습니다. (0) | 2020.08.20 |