Just an mpeg2enc script
6, Jan, 2009I’ve never had 100% compatibility using ffmpeg to convert our files to mpeg2. From years of past dvd authoring I’ve amassed quite a few different STBs to test on. They run the gammit from utterly cheap (Apex), commidity (Philips) and higher-end (Panasonic). Nothing is high-end - can’t afford it. Just your basic $30 Walmart special, to pretty good Best Buy $200 model.
ffmpeg authored streams always seem to produce some oditity on a couple of players. Seems to be incorrect GOPs or VBV buffer problems- you get a funky speed up then slow down problem, or not adhering to specified bitrates. I’ve had ffmpeg undershoot the bitrate, which really is not an issue. But when it overshoots, this is a problem. You’ll either run out of space, or the stream will excede the max bitrate according to spec.
mpeg2enc from the mjpegtools project is not the highest quality, nor the fastest encoder around. Both ffmpeg and mencoder run circles around it in speed. Anything on a Microsoft platform puts it to shame (CCE, HCenc, TMPGenc, ProCoder …). Mpeg2enc is FLOSS, Linux native, 100% spec compliant, and can be made to produce streams that rival the commercial offerings, just can’t help the speed.
You can not feed mpeg2enc just any old file. Mjpegtools only works with a few formats. Mjpeg (of course ;) ) DV, and yuv4mpeg. The easiest way to feed mpeg2enc a stream is to pipe it through ffmpeg.
ffmpeg -i file.blah -f yuv4mpegpipe - | mpeg2enc $OPTIONS
That’s not good enough for my projects though. Seems like I’m always authoring something shot from HI-8, an old out of print VHS, or {shudder} someone’s home movie shot on a VHS-C camcorder. Here’s where I have two great choices. I can either filter with mencoder, or use one of the many filters included with mjpegtools. Tough decision.
Mencoder’s filters have an advatage of speed, options, and filter choices. Mjpegtools’ filters IMO are more powerful and higher quality at the expense of speed. The choice is weighed by quality vs. speed. Trust me, the speed factor is huge. With mencoder and slight filtering, on one of our machines we see ~35 FPS, with mjpegtools’ yuvdenoise and slight filtering we see ~10 FPS. It all depends on the amount of grain, and anomalies that are present in the source material. Mencoder does fine on slight noise and grain before too much degradation is seen. Mjpegtools’ filters work wonders on those items you thought were lost forever.
Here’s the simple way to use mjpegtools’ filters and mpeg2enc. Once again using ffmpeg to pipe out.
ffmpeg -i file.blah -f yuv4mpegpipe - | y4mstabilizer $OPTIONS | \ yuvmedianfilter $OPTIONS | mpeg2enc $OPTIONS
Using mencoder is a bit more involved. You need to make a fifo, output mencoder to that fifo, then feed the fifo to mpeg2enc. If you wanted to, you can even add in a few of mjpegtools filters to chain.
mkfifo video.yuv mplayer -noconsolecontrols -benchmark -nosound -noframedrop -noautosub -vo \ yuv4mpeg:file=video.yuv -vf $OPTIONS inputfile.blah \ & cat video.yuv | mpeg2enc $OPTIONS
Here’s a complete command line I recently used for a somewhat clean capture. As you can see the command line options can get quite long after all the variables are defined.
mplayer -noconsolecontrols -benchmark -nosound -noframedrop -noautosub \ -vo yuv4mpeg:file=video.yuv \ cap.hdv -vf crop=1456:::,scale=720:-2:0:0:0.00:0.75:ntsc:0:0,fspp=5::6::,\ unsharp=l3x3:1.20:c3x3:0.50,expand=720:480 & cat video.yuv | \ mpeg2enc -f 8 -p -F 1 -a 3 -q 3 -b 6750 -H -D 10 -g 3 -G 12 -4 2 -2 1 \ -R 2 -M 6 -v 0 -r 32 -o cap.m2v
- Posted by disturbed1 in in Scripts
- Add a comment