gekk.info « articles

Capturing/scaling retro video

This is just a scratchpad for some useful FFmpeg recipes etc. that I use when dealing with old video from tapes, videogames, etc.

Re-Deinterlacing Deinterlaced Video

If you're showing interlaced video to someone who isn't a nerd, they want you to bob deinterlace it. This isn't in dispute, nobody wants to look at comb artifacts when they're just watching something for fun.

The problem is that if someone has "none deinterlaced" a video - e.g. they used a deinterlacer that just combines the odd and even fields into frames, dropping the FPS from 60>30 or 50>25 - it's infuriatingly hard to get any program to acknowledge this. ffmpeg, avidemux, virtualdub; all of them just shrug and go "idk bro it's already progressive."

What you WANT is the following chain: 30p > 60i > bob > 60p

It is incredibly hard to make this happen. I figured out how to do it with avisynth. I don't know if this works on linux or macos.

AVS file:
DirectShowSource("D:\Video\sprite tapes 1.avi", 30)
ConvertToPlanarRGB()
yadifmod2(order=-1, field=-1, mode=1)

I recommend leaving it on defaults, which will get you an enormous uncompressed file. Then put it through ffmpeg to scale it up and compress it:

ffmpeg -i INPUT.AVI -vf "scale=1440x1080:flags=lanczos" "OUTPUT.MP4"

Capturing from DOSbox

The best way to capture from DOSbox is to use the built-in video recorder - it seems to do a nearly perfect job, and getting the audio from the game even when you have it muted so you don't have to listen to hours of machine gun noises is a great feature.

DOSbox video recording starts/stops with Ctrl+Alt+F5. The codec is ZMBV, which you'll need a codec for (it's readily available On Line, will upload it here at some future date.) ZMBV movies will not RELIABLY play correctly in any player that I've tried - VLC for instance does not seem to decode the palette correctly, but FFmpeg will correctly transcode the video.

If you're transcoding to mp4, you really want to scale while doing it, or it's going to trash your video no matter what quality it is - x264 just will not work with 320x200 video. Pushing to 1280x800 (4x scale) works great for me, it looks good in a 4k video at fullscreen.

The FFmpeg for this is simple:

ffmpeg -i "FILENAME.AVI" -vf "scale=1280x800:flags=neighbor" "OUTPUT.MP4"

I use a batch file for this purpose, which looks like this:

for %%f in (./*.avi) do @ffmpeg -i "%%f" -threads 16 -vf "scale=1280x800:flags=neighbor" "output\%%~nf.mp4"

This transcodes all .avi files in the current folder into a folder called "output". I copy the files from the dosbox capture folder, run this script, let it complete, then drag all the .avi's to a "finished" subfolder so they don't get processed again.

Converting 60i captured video / DV

If converting from DV, or other 60i video, I absolutely hate all forms of deinterlacing other than bob / yadif. It is surprisingly hard to get the weenies on video forums to cough up the recipe for this, because they all think it's a violation of the sanctity of life or something.

Here's my FFmpeg command:

ffmpeg -i INPUT.DV -vf "yadif=1,scale=1440x1080:flags=lanczos" "OUTPUT.MP4"

The "yadif=1" is critical; I believe yadif=0 results in a """"""more correct"""""" downconvert to 30p, while yadif=1 produces the 60p output that everyone actually wants. 1440x1080 isn't always the exact right resolution to use, but practically speaking it's probably going to look fine for e.g. youtube purposes - it's the 4:3 equivalent of 1080, of course. And lanczos just looks best to my eyes.

And here's the batch:

for %%f in (./*.avi) do @ffmpeg -i "%%f" -vf "yadif=1,scale=1440x1080:flags=lanczos" "output\%%~nf.mp4"

Converting to DV

Converting from DV to other formats is straightforward, but it took me many hours the first time I tried to convert TO DV, in order to make a file I could play into a Firewire DV interface to e.g. record onto a tape. Most modern software does not support DV format output, support for interlacing is rare and finicky, and ffmpeg requires specific input settings.

If your input is already in the right format, that is, 720x480 29.97i, use this recipe to convert it:

ffmpeg -i input.mov -pix_fmt yuv411p output.dv

The critical part is obviouisly the pix_fmt - I believe if you're producing PAL DV you can just feed ffmpeg whatever and it'll just work, but for NTSC it will not coerce on it's own, so you have to tell it to use 4:1:1. Remember to put the -pix_fmt AFTER the input, otherwise it'll try to use it in the wrong order.

I haven't tested PAL yet so you're on your own for that.

If you need to generate input in the right format, I've been using Davinci Resolve, and I believe you can do this even in the free version.

Remember when authoring the video that you will be dealing with overscan!


If this was interesting to you, or if you did something interesting with it, email me: articles@gekk.info

If you like my work, consider tossing me a few bucks. It takes a lot of effort and payment helps me stay motivated.

List of Articles