Been trying to figure out how to do this for quite awhile. Finally found a program that can handle it, but unfortunately it’s windows only and GUI based, so doing it for a batch is difficult. Anyway, here’s the problem this sets out to solve:

For language learning purposes or because you want to watch something with a friend who doesn’t read the same language as you you want to watch a movie with subtitles from two different languages playing at the same time. We’ll assume the subtitles you’re working with are in SRT format, if they’re not the situation is quite a bit more complicated, you can check the suggestions below.

Your best bet is simply to get them into SRT format. You can find a lot of subs at subscene or opensubtitles (or just google) and save yourself the trouble of converting. If that’s not an option, then you can simply convert your subs to SRT format. The program we’ll be using below, Aegissub can import a wide variety of subtitle files, with the exception of vobsub (.idx/.sub extension subtitles).

If you have that kind of subtitle you’ll need to do an OCR conversion, do some googling for avidemux and/or vobsub.

 If you’re running windows, then the easiest solution by far is just to use KMPlayer (as of this writing latest download link is here, if it’s changed just browse the forum a bit). In KMPlayer you can open the file, then choose a 1st and 2nd language subtitle from within the right click menu.
If you’re not on windows then you’ll need to proceed with the merge and convert process. In order to merge the subtitles together you’ll first need to download Aegisub (it’s cross platform). Within Aegisub open the first language’s subtitle file, hit Cmd-A (or Ctrl-A on windows) and then Edit->Copy Lines. Open the second language’s file, and paste the contents in. Then do File->Export Subtitles and save to a new file. If you re-open that new file you’ll see that subs have been merged together. So just rename the new file to match your subtitle file and you’re good to go.

Random things I had to deal with:

Getting NTFS write support to work
This was not all that bad, I installed homebrew, then used it to compile ntfs-3g (and by extension fuse). Fuse requires a little manual editing to get it going by hand, but homebrew helpfully points out what needs to be done. The only tricky bit was that the website with directions that homebrew points you too on how to get fuse automounting NTFS filesystems is meant to be used with MacPorts, so one line of the/sbin/mount_ntfs that he gives you needs to be changed. On line 30 you want to change /opt/local/bin/ntfs-3g to /usr/local/bin/ntfs-3g

Getting Homebrew packages such as mplayer and ffmpeg to install correctly
The other problem I ran into is that Lion seems to be using a different version of gcc than Snow Leopard was using, which caused a lot of programs to stop building correctly. Someone has nicely packaged up an installer for the non-llvm version of GCC, it’s available from here.  To fix the problems and install correctly first uninstall Xcode via /Developer/Library/uninstall-devtools --mode=all, install that package’s gcc, and then reinstall Xcode.

This is possible! Long story short a comment on YiFan’s 3.2.1 jailbreak page pointed out how to do it. I won’t fully explain how to do it here, but basically you need to use YiFan’s jailbreak, then install usbNetwork access to get SSH access to your kindle. Once that’s done you can copy DuoKan onto the kindle as usual, and use your SSH access to run the install script. I’m new to the kindle jailbreaking world, but everything I needed to download to make this work was available here. Duokan itself (english version) you can get from the links on flip’s post here.

Some notes (mostly to remind myself so I don’t have to figure it all out again next time, but maybe they will be useful to someone)

Jailbreak seemed to work used someone’s perl script to make it quicker

for the usbNetwork portion, I followed the steps in the usbNetwork README_FIRST.txt, only thing I had to do that wasn’t mentioned was set up a static ip for my computer that was in the same subnet as the IP set up on the kindle.

This didn’t seem to be mentioned anywhere in the readme files, but to disable the usbnetworking and get back to disk mode you have to retype ~usbNetwork in the search box.
Original text of the comment from elale.smth on Yifan’s page for posterity:

If you wanna install Duokan (for Chinese user), you need first install usbnetwork-0.33, and copy DK¿s folders to root of Kindle drive. Then telnet/ssh to kindle via usb or wifi to run the following script on your kindle:sh /mnt/us/DK_System/install/install.sh(this is just the installation script of Duokan, which cannot be executed by its update bin file, so you need to do it manually. Now you can ¿reboot¿ your kindle to make it work).

The new version of Handbrake allows you to store vobsub subtitles into the output mp4 file as you rip. This is a very nice touch in that now you no longer have to fire up vobsub separately to rip your subtitles and can convert the whole movie in one rip. Unfortunately, as the Handbrake people mentioned player compatibility with mp4 vobsub subtitles is rather low. To get around this, I needed a way to extract standard vobsub format subtitles from the mp4 file. As usual, mplayer/mencoder was able to take care of it for me.

First, make sure you have a good copy of mplayer/mencoder installed with support for osd and subtitles. This is covered in other posts here, if using macports you’ll need to add custom variants. Homebrew takes care of it by itself.

First open the mp4 in VLC and check the subtitles control to see what languages you have available and what IDs they are. Then, run this command:

mencoder vendetta\ guy.m4v -vobsubout vendettaguy -vobsuboutindex 2 -vobsuboutid en -sid 1 -nosound -ovc copy -o test.avi

in this example -vobsubout provides the name of the .idx/.sub vobsub files you’ll create. -vobsuboutindex is the index in the output vobsub files (if you want to add multiple languages to your output you can repeat this process). the -sid parameter controls which stream you extract from your input file, so enter the number you got from VLC here. Use the -vobsuboutid paramter to control the name of the language in the list. Good luck finding a list of the proper format of these codes, I only know English = en, Chinese (Simplified) = zh and Japanese = ja.

You may additionally need to add the fps if mencoder doesn’t detect it properly. To do this, just add -fps to the command line arg, (try 29.970) or another valid value.

This is a pretty useful trick if you need to get around a corporate firewall or the Great fireWall of China. It still allows PPTP through, setting it up is pretty easy and unlike OpenVPN it’s supported by every major OS without any additional software. You can even use it from your iPhone.

To get it going you need one server or VPS that you have access too. Install pptpd with
sudo apt-get install pptpd
Now to edit some files… I’d suggest giving your machine a static IP address by editing /etc/network/interfaces (be careful, if you are not using the server version of Ubuntu Network Manager will most likely take over and set your machine back to DHCP. I’d recommend disabling Network Manager or trying to set a Static IP through it.

You will first need to figure out what subnet your router is using. The quickest way to do this is just to type ifconfig at the command prompt. Look for the output from

eth0, it should look something like this:
eth0 Link encap:Ethernet HWaddr 00:22:22:22:22:22
inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::240:45ff:fe26:775a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:225008 errors:0 dropped:0 overruns:0 frame:0
TX packets:76464 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:32669088 (32.6 MB) TX bytes:21169594 (21.1 MB)
Interrupt:23 Base address:0xc800

The blue line is the one that you need to pay attention to. To drastically oversimplify, the numbers next to inet addr, are your IP address and the first three represent your subnet. Ok, I’m too lazy to write the rest of this with that much detail. Long story short:

  • set your current IP address with /etc/network/interfaces to a static IP.
  • edit /etc/pptpd.conf and add this:
    localip 192.168.1.101
    remoteip 192.168.1.20-24

    changing the IPs to match your network’s config.
  • Add a line to /etc/ppp/chap-secrets with desired name and password
  • Uncomment and enable the the #net.ipv4.ip_forward=0 line in /etc/sysctl.conf to net.ipv4.ip_forward=1
  • Edit /etc/rc.local and add the following before the exit 0:
    iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    iptables -A FORWARD -i eth0 -o ppp0 -m state --state RELATED,ESTABLISHED -j ACCEPT
    iptables -A FORWARD -i ppp0 -o eth0 -j ACCEPT
  • Execute /etc/init.d/rc.local start to start the IP masquerading
  • Execute sysctl -p to refresh the sysctl.conf settings you changed
  • That should do it.

    References:
    http://www.sharedknowhow.com/2008/09/linux-vpn-server-installation-for-use-with-iphone/
    http://www.ubuntugeek.com/howto-pptp-vpn-server-with-ubuntu-10-04-lucid-lynx.html

My Version
This is the ffmpeg command I use with the copy of ffmpeg I built locally on my mac via MacPorts. Check that your ffmpeg is OK by running
ffmpeg
from the command prompt, it will spit out some information about the various options it was compiled with, should look more or less like this:

FFmpeg version 0.5, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --prefix=/opt/local --disable-vhook --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-avfilter-lavf --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libdirac --enable-libschroedinger --enable-libfaac --enable-libfaad --enable-libxvid --enable-libx264 --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/gcc-4.2 --arch=x86_64

Then use a command like the one below:

ffmpeg -i INPUT.MOV -acodec libfaac -ab 128k -s 640x480 -vcodec libx264 -vpre hq -vpre ipod640 -b 1500k -aspect 4:3 -threads 0 -f ipod output.m4v

Info taken from this site.
Stolen from Azureus

Azureus now has iPhone encoding built in. I was a little curious how it managed the encoding, I had hoped they wrote a Java based video encoder capable of converting anything into iPhone suitable mp4s thereby creating a cross-platform solution that didn’t require compilation, but alas they, like everybody else used the power of open source via ffmpeg.

A little playing with the ps command and I was able to rescue the ffmpeg incantation they use to convert to iPhone. Since they helpfully include a pre-compliled ffmpeg binary with all the necessary libs this is actually almost as good since as many know trying to compile ffmpeg for each platform can be quite a difficult and trying experience.

Anyhow, here’s the code:

/Users/YourUser/Library/Application Support/Vuze/plugins/vuzexcode/ffmpeg -y -threads 2 -i file.avi -f mp4 -s 480x272 -r 23.976 -vcodec libx264 -bf 0 -coder 0 -refs 4 -g 50 -maxrate 8000kbps -bufsize 8000kbit -crf 20 -me_method umh -ar 32000 -ac 1 -ab 128 -acodec libfaac outfile.mp4

This post is about how to hardcode srt format subfiles in a separate file into your videos using mencoder, with a specific emphasis on doing it for Chinese subtitles.

If you want to hardcode vobsub based subtitles, mencoder seems incapable of doing it, the only reliable way I’ve found thus far is to use Handbrake.

Update: VLC is also capable of it if you use it from the command line. It’s tricky tho. Here’s the command that worked for me:
/Applications/VLC.app/Contents/MacOS/VLC -I dummy -v "The Lost bladesman (donny yen).m4v" "vlc://quit" --start-time 225 --stop-time 240 --sout-transcode-soverlay --sub-track=0 --sout='#transcode{vcodec=mp4v,vb=400,scale=.5,acodec=mp4a,ab=96,channels=2}:std{access=file,mux=mp4,dst=lostblades.m4v}'

/Applications/VLC.app/Contents/MacOS/VLC -I dummy -v "The Lost bladesman (donny yen).m4v" "vlc://quit" --sout-transcode-soverlay --sub-track=0 --sout='#transcode{vcodec=mp4v,vb=600,scale=1,acodec=mp4a,ab=96,channels=2}:std{access=file,mux=mp4,dst=lostblades.m4v}'

http://automate-everything.com/lang/en/2009/05/how-to-embed-idx-subtitles-into-an-mp4-or-avi-file-with-mencoder/

Prerequisites:
mplayer installed on your mac via ports with this command:


sudo port install mplayer-devel +aa +mencoder_extras +osd +xvid +x264 +faac

To use Chinese subtitles you must have them encoded in a text encoding mencoder can understand, have a font that can render that text encoding, and then you must tell mencoder to actually use that text encoding. I made this happen with Chinese fonts by using one of Apple’s Chinese fonts, saving my subtitles file as utf8 and telling mencoder to use utf8 when rendering the subtitle. I had to disable fontconfig using the -nofontconfig option befause fontconfig did not seem to be properly supporting unicode (utf8) characters.

Merge Chinese subtitles (utf8 encoded) into the film. This made use of a Chinese font copied into ~/.mplayer/subfont.ttf. To be double sure I also edited ~/.mplayer/config to have font=~/.mplayer/subfont.ttf. The subtitle stream doesn’t actually get hardcoded in unless you specify sid -1 (or whatever ID your subtitle stream is. You can find the subtitle ID by doing mplayer -v on your movie file. You can also just use the -font option as in this example:

mencoder -utf8 -nofontconfig -font /Library/Fonts/Hiragino\ Sans\ GB\ W6.otf -sub Waiting.Alone.2005.DVDScr.XviD.MP3-NewMov.cht.srt -ss 5:00 -endpos 30 -ovc lavc -lavcopts vbitrate=1000 -oac copy Waiting.Alone\[独自等待\].avi -o WaitingAlone.chineseSubs.avi

The -nofontconfig is used so that you can properly specify the Chinese font.

mencoder -utf8 -nofontconfig "Kiss.Kiss-Bang.Bang[2005]DvDrip[Eng]-aXXo.avi" -sub "Kiss.Kiss-Bang.Bang[2005]DvDrip[Eng]-aXXo.srt" -sid 1 -ovc lavc -lavcopts vcodec=ffvhuff -oac copy -ss 5:00 -endpos 30 -o ~/Desktop/test.avi


mencoder /Users/nik/Desktop/torrents/waiting-alone/proper/simple.avi -sub /Users/nik/Desktop/torrents/waiting-alone/proper/simple.srt -sid 1 -subfont 'Helvetica' -subfont-text-scale 3.5 -ovc lavc -lavcopts vcodec=ffvhuff -oac copy -ss 5:00 -endpos 30 -o /Users/nik/Desktop/torrents/waiting-alone/proper/out.avi

Converting to iphone:
reference

mencoder wps-hearme-cd1.avi -ss 30 -endpos 15 -o test.mp4 -vf scale=480:-10,harddup -oac faac -faacopts mpeg=4:object=2:raw:br=128 -of lavf -lavfopts format=mp4 -ovc x264 -x264encopts nocabac:level_idc=30:bframes=0:threads=auto

For whatever reason upgrading to Snow Leopard broke the Fluid webApp I use to monitor my gMail account. (What’s Fluid you ask? Fluid is an application that allows you to make a website into a separate application. Basically, it’s a new browser window, but it gives you a separate icon on your Dock/Start Menu/What have you). I use Fluid with Google Gear’s offline plugin to get the convenience of a standalone email app, but still use the Gmail interface I’m used too and still be guaranteed to have access to all my email anywhere I can find a web browser.

One of the nicest things about using Fluid was that it let me use Google’s Offline Gmail extension (and the Google Gears plugin it requires) separate from my browser. That way I don’t have to clutter up my browser’s profile directory  with all my offline emails (this is important to me since I sync my entire browser profile over Dropbox so that I get the same browsing experience everywhere). Unfortunately, it appears Google’s Gears isn’t quite compatible with Snow Leopard yet, so my offline Gmail functionality is no longer working. Confusingly, Fluid wouldn’t even load the Gmail website, it just hung at a white screen repeatedly.

Until Google updates the Gears plugin to support Snow Leopard, I’m temporarily switching back to Mozilla’s Prism product. Prism is very similar to Fluid (in fact, Prism is what inspired Fluid’s developers to create Fluid), but instead of being based on Apple’s WebKit (and thus highly integrated with OS X) it’s based on the Firefox code. This has the nice advantage that it’s cross platform and that it’s capable of using Firefox add-ons. It turns out only the Gears Safari plugin is broken on Snow Leopard, the Gears firefox add-on still works fine, so Prism has been able to solve all my email woes.

Well, almost all. One nice feature of Fluid is that it automatically shows dock badges on the Gmail dock icon whenever a new email message comes in. With Prism I’m stuck relying on my Gmail Checker Firefox add-on to alert me to new messages. Getting offline Gmail to work in Prism is a bit of a challenge though. I ended up following the directions here:

http://westacular.livejournal.com/43666.html

with some references to the directions here:

http://otaqui.com/blog/382/enable-google-gears-and-offline-gmail-for-mozilla-prism/
Here’s my modified copy of the google-gears xpi, it should work on any version of Prism since I basically just short-circuited the version check. YMMV, I’m not responsible for any computing disasters that may result from using this.

© 2012 Putztastic Tech Suffusion theme by Sayontan Sinha