Sunday, December 26, 2010

Merging and encrypting PDF with Ghostscript

Recently I needed to merge several PDF files into a single file and also encrypt it. So after some googling, here my recipe:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOwnerPassword=password1 -sUserPassword=password2 -dKeyLength=128 -dEncryptionR=3 -sOutputFile=output.pdf input1.pdf input2.pdf input3.pdf


Wednesday, December 1, 2010

Other Utility Mill scipts

I have made several utility mill scripts in the past and since I am reminded of it again, I might as well post links to my other utilities. Hopefully, someone will find it useful:

srt_delay: subtitle timing delay adjustment

I suppose SRT file timing offset is a common problem, however I can't seems to find any simple good tool that works on both Linux and Windows. While most media player on PC should be able to adjust the delays, my TV set-top box could open SRT files but could not adjust timing delays in the subtitle which could be annoying.

So, I decided to roll up my sleeves and wrote the little utility python script in a few minutes. Besides, how difficult could a simple format like this http://en.wikipedia.org/wiki/SubRip?

You can download the script from pastie.org:
http://pastie.org/1339071
I've released it as free and public domain. Anyone can use it to do anything you like.

Anyway, for Windows folks, I have also made and online version by porting it to excellent python script hosting called Utility Mill.
Just go to http://utilitymill.com/utility/srt_delay and follow the instructions.

Wednesday, February 24, 2010

Bilingual VCD to DVD

Recently my mum wanted to replace her stack of VCDs to DVD. The VCDs are bilingual which is one language on each of the stereo channel.
Since DVD supports VCD's MPEG 1 PAL (352x288) format as described in the mencoder manual , I thought I could just easily copy the video stream and transcode the audio stream to AC3 with the following mencoder recipe:

mencoder -ovc copy -oac lavc -lavcopts acodec=ac3:abitrate=192 -srate 48000 -af lavcresample=48000 -of mpeg -mpegopts format=dvd:tsaf AVSEQ01.DAT -o AVSEQ01.mpg

However, after burning the first disc with DVDStyler, I found that my Phillips DVD player does not allow switching between left and right channel for DVDs although language switching works fine with the original VCD. Thus, I have to split the single track stereo channel into two separate mono audio channel. After some experimenting with mencoder's audio filter, here's the recipe:

mencoder -nosound -ovc copy -of mpeg -mpegopts format=dvd:tsaf AVSEQ01.DAT -o video.mpg

mencoder -srate 48000 -af channels=1:1:0:0,lavcresample=48000 -ovc frameno -oac lavc -lavcopts acodec=ac3:abitrate=96 -of rawaudio AVSEQ01.DAT -o audio1.ac3

mencoder -srate 48000 -af channels=1:1:1:0,lavcresample=48000 -ovc frameno -oac lavc -lavcopts acodec=ac3:abitrate=96 -of rawaudio AVSEQ01.DAT -o audio2.ac3

Now, instead of single mpg file, we have 3 separate streams. To make the DVD menus, multiplex the streams and generate the ISO image to burn, I found DVDStyler (also available in ubuntu repo) to be useful because I found that most DVD authoring tools seems to insist on re-encoding the video files to MPEG-2. Although default DVDStyler also tries to re-encode them, it has an option to just copy the stream as shown below in the title properties dialog.


With this method, I could combine 6-9 VCDs into a DVD. Of course, the video quality is just as good as its source which is relatively poor for a DVD. Finally, audio track switching works fine on the standalone DVD player and also on PC.

Thursday, January 28, 2010

Transcoding video to H.264 for Nokia 5130

My wife is going to take a rather long journey bus this weekend. So, I decided to transcode some videos for her to watch on her phone.

Here's the recipe:

ffmpeg -y -i inputFile.avi -f mp4 -vcodec libx264 -level 30 -s 240x128 -b 200k -bt 768k -bufsize 10000k -maxrate 10000k -g 300 -coder 0 -threads 4 -acodec libfaac -ac 2 -ab 96k outputFile.mp4

This is mostly based on the instructions from the videohelp.com forum.

I have tried 320x240 resolutions, but I decided to scale it down a little to save space since it does not look any worse at 240x128.