Mux video and subtitles (.mkv) Subtitles are typically embedded in mkv files, but are usually kept as separate files with mp4. Ffmpeg -i 'video.mp4' -i 'subtitle.srt' -c copy 'output.mkv' Supported subtitle formats by ffmpeg for.mkv: srt, ass, ssa and PGS (Bluray image based subtitles). Simple python script to encode videos using ffmpeg - encode.py. # extract ass subtitles and and subtitle into command: subprocess. Call (FFMPEGPATH.
- Ffmpeg Extract Pgs Subtitles
- Ffmpeg Dvd Subtitles
- Ffmpeg Extract Vobsub
- Ffmpeg Extract Srt
- Ffmpeg Extract Subtitle From Mkv
Ffmpeg Extract Pgs Subtitles
'' |
This python script encodes all files that have the extension mkv in the current |
working directory. |
Sources: |
http://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide |
'' |
importsubprocess, os |
#------------------------------------------------------------------------------- |
# CONFIGURABLE SETTINGS |
#------------------------------------------------------------------------------- |
# controls the quality of the encode |
CRF_VALUE='21' |
# h.264 profile |
PROFILE='high' |
# encoding speed:compression ratio |
PRESET='fast' |
# path to ffmpeg bin |
FFMPEG_PATH='/usr/local/bin/ffmpeg' |
# font dir |
FONT_DIR='/var/www/.fonts' |
#------------------------------------------------------------------------------- |
# encoding script |
#------------------------------------------------------------------------------- |
defprocess(): |
cwd=os.getcwd() |
# get a list of files that have the extension mkv |
filelist=filter(lambdaf: f.split('.')[-1] 'mkv', os.listdir(cwd)) |
filelist=sorted(filelist) |
# encode each file |
forfileinfilelist: |
encode(file) |
defencode(file): |
name='.join(file.split('.')[:-1]) |
subtitles='temp.ass'.format(name) |
output='{}.mp4'.format(name) |
try: |
command= [ |
FFMPEG_PATH, '-i', file, |
'-c:v', 'libx264', '-tune', 'animation', '-preset', PRESET, '-profile:v', PROFILE, '-crf', CRF_VALUE, |
] |
# create a folder called attachments and symlink it to FONT_DIR |
# extract attachments |
subprocess.call(['mkdir', 'attachments']) |
subprocess.call(['rm', '-f', FONT_DIR]) |
subprocess.call(['ln', '-s', '{}/attachments'.format(os.getcwd()), FONT_DIR]) |
os.chdir('attachments') |
subprocess.call([FFMPEG_PATH, '-dump_attachment:t', ', '-i', './{}'.format(file)]) |
os.chdir('.') |
# extract ass subtitles and and subtitle into command |
subprocess.call([FFMPEG_PATH, '-i', file, subtitles]) |
ifos.path.getsize(subtitles) >0: |
command+= ['-vf', 'ass={}'.format(subtitles)] |
command+= ['-c:a', 'copy'] # if audio is using AAC copy it - else encode it |
command+= ['-threads', '8', output] # add threads and output |
subprocess.call(command) # encode the video! |
finally: |
# always cleanup even if there are errors |
subprocess.call(['rm', '-fr', 'attachments']) |
subprocess.call(['rm', '-f', FONT_DIR]) |
subprocess.call(['rm', '-f', subtitles]) |
if__name__'__main__': |
process() |
commented Mar 26, 2020
Thanks for the script. Can it be modified to look for a keyword string in the first part of the file name? I want to decode only files that have 'x265' in the name (e.g. 'The.Invisible.Man.x265.DD5.1.mkv'). I assume the modification would center around this line in the script: I looked on the web and couldn't find much, and trial and error resulted in only errors. Any help you can offer would be appreciated! |
Ffmpeg Dvd Subtitles
commented Aug 10, 2020 •
Ffmpeg Extract Vobsub
for future reference, this would be filter(lambda f: 'x265' in f and f.split('.')[-1] 'mkv', os.listdir(cwd)) |