본문 바로가기

맥에서 동영상 자막 추출 방법

by skyChris 2022. 3. 1.

mkv 파일, mp4 파일에서 추출 방법

 

1. mkvtoolnix 이용 (mkv)

2. ffmpeg 이용 (mkv, mp4)

 

 

 

 

MKV files

In order to extract subtitles from Matroska (MKV) files, you need the free and open source mkvtoolnix packages. They come for Windows and Linux, and on a Mac you can install them through Homebrew with brew install mkvtoolnix.

 

Then, inspect the file:

 

mkvmerge -i input.mkv

 

This will list the tracks, for example like this:

 

File 'input.mkv': container: Matroska

Track ID 1: video (V_MPEG4/ISO/AVC)

Track ID 2: audio (A_AAC)

Track ID 3: subtitles (S_TEXT/UTF8)

 

Based on the ID of the track, call the following command, where <trackID> is the one you identified above. <output> is just a dummy name, you can use any you want.

 

mkvextract tracks input.mkv <trackID>:<output>.srt

 

So, in our case, that would have been:

 

mkvextract tracks input.mkv 3:subs.srt

 

 

 

 

 

 

 

FFMPEG

 

FFmpeg can easily extract embedded subtitles from videos.

This command will grab the default subtitle track and export it as a srt file:

 

ffmpeg -i input_file out.srt

 

What if we want to get a different subtitle?

First we need to figure out the track number for that subtitle by running ffmpeg ‑i input_file.

You will get an output that something like this:

[...] Stream #0:2(eng): Subtitle: subrip (default) Metadata: title : English-SRT Stream #0:3(eng): Subtitle: hdmv_pgs_subtitle Metadata: title : English-PGS Stream #0:3(chi): Subtitle: hdmv_pgs_subtitle Metadata: title : Chinese-PGS [...]

Notice the tracks are numbered #0:2, #0:3, etc. This is the value we want to pass over to the map command to select the proper subtitle.

 

ffmpeg -i input_file -map 0:3 out.srt

 

 

반응형

댓글