My Deinterlacing and Post-Processing Scripts

Posted by Keith Gable (ZiggyTheHamster) Wed, 26 Nov 2008 15:05:00 GMT

At work, we put up a lot of Flash video. I use On2 Flix Pro for the Flash encoding part. But I get the content in a variety of formats. Perhaps the most common format we get is 480i MPEG-2 video interleaved. I’m encoding on a Mac, and QuickTime cannot correctly feed the audio stream into Flix Pro because it’s interleaved in the video stream. Also, Flix Pro’s deinterlacer sucks. So, I use mplayer and mencoder to fudge the video around and deinterlace it. It’s working very well. Oh yeah, you’ll need Perian.

Read it after the break.

Wait, how do you get mplayer and mencoder on a Mac? mplayer is included in MPlayer OSX. Show Package Contents, Resources, External_Binaries, mplayer, Show Package Contents, MacOS, and bam, your binary for mplayer is in there. mencoder, on the other hand, is hard to find. I ended up using ffmpegX’s mencoder, which is “MEncoder dev-CVS-060307-04:23-4.0.1”, compared to my mplayer which is “MPlayer dev-SVN-r25648-4.0.1” and way newer.

First, I have to strip the MP3 audio stream and the MPEG-2 video stream, into separate files. I have my video rips folder set up with a “scripts” subfolder and a “work” subfolder. Here is my script to dump both streams:

#!/bin/bash

# Takes $1 and dumps it into two files in work/
./scripts/mplayer "$1" -dumpvideo -dumpfile work/dump.m2v
./scripts/mplayer "$1" -dumpaudio -dumpfile work/dump.mp3

Next, I run cropdetect, which is a stupid script to save me typing:

#!/bin/bash

# Runs crop detect on the stream we dumped.
./scripts/mplayer work/dump.m2v -vf cropdetect -vo null -ao null

Next, I run a deinterlacing and cropping filter. And postprocessing maybe, but I’m not even sure if it works in mplayer like it works in mencoder. I’m sure the latest mencoder can let me combine this step with the next one. But as it stands I need to do this in two steps.

#!/bin/bash

# Takes work/dump.m2v and applies the crop in $1
# and deinterlaces, outputting to work/dump.deint.yuv

./scripts/mplayer work/dump.m2v -vf crop=$1,pp=de,yadif=0 \
    -vo yuv4mpeg:file=work/dump.deint.yuv

Finally, I put both streams together, doing final postprocessing. I also convert it to HuffYUV because QuickTime can play it with Perian. Again, I think the latest mencoder has the yadif deinterlacer, which would let me combine the previous script and current script in one step. BTW - A/V sync gets off if you leave out harddup.

#!/bin/bash

# Takes files in work and compiles them into work/output.avi
# $1 if specified is a list of additional filters to apply.

if [ "x$1" == "x" ]; then
    ./scripts/mencoder work/dump.deint.yuv -noskip -vf harddup,pp=de -ofps 30000/1001 -ovc lavc \
        -lavcopts vcodec=huffyuv:format=422p -audiofile work/dump.mp3 -oac copy -o work/output.avi
else
    ./scripts/mencoder work/dump.deint.yuv -noskip -vf harddup,pp=de,$1 -ofps 30000/1001 -ovc lavc \
        -lavcopts vcodec=huffyuv:format=422p -audiofile work/dump.mp3 -oac copy -o work/output.avi
fi

Also, if you noticed, the previous script lets me specify additional filters on the command line if I want. Usually I have to run hqdn3d, but not always.

Oh, and this will use about 1 GB per minute of content, times two because it’s creating an uncompressed file twice (the final AVI and the intermediate .deint.yuv). Don’t run yourself out of disk space! :)

Comments

Leave a response

Comments