neděle 8. března 2009

... the right tool for the right job

I needed to embed a logo image and a short static text into video. I needed to do it as a batch job. It took some time to find the right tool. Finally I have one.

Avisynth is the right tool. One drawback - windows only. But this will change in near future.

A short avisynth script does the job. Avisynth composes the video stream (raw)frame after frame acting as a frame server. The result can be fed into several encoders e.g. VirtualDub (great for debugging the script), mencoder (good for encoding final video into any format you may want).

Sample script - script.avs
video=DirectShowSource("input-video.avi")
logo=ImageReader("logo.png")
logoMask=ImageReader("logo.png",pixel_type="RGB32").ShowAlpha(pixel_type="RGB32")
Overlay(video,logo,x=20, y=20, mask=logoMask).Subtitle("text text text", 640,480, align=3)


Encoding - H.264 in MP4 container encoded using constant quality (variable bitrate)
mencoder -ovc x264 -nosound -x264encopts \
qp=24:keyint=25 -of lavf -lavfopts format=mp4 -o out.mp4 script.avs