Managing video for SABU

Handle MP4 video problems

In the previous post , we talk about how to extract MP4 and subtitle files from MKV files. Actually, ffmpeg can also do video conversion and re-encode your video. It helps when the video/voice encoding format is not supported. In case you have problems on your MP4 ( either because of file format or the too high the resolution ), you can re-encode your MP4 from your video source ( instead of extract/copy ) for your iPhone by ffpmeg.

Here is the command to do so.

ffmpeg -i inputVideo.mkv -s 480×320 outputVideo.mp4.

Meaning of parameters:

-i inputVideo.mkv : name of input video file. this could be rvmb, mp4 or other formats.
-s 480×320 : this is the standard iPhone resolution. You can use 960×640 for retina display.
outputVideo.mp4 : this is the output video filename and should have the .mp4 extension

Optimize the video file size

Though you have watched some anime/drama, most likely you would like to keep them always on the iPhone for SABU. The reason is either you can easier do revision or play the “real” sound and clips when you study the built in flash cards.

Instead of storing the whole 200-300MB video for each 30min episode, you can consider downsize the mp4 ( lower the video quality and voice quality ) so that the resultant file is 30MB. Then, you can keep a decent collections of dramas in your iPhone.

If you dedicate 10G of space for the videos, you can keep 333 similar episodes ( ~ 10-20 series of dramas ). If you have a 128G iPhone, you can store around 200 series of dramas.

Here is the command to do so.

ffmpeg -i inputVideo.mkv -s 480×320 -b 100k -ab 64k outputVideo.mp4

Meaning of parameters:

-i inputVideo.mkv : name of input video file. this could be rvmb, mp4 or other formats.
-s 480×320 : this is the standard iPhone resolution. You can use 960×640 for retina display.
-b 100k : video bit rate. 100k is a pretty low ( while still acceptable for me ). you can adjust the bit rate if you want different quality or size
-ab 64k : voice bit rate. we suggest not to downsize the voice to less than 64kbps because it is better to keep a decent copy of the voice for learning a language.
outputVideo.mp4 : this is the output video filename and should have the .mp4 extension

I tried a sample of above command and converted my original 30mins episode from around 500M to 30M.

Here are some of my test results for a 30mins episode.

1M video bit rate -> 207M
500K video bit rate -> 115M
200K video bit rate -> 61M
100K video bit rate -> 42M
100K video / 64k voice bit rate -> 31M
100K video / 32k voice bit rate -> 25M

Results of mp3 ( voice only ) for comparison:

64k voice bit rate -> 11.6M

Bulk conversion of video files

You may have a series of episodes in MKV with different subtitles. After checking the tracks of the subtitles, you can extract MP4 and subtitles using script like below.

Example bash script for conversion ( test in Mac OS X )

for a in *.mkv ; do echo “${a%.*}” ;

ffmpeg -i “$a” -vn -an -map 0:3 -c:s ssa temp.ssa;
grep -v “,CN,\|,OP-CN,\|,ZWDB,\|,ZWBT,” temp.ssa > “${a%.*}.jp.ssa”;
rm temp.ssa

ffmpeg -i “$a” -vn -an -map 0:2 -c:s ssa temp.ssa
grep -v “,JP,\|,OP-JP,\|,JPDB,\|,JPOP,” temp.ssa > “${a%.*}.chs.ssa”;
rm -f temp.ssa

ffmpeg -i “$a” -vn -an -map 0:4 -c:s ssa temp.ssa;
grep -v “,CN,\|,OP-CN,\|,ZWDB,\|,ZWBT,” temp.ssa > “${a%.*}.jp2.ssa”;
rm temp.ssa

ffmpeg -i “$a” -vn -an -map 0:3 -c:s ssa temp.ssa
grep -v “,JP,\|,OP-JP,\|,JPDB,\|,JPOP,” temp.ssa > “${a%.*}.cht2.ssa”;
rm temp.ssa

ffmpeg -i “$a” -c:v copy -c:a copy -sn “${a%.*}.mp4”;

done;

For each MKV file in the directory, it extracts the MP4 and track 0:3 ( Japanese subtitle ) into .jp.ssa and so on for the other subtitles. It also process the language file and remove lines of other languages.