adding subtitle to video

Well this might be my last post about using IPod on FreeBSD, cause the last I concerned, for us non-English users only, how to “hard-encode” the subtitle to video files, is resolved :)

Most of the DVD rip tools will generate 2 files: an avi file, mostly xvid encoded, and a .srt file, which holds the subtitle. There might be several .srt files if there are multiple language on the DVD.

Most player on FreeBSD, like mplayer, handle this situation quite well, it will find the subtitle and display it, as long as the .avi file and the .srt file holds the same base name. However, IPod can’t do this. So we’ll need to “paint” the subtitle into the video.

The command I use is:

mencoder "$1" -sub "$base.srt" -oac copy -ovc lavc -font \
"~/.mplayer/subfont.ttf" -subcp cp936 -subfont-text-scale \
4 -vf scale=320:240 -o temp.avi

The key here is “-font” to specify the font to render, “-subcp” to specify the encoding of the subtitle, and “-subfont-text-scale” to specify the size of the rendered font. I also added “-vf scale=320:240″ here to prevent the font get blured in the next “ffmpeg” step.

So here’s the final script I got:

#!/bin/sh

base=`echo $1 | gawk -F. ‘{print $1}’ `

echo “$1 $base”

# test
# -endpos 60

# # add subtitle
mencoder “$1″ -sub “$base.srt” -oac copy -ovc lavc -font \
“~/.mplayer/subfont.ttf” -subcp cp936 -subfont-text-scale \
4 -vf scale=320:240 -o temp.avi

# rm to avi
# mencoder “$1″ -oac copy -ovc lavc -o temp.avi
# sometime we need to use this
# mencoder “$1″ -oac pcm -ovc lavc -o temp.avi

# #to ipod, if no previous convert needed
# ffmpeg -i “$1″ -f mp4 -vcodec xvid -maxrate 2000 -b 1500 \
# -qmin 3 -qmax 5 -bufsize 16384 -g 30 -acodec aac -ac 2 -ar 44100 -ab 192 -s \
# 320×240 -aspect 4:3 “$base.mp4″

#to ipod, if previous convert needed
ffmpeg -i temp.avi -f mp4 -vcodec xvid -maxrate 2000 -b 1500 \
-qmin 3 -qmax 5 -bufsize 16384 -g 30 -acodec aac -ac 2 -ar 44100 -ab 192 -s \
320×240 -aspect 4:3 “$base.mp4″

# # remove temporary file, if needed
rm temp.avi
And now I can make IPod compitable videos with Chinese subtitle, English subtitle, and no subtitle. And my wife can learn English on her IPod now :)

Tags: , , , , ,

Post a Comment

You could use <code type="name"> to get your code colorized

Your email is never published nor shared. Required fields are marked *

Close
E-mail It