Nakor’s Rucksack

Random Thoughts From a Madman

Skip to: Content | Sidebar | Footer

My HDTV Workflow

19 April, 2009 (13:26) | Geek Talk

This is a description of the steps I use to prepare recorded HDTV (using mythTV and HDHomeRun) for viewing. The end product is a HD resolution, commercial-free video file suitable for streaming by the Sony Playstation 3. Stripping commercials is important, as the PS3 has rather poor playback controls for streamed video. Generally these video files are deleted once viewed; however, I’ve included the additional steps that I take for some choice programs which are re-sized to 720p and re-encoded with H.264 for archiving. I generally follow this procedure once a week; although it takes a few hours to complete, most of the time is “non-interactive”, and is spent waiting for file copies to complete or various programs to run. Thus it generally doesn’t take much “hands-on” time at all to complete.

Step 1: Copy Files.

First I copy the raw MPEG-2 files from the mythTV server to my work machine. The mythTV server is an old PowerPC G4 and unsuitable for any video work or even HD playback. An additional hurdle is that the software I use is Windows-specific. A week’s worth of captured raw video comes to about 60GB, and takes over an hour to copy over 100Mbs ethernet at 10-11MBs. I now see the value in Gbit ethernet, but I’m sure the mythTV server does not support it, and I would also need to invest in new routers/hubs.

Step 2: Detect Commercials.

For this task, I use the excellent program comskip. Since comskip is not multi-threaded and I perform this action on a dual-core machine, I split the files into two directories, and I run comskip on them concurrently. Comskip generates a VideoRedo project file for each video with the commercials marked as cuts. However, these cuts generally require a few manual tweaks.

Step 2b: Edit Project Files.

For some reason, comskip does not properly recognize the audio in video recorded from one of the channels. At this point, I open those project files (which appear to be XML-like in structure) with jEdit and manually set the correct audio track. This is a trivial but important step. Otherwise, saved video from these project files will not have audio. It took me a while to figure this out, but once I did, it takes about 10 seconds to perform the edits.

Step 3: Edit Video.

For this step, I open each project file in VideoRedo (which is a superb, affordable editing program that I highly recommend) and adjust the cut points made by comskip. Many times, no edits are actually needed. When edits are required, they are generally to move the cut points a few frames one direction or another. I then use the preview function to make sure the transitions are smooth. This is the most labor intensive step, but I think each video requires at most a couple minutes of work; most require less.

Step 4: Save Video.

If a given video is not to be archived, then I save the video in a VOB format. The PS3 does not like the large MPG files generated by VideoRedo for some reason. If the file is to be archived, I save as MPG – this file will be transcoded later on before viewing.

Step 5: Copy Files.

In this step, I simply copy the edited files not destined for archiving back to the mythTV server for later streaming to the PS3. This step doesn’t take quite as long as Step 1, but it’s still an hour process. They will be deleted after viewing. If there are files to be transcoded, then I proceed to Step 6.

Step 6: Transcoding.

(NOTE: I have only followed these steps for 1080i video files. I imagine the procedure for 720p files would be similar, and would be perhaps faster since no resize would be necessary. If FOX or ABC ever puts on a show worth keeping, I’ll give it a shot.)

For transcoding to H.264, I use MeGUI. This is a suite of tools that includes x264 and avisynth. It requires a bit of knowledge to use, but it is very flexible. Although it includes an avisynth script generator, it is still very helpful to know how avisynth works. I will not go into that here, mostly because I do not feel qualified to teach it. Suffice it to say that in essence, avisynth takes a frame of video, performs transformations on it, and passes it on a the actual video encoder, in this case x264. x264 is multi-threaded, so it takes full advantage of all available processor cores.

Avisynth does not decode MPEG-2 directly; you must create a d2v index file by running DGIndex on the MPG file. This has the side effect of stripping the file of audio; avisynth doesn’t deal with audio, so you have to re-mux the video and audio once the encode is complete. Fortunately this is easy, and it retains the original broadcast digital audio track (including surround, if the audio was originally broadcast as 5.1 Digital Dolby).

My current avisynth script performs detelecine/decimate (converting broadcast 29.976i fps back to the original film rate of 23.976p fps). This has the benefit of deinterlacing, which eliminates “combing” which can occur when viewing interlaced material on a progressive display. I resize to 1280×720, and perform a sharpen (spline64). I use the PS3 preset for x264, but I set the bitrate to 5000kbs. I could probably get away with using less, but space is cheap.

The actual video encoding takes hours; on my main PC (Intel Core 2 Duo E6400), an encode of a 42 minute video file (originally at 1080i) takes over 6 hours. The result, however, is impressive; a 6GB file is magically transformed into a 1.5GB file with virtually no loss of perceived quality. Granted, this file is a much lower resolution than the original (720p vs. 1080i), but I have been unable to tell the difference when viewed on my 46″ HDTV. It looks much better than any DVD ever could.

Step 7: Re-Muxing.

At the end of the encode step, you have a pure video file (.264) and a pure audio file (.ac3). Now you need to re-mux (“glue”) them together in a format the PS3 can play. First, I run a tool called h.264Info on the .264 and set the “Level” to 4.1. I honestly do not know if this step is required or not; I read somewhere that it was. Presumably the .264 is already encoded to level 4.1 as per the x264 PS3 preset. But, it doesn’t seem to cause any harm, and it only takes a minute or so to run.

Next I load the .264 file (processed by h.264Info) and the .ac3 file into tsMuxer. I select .m2ts as the file type, and hit start. This also only takes a minute or so, and you are left with a .m2ts file which the PS3 will play nicely! I usually rename this to .mpg – technically, .m2ts is a mpeg format, and supposedly the PS3 is “more compatible” with .mpg files. Either way it seems to work, so I use .mpg because it is a more commonly recognized extension.

It does takes some work, but the result is commercial-free HDTV when *I* want to view it. Not only that, but the transcoded, archived files are higher quality than any DVD boxset and are completely free for just a few minutes of actual work.

Write a comment

You need to login to post comments!