Return to site

Ffmpeg Extract Ass Subtitle

broken image


Opened 9 years ago

  1. Example to stream copy all of the video and audio streams, convert the all text based subtitle input streams (SRT, ASS, VTT, etc) to the streaming text format, and set the language for the first two subtitle streams. Ffmpeg -i input.mkv -map 0 -c copy -c:s movtext -metadata:s:s:0 language=eng -metadata:s:s:1 language=ipk output.mp4.
  2. Does any body know how to extract subtitles from a dvd or a vob file with ffmpeg? I could get fine working.sub and.idx files via mencoder command: mencoder dvd://1 -vobsubout subtitle -vobsuboutindex 0 -vobsuboutid it -sid 10 -nosound -ovc copy -o 1.avi but i get a huge temporary file (1.avi) witch is the entire video stream.

In the meantime, I suppose you know you can use mkvextract to extract the subtitles tracks. For me reading srt files works fine. I tried something like 'ffmpeg -i subs.srt subs.ass' and it works. I only have problems with writting ass subtitles to mkv files, but it is separate and more complicated issue.

Closed 8 years ago

Last modified 7 years ago

#862closeddefect (fixed)

Reported by:Owned by:
Priority: normal Component: ffmpeg
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Attachments (4)

SRT-in-MKV-support.patch​ (1.7 KB) - added by 9 years ago.
Add timecodes to srt subtitles exported from matroska.
ffmpeg.verbose.log​ (2.5 KB) - added by 9 years ago.
Output of 'ffmpeg -loglevel verbose -scodec srt -i source.mkv -y target.srt'
target.srt​ (192 bytes) - added by 9 years ago.
Expected output(subtitles with timecodes).
source.mkv​ (266.1 KB) - added by 9 years ago.
Sample source file. Contains video audio and srt subtitle track.

Download all attachments as: .zip

Change History (11)

by , 9 years ago

comment:1 by , 9 years ago

by , 9 years ago

Ffmpeg extract subtitle from mkv

by , 9 years ago

by , 9 years ago

comment:2 by , 9 years ago

Ffmpeg Subtitle Stream

follow-ups: 4 5comment:3 by , 9 years ago

Component:avformatFFmpeg
Keywords: text subtitles added; srt matroska mkv removed
Reproduced by developer: set
Status:newopen

in reply to: 3comment:4 by , 9 years ago

in reply to: 3comment:5 by , 9 years ago

Last edited 9 years ago by (previous) (diff)

comment:6 by , 8 years ago

comment:7 by , 7 years ago

Note: See TracTickets for help on using tickets.
Ffmpeg Extract Ass Subtitle

by , 9 years ago

by , 9 years ago

comment:2 by , 9 years ago

Ffmpeg Subtitle Stream

follow-ups: 4 5comment:3 by , 9 years ago

Component:avformatFFmpeg
Keywords: text subtitles added; srt matroska mkv removed
Reproduced by developer: set
Status:newopen

in reply to: 3comment:4 by , 9 years ago

in reply to: 3comment:5 by , 9 years ago

Last edited 9 years ago by (previous) (diff)

comment:6 by , 8 years ago

comment:7 by , 7 years ago

Note: See TracTickets for help on using tickets.
Simple python script to encode videos using ffmpeg
encode.py
''
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:
filelist = filter(lambda f: f.split('.')[-1] 'mkv', os.listdir(cwd))

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!

commented Aug 10, 2020

Ffmpeg Extract Srt

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:
filelist = filter(lambda f: f.split('.')[-1] 'mkv', os.listdir(cwd))

for future reference, this would be filter(lambda f: 'x265' in f and f.split('.')[-1] 'mkv', os.listdir(cwd))
or, using list comprehension, filelist = [f for f in os.listdir(cwd) if 'x265' in f and f.split('.')[-1] 'mkv']

Ffmpeg Extract Subtitle From Mkv

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment




broken image