Log in

View Full Version : Archiving VHS, de-interlace, lossless x264


batfastad
20th January 2015, 01:28
Hi everyone

I've unearthed a box of old family videos on VHS tape that I'd like to preserve while I still have a video player that works. Some of these were originally recorded by camcorders on Hi8 or VHS, others were converted a long time ago from various old cinefilm formats.
I have a USB video capture box which I used to use for live web streaming http://blitzcast.com/b1-3/ from a Sony camcorder at events. It was designed for games console streaming but I found it works really well as an all-round capture device.

Normally when archiving audio I capture in the best quality possible then transcode/downsample to a current format for actual practical playback. I'd like to do the same with video, storing it as a "lossless" video file (or as close to as possible) then I'll probably convert to DVD for actual playback for the time being.

Brief digging around and it looks like my lossless capture format options are:
* HuffYUV
* x264 "crf 0"
* MJPEG

It looks like VirtualDub is still a good tool for the job of capturing as well. I've followed this excellent guide for a workflow of setting up VirtualDub for capturing... http://www.doom9.org/index.html?/capture/start.html

I started looking into x264 for capturing. I'd never heard of HuffYUV and found this http://stackoverflow.com/questions/26346810/how-to-use-x264-encoder-with-directshow which suggested using x264vfw as a frontend which exposes x264 within VirtualDub.

These are all PAL VHS tapes so I was running test captures at 720x576 YUY2 and a framerate of 25.0000.

A raw .avi rip from VirtualDub which came in at 5.5GB for 4min of video, with the CPU hardly blinking.

Then a compressed one through x264 with the lossless setting in x264vfw came in at 985MB.
But this hit the 4 cores in my laptop up to about 85% throughout (CPU i5-4210M). The VirtualDub overlay was very choppy but the stats window reported no dropped frames so I thought I might be ok. On playback it's not choppy like the VirtualDub preview, though in a side-by-side against the raw .avi capture, it is very slightly off in places.

So I don't think my laptop has enough grunt to be able to capture in x264 lossless in real-time. But I also won't have enough disk space to capture in raw .avi and transcode later. I read somewhere that HuffYUV is typically alot less taxing on CPU and has a similar file size saving to x264 lossless. So it might be that I capture in HuffYUV and then transcode to x264 afterwards. I need to experiment with HuffYUV more.

I did a test transcode using ffmpeg from the linux command line to take my raw .avi to x264 lossless.
This is my command: ffmpeg -i testcapture.avi -c:v libx264 -crf 0 -preset slow -c:a aac -b:a 192k -ac 2 -strict -2 testcapture_x264_c0_slow.mp4
File size down to 1.8GB for 4m 30s of video, which is just about acceptable for my archiving. The encoding took about 7min with CPU maxed throughout, so really there was no way I was going to be able to do this in real-time during the 4m 30s of video.
I tried -preset veryslow but that took about 15mins so it's probably not worth the extra time needed for any improvement in encoding quality there might be. I couldn't see any difference.
Playback, no minor stutters like the real-time encoding. Looks identical to me when comparing the raw avi. So x264 lossless for archiving seems like a great option based on quality/file size.

I should say that I'm not bothered about cleaning up the source at this stage, cropping black bars and removing any VHS blips/noise etc. I want to capture what's coming out of the VHS player, and if there's noise/blips then that's part of the video as much as the rest of it IMO.

ffmpeg printed out the specs of my raw capture at the start of the encoding log...
Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 720x576, 25 tbr, 25 tbn, 25 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s

The x264 output from ffmpeg...
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv422p, 720x576, q=-1--1, 12800 tbn, 25 tbc
Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 192 kb/s

My questions...
1) De-interlacing. When playing back my raw avi capture I can see horizontal lines in areas of motion similar to this http://www.doom9.org/capture/images/interlaced.jpg So the video is probably interlaced and I should de-interlace.
Would it make sense that my PAL VHS tapes (non-broadcast) are interlaced? Or is interlacing something that's only used in broadcast etc?
Since I'm planning on keeping an x264 file and probably authoring DVDs for relatives, it's not like I would ever need to re-interlace in the future?

2) Is my ffmpeg command above appropriate for taking my raw .avi down to x264 lossless? Are there any further options for the video that I need?

3) Would a higher -crf value reduce file size without much of a loss in quality?

4) Does this input stream info from ffmpeg look right for a PAL VHS capture... yuyv422, 720x576, 25 tbr/tbn/tbc?

5) The output stream info from ffmpeg is now yuv422p instead of yuyv422. Does that look right?

6) The added "p" there, does that mean my source was interlaced and the output is now progressive, and x264 has auto de-interlaced or something?

7) I've seen a few small mentions of x264 only supporting 4:2:0 (whatever that means). Is that going to be a problem for my workflow above?
Should I be worried about the 422 in the source and output from ffmpeg?

8) Anyone have any good info about capturing with HuffYUV in VirtualDub then converting from HuffYUV to x264 in ffmpeg?

I should also say that I'm capturing in Windows 7 because the drivers for the capture box are installed, then running ffmpeg under Linux (Xubuntu) which is my primary desktop OS. I should probably try using the capture box under Linux to see what happens but at the moment I'd just like to make sure my workflow is ok.

I hope all of that makes sense. Video encoding stuff is always something I look at for a project once every few years then immediately forget and end up having to re-learn.

Cheers, B

foxyshadis
20th January 2015, 14:10
Instead of HuffYUV, you might use utvideo or magicYUV, which both compress a little better, since you have tons of CPU to spare. Alternately, play with the x264 presets, they range down to realtime and ultrafast, which should be plenty fast enough for you but rather larger. You might even be able to get away with fast or medium, try it out.

Everything x264 is yuv4xxp, because MPEG is always planar. Deon't worry about that, yuv422p and yuyv422 are just two ways of storing the same data. p just means luma and chroma are stored separately (planar), instead of mixed together.

You'll always end up converting down to 4:2:0 for DVD, and any distribution you do should also be in this format. Wiki has more info than you ever wanted to know (https://en.wikipedia.org/wiki/Chroma_subsampling), but basically it's just half the resolution for the color parts -- but VHS already has such low resolution color that it makes no difference.

How you treat the chroma depends on the output: If you're going straight to DVD, don't deinterlace at all, just convert to 4:2:0 interlaced and encode to DVD, unless you have a 3:2 pattern that can be IVTC'd. DVDs are naturally interlaced. If you're going to be distributing online or digitally in general, you'll need to deinterlace, and that can be done quickly and cheaply, or very long and painstakingly; the Avisynth forum has tons of information on this. Even Virtualdub can do it, though the quality is really bad.

Lastly, higher crfs do help a ton with size without seriously affecting quality. You can go up to 10 or 12 and still never notice that it isn't lossless.

batfastad
21st January 2015, 01:33
Excellent info - thanks for that! I know there's thousands of threads on here covering variations of this stuff
Yeah I briefly looked at that colour stuff a few days ago and it's just not sticking :p I think I'll just pretend it doesn't exist for now. From what you've said it sounds like it's not too much of an issue for VHS captures at this stage.

In terms of the capture format, I'll look into those. But it really depends on how easy it is to get each one into x264.
Since I'll probably be capturing in something that's not x264 (for reasons of x264 CPU usage), it doesn't really matter how long the x264 encode takes as I'll be doing that as a separate process after capture.

I'll then keep a decent x264 file somewhere, -preset slow and -crf 0 seemed ok but I had a look at changing -crf as you suggested and was impressed with the difference in file size...
-crf 8 = 990MB
-crf 10 = 805MB
-crf 12 = 629MB
I reckon I'll definitely go with one of those, the output looks perfect to me. Fine for these grainy old VHS tapes!

What tools do I need to convert HuffYUV etc into x264?

The archived file I may as well keep interlaced then. That's always a process I can do later if my final output format requires de-interlacing.

Initially I'll output onto DVD. Is there an up to date workflow for that anywhere?
Doesn't look like this has been updated since 2004 http://www.doom9.org/index.html?/capture/encoding_authoring.html
Just want to check those are still the best tools to use.

AviSynth for the colour conversion to 4:2:0 then passed into an MPEG-2 encoder for DVD?
Or can should/an encoder handle the colour conversion?

Cheers, B

manolito
21st January 2015, 08:39
Yes, this Doom9 guide for authoring to DVD is terribly outdated.

If you want an easy to use and high quality all-in-one solution, have a look at AVStoDVD. Uses HCenc (or ffmpeg) for encoding, AviSynth for frame serving and IMGBurn. Easy to use, but also customizeable for special needs.


Cheers
manolito

batfastad
21st January 2015, 17:15
Nice one, AVSTODVD looks perfect! Great guide here http://forum.videohelp.com/threads/353284-AVStoDVD-beginners-guide-Any-video-to-DVD-Video

I have also just discovered the wonders of ffmpeg -target pal-dvd which should accept my x264 mp4... http://docs.salixos.org/wiki/How_to_create_a_video_DVD_from_the_command_line

Time for some experiments!

Thanks for all your help
Cheers, B

mäger
23rd October 2015, 19:16
i found an old video i also tried to capture via the usb device once... it is somekind of yuy2 avi file (640x480) and 2:11 minutes is 1.89GB in size...
so i used megui on it - and it created a 32.2MB file from it, and also removed the partial interlace on it (which it detected with the analyze button)
(it doesnt have any audio for some reason tho, even the raw file)