mailto: blog -at- heyrick -dot- eu
A big disc is essential
I will, in a moment, walk you through the process of transcoding Demons episode 1.06. One thing you will need to be aware of is that you will be quite liberal with disc space. For example, I have just transcoded the film Ignition that I recorded a couple of days ago:
These are for the options and settings that I use. If you want to use a higher quality transcode or a larger image size, your MJPEG files may exceed 4Gb which means you will need to perform these actions on an NTFS-formatted disc; having said that, if your disc is large (and I would recommend upwards of 80Gb for your video files - I have a 230Gb drive and it is about half-full of video-in-progress files), then you'd be mad to be using FAT...
- Source MP4 files:
391Mb / 390Mb
- Transcoded intermediate MJPEG files:
3.27Gb / 3.27Gb
- Intermediate XviD files:
250Mb / 254Mb
- Final XviD file:
- Total consumption:
All of these products are free (in cost; mostly GPL); download and install.
Indispensible! If you can, try to get the earlier v1.5.4 version as the interface is less cluttered than more capable later versions. If you need more facilities... upgrade! ☺
- XviD codec
A DivX-compatible MPEG4 compression system that, to me, gives more pleasing results; with a powerful options/setup box that isn't packed out with visual 'fluff'.
- Pazera MP4 to AVI convertor
The tool to convert the MP4 files into something more acceptable to VirtualDub, and the rest of the wired world!
- You may also benefit from a codec pack. Google, for there are many.
My codec pack of choice is the K-Lite Codec Pack.
If your codec pack contains XviD, install this before you install the latest XviD codec.
Transcoding, step 1
While there is some software that will permit MP4 video to be watched, for example Nero Showtime (if you purchase the MPEG4 thingy) or the basic MPlayer; you may find that there the most useful and flexible video editor (VirtualDub) does not understand MP4.
For this reason, the first step is to transcode the MP4 into a version of AVI which may be used in the editing stage. It is important to bear in mind that AVI is not a specific format, it is a "container" for a variety of different video formats. The codec, the video format, that we shall be using is MotionJPEG (or MJPEG). This is because it is quick to decode. My computer, running a 450MHz CPU, takes a noticable length of time when working directly with XviD compressed video. By using MJPEG, we can jump around the video file as necessary for the removal of advertising and such, and the results appear on-screen instantly.
The first step, once the file has been copied to your work folder, is to fire up Pazera MP4 to AVI convertor to perform the initial transcode.
You can see from this that I have chosen the options:
The choice of video rate should be entered into the drop-down list manually as the provided options only go up to 2000kbit/sec.
- Video: MotionJPEG, 6400kbit/sec. Frame rate auto (will be 30fps).
- Audio: 16 bit PCM, sampling rate/channels auto (will be 44100Hz stereo).
To justify these choices, the MJPEG is a fairly high bitrate to reduce the degree of additional artefacts in the image. Using raw video data would mean the transcode is invisible, however it consumes a shocking amount of disc space. MJPEG at this quality is a trade-off between quality and size.
For this reason, additionally, we convert the source AAC audio into raw PCM audio. We could make it an MP3, however it is easier to do that at the end and using PCM now means there will be less risk of loss due to too many encode-decode-encode type cycles.
Sit back, let it get on with it. On a ~1GHz system, it will convert slightly faster than real-time.
Transcoding, step 2
Once the video is in a friendlier format, we fire up VirtualDub and load the AVI file.
Once we have the video loaded into VirtualDub, it is time to check the frame rate. If all goes well, the frame rate for a PAL recording will be 29.989fps. If it is anything else, this implies that the audio and video tracks are of slightly different lengths.
This is available under the Video menu:
If the frame rate is not 29.989, you should force it as shown here:
Set the desired frame rate to 29.989 and set the convert to rate to 29.9890.
If you would prefer to try converting your video back to the PAL refresh rate, then you should instead set the conversion to 25.0000fps. The reason that I am sticking with ~30fps (for the moment) is that I believe sampling a 25fps input at 30fps will introduce problems (motion jitter, that sort of thing) and I'm not entirely convinced that converting this 30fps version back to 25fps won't only serve to introduce even more problems. For you? Play around with some short snippets (especially with panning and vertical movement) and try it both on your computer and your DVD player - see what you prefer.
In order to play video in VirtualDub... the leftmost bottom is Stop. The next button, Play-with-I, is the one you will want most, it plays the input video in the left panel (but will include audio skew correction). The next button, Play-with-O will play the output video in the right panel, for example if you have altered the contrast or scaling, etc, it will show how the result looks.
You may find that the audio is slightly out of sync, but constantly so - say half a second (perhaps) throughout the course of the programme. If this is the case, the audio interleaving (under the Audio menu) will allow you to correct for this.
The skew correction (bottom half) is where we can fix problems. The time is measured in milliseconds, so 1000 (as shown here) will delay the audio by one second, and -1000 will advance it a second.
It is best to look for a distinctive sound, such as a splash or a door slam, and with the audio skew at zero, count seconds in your head from the action to the audio (or vice versa, as applicable). Then enter this value (7000 = 7 secs, etc) into the skew, and replay so you can fine-tune it. Then look for somebody speaking and tweak the skew until it is correctly synchronised.
You may find the sync is good for, say, half the programme and then (usually following an advert break) it all goes wrong. I don't know why this happens, if it is a problem with the PVR or something odd in the source video (broadcaster? satellite receiver?).
To work around this, you will need to 'select' the good part and save it as one job, then select the remaining part (after correcting the audio skew) and then save it as another job, then glue the pieces together. I will cover this at the end.
Once the sound is in place, we can work on removing the head and tail for it is unusual to have a recording begin and end at exactly the right place, especially if it is a timed recording. There is a time bar along the bottom. Move this to the start of where you want to edit, using the Cursor Left and Cursor Right keys to step to the exact start frame. Then press the rightmost, but one, button as shown:
Pictures from Demons
You have just set the start position of a selected region. Now move to the end frame (inclusive) and click the rightmost button to set the end position:
Now press Delete. Bang! It's gone.
Pictures from Demons
Repeat this process in order to remove all of the advertising (you will see the selected region in blue), for really you don't want to waste space (and time) knowing there's a DFS winter sale and that GoCompare can save you money and how Cow&Gate preparation is the same as giving your little brat 20 litres of milk a day, not to mention the ongoing saga with those Tesco and ASDA adverts about who is cheaper - I kinda figure there is worth in the maxim you get what you pay for...
|Cow&Gate advert, ITV1.|
Advertising may help keep our channels with money, especially the more niche channels, but it isn't necessary in an archival recording.
If your computer isn't terribly fast, set the Options Drop frames when behind and Enable DirectDraw acceleration; these will often speed things up a fair bit. Leave the other options alone until you know what they are for.
Now go to the Video menu and click on Compression, then in the window that appears, choose XviD:
You can choose DivX if you wish. I prefer XviD because the codec interface is more useful, plus the end results seem, to me, to be better than DivX.
I have two DivX-capable pieces of equipment, my Zen (not certified) and my DVD player (DivX certified) and both play back XviD without problems. Furthermore, the PVR is capable of XviD playback (shame it can't record that way).
Now click the Configure button to set up the codec:
The value you enter in the target bitrate will have the greatest impact on quality. I aim for lower values such as 480-550 for stuff that I want a copy of but am not looking for great quality, while things I am more interested in receive values from 640 to 920. I find a combination of my PVR and about 660kbit/sec is not as good as a DVD but better than a videotape, so that is my most common option.
If you are intending to burn your video file on to a CD-R, you can use the Calc button to work out from the length what sort of bitrate you will need in order to get the file to fit nicely.
If you see something about quantizers, like that shown below, simply click the Target quantizer button to switch to bitrate mode.
Next, if your input video is 16:9 anamorphic (in other words, if your set top box is set to 16:9 widescreen mode), click on the more... button opposite "Profile @ level" at the top. Then click the Aspect Ratio tab, and select 16:9 as shown:
With respect to the warning, both Windows Media Player 9 and my DVD player display anamorphic content correctly. The PVR does not, but I suspect this is because the aspect options are not implemented.
Why is this important? Well, firstly you have extra vertical resolution which can lead to a better quality image. Secondly, this is future-proofing your recordings. For if you have a 4:3 television, your DVD player can letterbox the video file for you. If you later purchase a widescreen TV, your DVD player can then output the anamorphic video directly and it will look as best it can on your TV.
If, on the other hand, you record a widescreen film letterboxed into a 4:3 picture, it won't look any different on a 4:3 television than it did originally. What about when you want to watch it on a widescreen TV? It will still be a 4:3 image with a letterboxed widescreen picture within and there several different ways this can be handled (centred as a 4:3 image, centrally expanded to fill the screen...) none of which will provide pleasing results.
Back at the main codec settings window, if you click the More button to the lower right, you can fine-tune your settings:
I find the settings shown are suitable for most conversions. Changes made here will have the greatest impact on processing speed.
When your video options have been set up, it is time to turn to the audio side. This, thankfully, is a lot simpler.
In the Audio menu, ensure you have selected Full processing mode and then choose Compression.
In the window that appears, select Lame MP3 with the option 44100Hz, 128kbps CBR, Stereo:
If Lame MP3 does not appear, you will need to install the Lame audio codec; however if you have installed a reasonable codec pack, you should already have this in place.
Now you are ready to get the conversion going. Under the File menu, choose Save as AVI and you will see the following:
I tend to prefix the video filename with an underscore to mean the final version. I will, obviously, rename when I am done, but it's a useful way to know what is what.
If you plan to convert a number of files at one time, click the Don't run this job now, add it to job control so I can run it in batch mode option!
The job control is a good way to get your computer to process a number of files at the same time. Under the Options menu you can choose to have your computer shut down when everything has been processed, so you can let it run during the night and your computer will switch itself off when all has been done. A 1GHz computer will process at around 12-16fps (depending on quality and options).
Without job control:
If you choose to save directly, a status window will pop up to let you know how things are progressing. Be careful with the Abort button, it takes effect right away.
Be careful also with the process priority. If you plan to carry on using your computer, you might want to set the priority lower to make other tasks more responsive. There is little point to setting the priority higher, it does not alter much. If you set the priority to highest you will find your computer becomes unresponsive. It hasn't crashed, you've just requested the majority of available time be given to VirtualDub, even to the effect of interrupting screen redraws and the like.
Transcoding, step 3 (if necessary)
It might be that your video needs to be saved in small chunks (for audio missync) or you have a film which is split into parts due to the PVR's saving files as hour-long chunks.
If you wish to save a part of the video, the way you do this is to select the region exactly as you did for advertising removal. However instead of deleting the selection, do a Save as AVI on it. Then you can delete it and work on the following part.
There is no option but to reprocess one (or more?) if the segments in order that they have the same frame rate.
Give the files incremental names, like "_demons 1-06 a.avi" and "_demons 1.06 b.avi", etc. It is IMPERATIVE that you specify the target frame rate so all of the files have exactly the same frame rate information.
If you don't, you will see the following:
Obviously, the processing of the segments is best added to job control so it can be processed at the same time; instead of you having to wait for each bit before you can carry on.
When you have finished with the conversion to XviD of the various parts, load the first part into VirtualDub. Now open the File menu again and use the Append AVI segment option as many times as necessary to glue the pieces together.
Note that the VirtualDub preview shows you the actual video frame and pays no attention to the aspect ratio setting. If you specified 16:9, you won't see this reflected in VirtualDub...
Play a few locations in the file, make sure the audio matches up correctly. If it does not, you will have to work out what the offsets should be for each segment and reprocess the segments in turn with the desired audio skew (use direct stream copy for the audio and video to save reprocessing it all over again). This is because an audio missync will throw off anything that follows, so you will need to work around this. Don't worry if the audio within the segment is off, if you have done it correctly, it will match up in the final assembled version.
When you have the shew-corrected segments, glue them together and everything should be good. After processing, don't forget to set the skew back to zero for the following steps!
I know this sounds a monumental pain in the ass. It would be nice if it was possible to tie specific audio frames to specific video frames, like maybe every five seconds or such. Instead, it appears as if the video and audio are two independent streams that run side by side but otherwise bear little relationship to each other (that's why using VBR audio can go so badly wrong if you fast forward or rewind).
Once you are happy that the video is in good form, ensure both the video and audio menus are set to Direct stream copy, as we already have our XviD/MP3 streams, it's just a matter of sticking them together. You can do this on-the-fly as a 1GHz computer ought to manage around 400-600fps (remember, it is really only copying).
Check the results in something like Windows Media Player. Double-click the AVI file, something will pick it up and start playing it. Skip around, make sure it looks okay.
When you are happy, it is time to close VirtualDub and delete the MP4 and intermediate AVI files...
My own version
It sounds complicated, and it is certainly a lot more hands-on than if the PVR was able to output XviD directly (with an aspect ratio setting that worked). On the other hand, there does not seem to be much software that allows you such a fine degree of control over the final result, especially when the recording appears to contain audio and video of slightly different lengths (which can throw out a lot of software), plus the stated frame rate is 30.000fps when in actuality it is 29.989fps (which means the sound will 'drift' more and more as you progress into the recording). It would be nice to have an all-in-one click-to-fix, but I am not aware of such a thing.
In fact, it would be nice to leave the MPEG4 video and AAC audio alone and simply rip them out of the MP4 file and stick them into an AVI wrapper in such a way that something DivX compliant will be able to play it. It is MPEG4 video... so is XviD... so why are we taking four hours to transcode MPEG4 to MPEG4 (via MJPEG)? If you know of a tool capable, please let me know where I can download it!
I have left out a lot of my own specifics, but you might have noticed some of the screenshots look subtley different to each other. This is because the assembling work is performed on Aiko, working with video files on Ayleigh. The Pazera tool and the actual XviD conversion are performed on Ayleigh. To communicate, I use shared folders and Ayleigh is running a TightVNC server.
This means that I have the flexibility of performing the video edits on the computer in front of me, while the actual grunt-work is performed by the other computer so mine can be nice and responsive for writing things such as this... ☺
Please note that while I check this page every so often, I am not able to control what users write; therefore I disclaim all liability for unpleasant and/or infringing and/or defamatory material. Undesired content will be removed as soon as it is noticed. By leaving a comment, you agree not to post material that is illegal or in bad taste, and you should be aware that the time and your IP address are both recorded, should it be necessary to find out who you are. Oh, and don't bother trying to inline HTML. I'm not that stupid! ☺ ADDING COMMENTS DOES NOT WORK IF READING TRANSLATED VERSIONS.
You can now follow comment additions with the comment RSS feed. This is distinct from the b.log RSS feed, so you can subscribe to one or both as you wish.
(Felicity? Marte? Find out!)
- Why I don't program for a living. (2022/08/11)
- USB MIDI for RISC OS. (2022/08/09)
- Archie - it's finally over, I went to Craon yesterday, The psychology of fleas, Vacuuming the concrete outside, Repainting the windows. (2022/08/07)
- It's the economy stupid, EDF and consent, Being nannyed by Google, Tidying up, Storms, Heat and bugs, More tidying up, Haircut. (2022/08/05)
- Yet more heat, Shrinkflation, Washing, Swallowtail caterpillar, Rees-Mogg was wrong and the folly of Brexit. (2022/08/03)
List all b.log entries
Return to the site index
PS: Don't try to be clever.
It's a simple substring match.
Last read at 20:24 on 2022/08/12.
© 2009 Rick Murray
This web page is licenced for your personal, private, non-commercial use only. No automated processing by advertising systems is permitted.
RIPA notice: No consent is given for interception of page transmission.