User Name
Password
AppleNova Forums » Genius Bar »

Video codec questions


Register Members List Calendar Search FAQ Posting Guidelines
Video codec questions
Thread Tools
Kraetos
Lovable Bastard
 
Join Date: Dec 2005
Location: Boston-ish
 
2006-02-19, 20:44

Hi All,

I have recently discovered how to transfer video directly from my DVR to my Mac. The video that comes from the DVR is saved into .m2t format, which is only readable by VLC player. I want to get it into Quicktime. VLC's exporting tools are rather weak, so I am using a program called MPEG Streamclip.

However, I cannot pick a viable format, for any number of reasons. The raw data is about 50 minutes of 704 x 480 video, in .m2t format. The file weighs in just shy of 800 MB.

Many of Apple's fancy codecs (pixlet, H.264) cause the file to baloon in size to about 3 GB. Exporting to a .mov file has a similar effect. The various .avi formats cause the file increase to the 1-2 GB range. Others make the file sub-500 MB, but the quality goes WAY down.

The only one which has a smaller size and decent quality is the 3ivx D4 (4.5.1) codec. The quality has no noticeable drop, and the file shrinks to about 650 MB. However, when I do this, Quicktime launches and displays an error message: "Some of the software required to play this video is missing" or something similar. It then launches me at the quicktime website, which is entirely of no help, because I already know exactly what codec I used so downloading new ones wont help. Also, it doesn't matter if I change the audio codec, it still comes through with no sound.

Go figure - the only efficient video codec I find doesn't work right. (Tangent: arent most codecs designed to COMPRESS raw video? Why are all these codecs actually INCREASING the size of the file? Its not like their going to eek any more quality out of the video from its raw format.)

If anyone could suggest a working codec, or a way to fix the 3ivx codec, it would be greatly appreciated.

Sadly, being a technology pundit is truly never having to say you’re sorry. You can be wrong for years and never lose your job.—The Macalope
  quote
Dorian Gray
Veteran Member
 
Join Date: May 2005
Location: Paris, France
 
2006-02-20, 23:39

Hi there,

Not sure how much you know about video, but here are a couple of tips to help you find a solution. ".m2t" is a file extension for MPEG-2 Transport Streams, and as you've noticed, these files can sometimes be a bit of a hassle to turn into something a bit more usable.

You've started well by using MPEG Streamclip, which is a good tool for this kind of thing. You should approach this in two steps: use MPEG Streamclip to export the video with a lossless (perfect quality) QuickTime codec, and then export that intermediate file from within QuickTime Pro using a suitable delivery codec. The reason I would do the intermediate encode is that it's very difficult to edit video if it's in a delivery format (because the long keyframe interval causes huge seek delays) and it's also very tricky to get accurate bitrate control from within MPEG Streamclip.

Both ".mov" and ".avi" are containers rather than codecs: they are file formats that are capable of holding video and audio encoded with various codecs (among other bits and pieces of information). For subsequent editing (or simply exporting) in QuickTime Pro, you should stick with a ".mov" format, which guarantees compatibility with QuickTime. Depending on the lossless codec you use for the intermediate encode, you will need somewhere between a huge and an obscene amount of free disk space, though this could be an external drive of course.

So, which lossless codec should you use? This depends somewhat on the content you are encoding, and the balance between your computer's processor power and hard disk size/speed. By the way, leave the sound as uncompressed stereo (QuickTime can encode to anything from this) and make sure the Frame Size is identical to your source video: enter it manually if need be.

For animated video use the "Apple Animation" codec (this is only lossless when the quality slider is set to 100%). This codec works in the RGB colour space and is good at compressing solid blocks of colour of the kind typically found in animation. Using it for video will do no harm - it's lossless afterall - but it will result in very poor compression, sometimes even resulting in a file larger than uncompressed video. It is moderately processor intensive and extremely disk intensive.

"Apple Component Video - YUV422" is an uncompressed codec that operates in the YUV colour space, with 4:2:2 chroma subsampling (for practical purposes this means that it's only lossless if your source video is in the YUV colour space, which it won't be in your present case). Useful when importing analogue video. The quality slider in MPEG Streamclip has no effect on this codec. It is very disk intensive but doesn't use much processing time.

You're probably familiar with the PNG lossless compression format for still images. "Apple PNG" simply compresses each frame of video as if it were a still image, using the RGB colour space. The quality slider in MPEG Streamclip has no effect when using the Apple PNG codec. This may be an appropriate codec for your intermediate encode, as it should preserve all the colour information in your original video. It is very processor intensive but gives relatively good compression.

"Apple Motion JPEG A" is lossless if you set the quality slider to 100% (though for practical purposes 85% may be as good as perfect). It uses the YUV colour space (4:2:2 again), so will not preserve all colour information from an RGB source. The "Apple Motion JPEG B" codec is identical except for compatibility differences for old hardware. This codec is much less processor intensive than Apple PNG and provides significantly better compression too, but at the expense of a loss of some colour information (which may be perfectly acceptable in your case).

I tested these codecs with a 10-second ".m2t" video clip of outdoor sports (file size 50 MB, 25 Mbps, 1440 x 1080 pixels, 29.97 fps) and these were the results:

"Apple Animation" at 100% quality: 950 Mbps (nearly 1 Gbps!!!), file size 1.2 GB.
"Apple Component Video - YUV422": 750 Mbps, file size 940 MB.
"Apple PNG": 360 Mbps, file size 450 MB.
"Apple Motion JPEG A": 215 Mbps, file size 270 MB.

My hard disk is only fast enough to play the last option in QuickTime Player, but all of them provide perfect quality video frames (with slightly different colour rendition). Note that my slow hard disk would not prevent QuickTime encoding them to a delivery codec - the encoding would simply take place at a pace slower than real-time, likely limited by processor rather than disk in any case. From the file sizes I got in my test, I would guess you would need 20 GB of free space for an Apple Motion JPEG A encode, 40 GB for an Apple PNG, or 80 GB for an Apple Component Video encode. I suggest you try Apple Motion JPEG A first, as it requires the least disk space and is pretty fast compared to the other options.

Then open the encoded ".mov" file in QuickTime, edit as required, and export to a delivery format of your choice. For near-DVD quality video I would suggest H.264/multi-pass/1500 kbps/100-frame keyframe interval (for video) with AAC/44 kHz/Stereo/128 kbps (for audio). This would result in a final video size of about 610 MB, which you can put in either a .MOV or .MP4 container depending on your preference. If you want a different file size (much smaller or bigger), adjust the bitrate and/or frame size accordingly. Ask if you want some starting points.

Quote:
Tangent: arent most codecs designed to COMPRESS raw video? Why are all these codecs actually INCREASING the size of the file? Its not like their going to eek any more quality out of the video from its raw format.
Not all codecs are designed to compress video. Some are for editing or intermediate encodes (such as the ones I suggested above), and these often sacrifice small size for other qualities, such as lossless compression or good seek times. Delivery codecs such as MPEG-4 are designed to make the final file as small as possible. However, the ".m2t" file you have is already very heavily compressed (with the MPEG-2 codec, as used on commercial DVDs for example). This is why some of the options are making the file a lot larger. Incidentally, by adjusting the quality slider in MPEG Streamclip you could probably make the files a bit smaller, but Apple Pixlet Video, etc. will always result in a vastly larger file than MPEG-2.

Hope this helps.
  quote
Kraetos
Lovable Bastard
 
Join Date: Dec 2005
Location: Boston-ish
 
2006-02-21, 11:35

Helps a lot, thanks. My primary concerns here are storing these video clips on my hard drive, and being able to pull screencaps. For screencaps I guess I'll need more keyframes.

After reading, it sounds like I wanna do the following:

1) Convert .m2t to Apple Motion JPEG A
2) Open in QuickTime, edit out extraneous stuff (the commercial brakes, for instance)
3) Convert the edited Apple Motion JPEG A to the H.264 with these settings:

Quote:
For near-DVD quality video I would suggest H.264/multi-pass/1500 kbps/100-frame keyframe interval (for video) with AAC/44 kHz/Stereo/128 kbps (for audio).
I would be using QuickTime for this final conversion, correct?

At which point I will have neat and tidy little 42-minute epidsodes of Battlestar Galactica on my hard drive. I think I am going to need to buy an external drive though.

Thanks so much for the help, I was really lost in something that is almost completely out of my league.

Sadly, being a technology pundit is truly never having to say you’re sorry. You can be wrong for years and never lose your job.—The Macalope
  quote
Dorian Gray
Veteran Member
 
Join Date: May 2005
Location: Paris, France
 
2006-02-21, 12:47

Quote:
My primary concerns here are storing these video clips on my hard drive, and being able to pull screencaps. For screencaps I guess I'll need more keyframes.
Yes, messing with video requires a huge (and preferably fast) hard disk, no getting around that! If you do decide to buy an external, try to get one with FireWire (faster than USB 2.0). As for screen captures, the keyframe interval won't affect your ability to do that (if QuickTime can play a frame, you can pause it on that frame and take a screen shot). Keyframes are just the frames that the codec has recorded in full. For subsequent frames (between keyframes) the codec just records the frame differences from the previous frame: eventually (over many frames) the differences accumulate to the extent that a new keyframe is needed or the quality will gradually creep away from optimum. When you select 100 as your keyframe interval, the codec will force a new keyframe every 100 frames, as well as every time the frame changes significantly (for example, on camera changes in films).

When you randomly start playing a video somewhere in the middle, QuickTime has to find the previous keyframe (which might be up to 99 frames earlier (with a keyframe interval of 100) if you're unlucky!), then calculate the frame after the keyframe based on the encoded instructions, followed by the next frame, etc., for 99 frames. Only then can QuickTime present the frame you randomly selected and start playing. This is why there is sometimes a pause of a second or two when you start playback in the middle of a video, particularly with processor-intensive codecs such as H.264. It therefore makes sense that if you want short seek times, you need a lower keyframe interval. But storing a keyframe takes much more space than the instructions for changes from the previous frame, especially in scenes where the only movement is someone's talking mouth, for example. So for a given file size, a balance must be struck to get the best quality, and this varies depending on the video material. Experiment with keyframe intervals of between 1 and 6 seconds (calculate based on frame rate) to see what works best for your video material.

This is one reason why MPEG-4, etc. are bad authoring codecs. You can't just remove whatever frames you feel like, because you may be removing a keyframe that was the starting point for a series of instructions for creating a frame a couple of seconds down the line. With Apple Motion JPEG A, on the other hand, you can add or remove frames wherever you wish, because each frame is independent of the others. In effect, every frame is a keyframe. So it's good for removing commercials.

The three steps you mention are correct (just make sure the quality slider is at 100% for Apple Motion JPEG A in MPEG Streamclip if you want best quality). You're also correct about using QuickTime for the final conversion (from Apple Motion JPEG A to H.264), although technically you could use any encoder that opens .MOV files. QuickTime Pro is great for encoding, although it doesn't give as much fine control as applications like Sorenson Squeeze 4.

If you're using the 1 GHz PowerBook in your signature, you'll find it will take several hours to make the intermediate encode in MPEG Streamclip, and probably over a day to encode the final H.264 video if you use multi-pass. You might also want to experiment to see if the PowerBook has enough power to smoothly play back 1500 kbps H.264 video at that frame size (it will be touch and go). It would make sense to encode a ten-second clip to see if you're satisfied with the quality, etc., before doing the big encode. Time how long it takes for QuickTime to encode the 10 second clip to give you an idea how long the entire 42-minute thing will take.

Of course the beauty of OS X is that you'll be able to use your computer normally while it's encoding away in the background, or put it to sleep to travel, etc.
  quote
Posting Rules Navigation
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Post Reply

Forum Jump
Thread Tools

« Previous Thread | Next Thread »

All times are GMT -5. The time now is 09:12.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright ©2004 - 2020, AppleNova