Dear all, This is a question for people typical of "mencoder-users", rather than a question about mencoder directly. What do people on this list do in terms of backing up video. In my case my original video will be in one of three formats: Mini DV tape (and DV AVIs) - huge files, typically 13G for an hour or so. Motion JPEG from my still camera - huge files, I've used it once as a trial and got over 3G of moving images. Screen capture from PC usage - not so huge files Problem is, I don't have enough disk space to let everything just lie around. I just ran out of space on my 300G usb drive. I would like to back up all my original video in some form or other. In particular the MiniDV and Motion JPEG files are home videos that I would like to be able to review into the distant future. But burning tens of DVDs per week to avoid post-camera quality loss is really not on. At present, I generally convert things into either DVD compatible MPEG-2, or DivX of some sort. I can back these up much more recently. But it's possible for me to use pretty well any format for my backups providing that mplayer (VLC et al) can read it. What formats would people recommend, and what do others do concerning backups.
On Nov 12, 2007 3:01 PM, Ross Clement <rossclement@gmail.com> wrote:
Dear all,
This is a question for people typical of "mencoder-users", rather than a question about mencoder directly.
What do people on this list do in terms of backing up video. In my case my original video will be in one of three formats:
Mini DV tape (and DV AVIs) - huge files, typically 13G for an hour or so. Motion JPEG from my still camera - huge files, I've used it once as a trial and got over 3G of moving images. Screen capture from PC usage - not so huge files
Problem is, I don't have enough disk space to let everything just lie around. I just ran out of space on my 300G usb drive.
I would like to back up all my original video in some form or other. In particular the MiniDV and Motion JPEG files are home videos that I would like to be able to review into the distant future. But burning tens of DVDs per week to avoid post-camera quality loss is really not on.
At present, I generally convert things into either DVD compatible MPEG-2, or DivX of some sort. I can back these up much more recently. But it's possible for me to use pretty well any format for my backups providing that mplayer (VLC et al) can read it.
What formats would people recommend, and what do others do concerning backups.
Hi Ross, A fairly good guideline is to you ask yourself what format you would mostly want to view your archived material in. Then for convenience's sake archive in that format (given that you have sufficient space). Previously (before I got a DVD burner and authoring software) I would compress home videos with VirtualDub (on Windows) and XviD. I achieved a 28 - 30 compression ratio from DV AVI source without annoying quality degradation. This worked very well for archiving videos and distributing them on CD. Now I intend keeping hard disk copies of DVDs I make. I have a 300GB hard disk dedicated for home videos. When that fills up, I'll probably just get another. I haven't yet played with the lossless compressability of the MPEG-2 format, but you may want to try that (ZIP, RAR etc. format). Also you could consider the lossless Lagarith codec for archival purposes, although of course you wouldn't be able to use that for material in DVD authored format. Regards, Francois
Ross Clement wrote:
What formats would people recommend, and what do others do concerning backups.
If space is an issue & you don't dislike h264's destruction of noise (or care to generate & re add it on subsequent decoding), x264. That's my choice at any rate. -- Michael Rozdoba
On Nov 13, 2007 2:05 AM, Michael Rozdoba <mroz@ukgateway.net> wrote:>
If space is an issue & you don't dislike h264's destruction of noise (or care to generate & re add it on subsequent decoding), x264. That's my choice at any rate.
Thanks. I am having a look at this now. Here's what I have so far. It seems to produce quite good quality clips even at say 3000Kb/s. Though I don't have a PSNR measurement as for some reason vcodec=x264 nor vcodec=h264 works with lavc for me. I'm using -ovc x264. Note that I'm playing around with creating quicktime compatible files as well. I won't apply the scale filter when backing up, and will use a higher bitrate. I'm also going to add in more "quality" parameters such as trellis. #!/bin/bash mencoder "$1" -of rawaudio -ovc copy -oac faac -faacopts br=192:mpeg=4:object=2 -channels 2 -srate 48000 -o "$1.aac" mencoder -of rawvideo -ovc x264 -oac copy -x264encopts bframes=1:bitrate=3000 "$1" -vf scale=-10:-1,harddup -o "$1.264" MP4Box -add "$1.264" -new "$2" MP4Box -add "$1.aac" "$2"
Ross Clement wrote:
On Nov 13, 2007 2:05 AM, Michael Rozdoba <mroz@ukgateway.net> wrote:>
If space is an issue & you don't dislike h264's destruction of noise (or care to generate & re add it on subsequent decoding), x264. That's my choice at any rate.
Thanks. I am having a look at this now.
I should point out I don't encode with x264 using MEncoder, but others around here must. There's certainly plenty of info around re config options.
Here's what I have so far. It seems to produce quite good quality clips even at say 3000Kb/s. Though I don't have a PSNR measurement as for some reason vcodec=x264 nor vcodec=h264 works with lavc for me. I'm using -ovc x264. Note that I'm playing around with creating quicktime compatible files as well.
Good luck. I've always found quicktime to be so restrictive of codec features & generally unpleasant that I don't touch it, but to be fair I haven't looked closely in years.
I won't apply the scale filter when backing up, and will use a higher bitrate. I'm also going to add in more "quality" parameters such as trellis.
#!/bin/bash
mencoder "$1" -of rawaudio -ovc copy -oac faac -faacopts br=192:mpeg=4:object=2 -channels 2 -srate 48000 -o "$1.aac"
mencoder -of rawvideo -ovc x264 -oac copy -x264encopts bframes=1:bitrate=3000 "$1" -vf scale=-10:-1,harddup -o "$1.264"
MP4Box -add "$1.264" -new "$2" MP4Box -add "$1.aac" "$2"
Does this work for non 25fps material? I might be wrong but I thought when mp4box is given .264 input (rather than .mp4), it needs to be told the framerate. In case it's of any use, this is what I often use when encoding with x264 under Windows (I imagine you might need to translate options): x264.exe --pass 1 --bitrate <rate> --stats stats --bframes 16 --b-pyramid --direct auto --filter -2,-1 --subme 1 --analyse none --me dia --threads auto --thread-input --sar <sar> --progress --no-psnr --no-ssim --output NUL input.avs x264.exe --pass 2 --bitrate <rate> --stats stats --ref 5 --mixed-refs --bframes 16 --b-pyramid --b-rdo --bime --weightb --direct auto --filter -2,-1 --subme 6 --trellis 1 --analyse p8x8,b8x8,i4x4,i8x8 --8x8dct --me umh --threads auto --thread-input --sar <sar> --progress --no-psnr --no-ssim --output output.264 input.avs mp4box.exe -add output.264 -add audio.m4a -chap ch.txt -fps <fps> -new finaloutput.mp4 For reference, the above is derived from MeGUI's HQSlower profile. A lot of valuable info can be found in the x264 related threads at doom9's web forum. -- Michael Rozdoba
On Nov 13, 2007 12:10 PM, Michael Rozdoba <mroz@ukgateway.net> wrote:
I should point out I don't encode with x264 using MEncoder, but others around here must. There's certainly plenty of info around re config options.
Thanks. I might install x264 itself, if I don't have it already.
Good luck. I've always found quicktime to be so restrictive of codec features & generally unpleasant that I don't touch it, but to be fair I haven't looked closely in years.
The video content I create is split half between work stuff (e.g. training videos for my students) and home stuff (general family video). For the work stuff I initially tried to provide videos that were suitable for both Windows Media Player and Quicktime (a lot of our students have Macs). After a short period of pulling my hair out (e.g. bash scripts that worked for small (width, height) videos but not for larger ones), I issued a blanket statement that VLC is the official video player for all of my modules, and had it installed on all machines used in my teaching lab. In some cases, I only got through things because I'd fortunately asked for mplayer.exe to be installed somewhere "just in case". I assure you all that nobody here would want to hear the unprofessional language I used to describe Windows Media Player during this episode. But I do need to load video into ProTools. At present I prepare ProTools compatible video by first rencoding my video into an AVI with dv format video. I burn that onto a DVD, and put it in a Mac, import into IMovie, and export as quicktime. Quicktime wouldn't even play my DVD compatible mpegs. But a reliable bash script to create quicktime compatible files would be useful. The official documentation uses mp4creator, which wouldn't compile on my machine.
MP4Box -add "$1.264" -new "$2" MP4Box -add "$1.aac" "$2"
Does this work for non 25fps material? I might be wrong but I thought when mp4box is given .264 input (rather than .mp4), it needs to be told the framerate.
I don't know. I only installed MP4Box this morning and have only converted one file. And it was already 25fps. I'll experiment with some 30fps content from my still camera when I get home.
In case it's of any use, this is what I often use when encoding with x264 under Windows (I imagine you might need to translate options):
I'm sure I'll be able to steal many of your option settings and reuse them. Particularly if I install or have x264. Cheers, Ross
Ross Clement wrote:
I'm sure I'll be able to steal many of your option settings and reuse them. Particularly if I install or have x264.
Here's a commandline that will give you near-lossless x264 encodes with mencoder. Depending on your usage you might want to turn off bframes completely, but if you convert to a different format anyway before you edit, leave as is. CRF determines the quality here. I'd say 15 is as lossless as you can get, but I use 18 on nearly everything, sometimes even 19. Experiment with 10 and 18 and see if you can tell the difference. Generally, <15 is considered a waste of bits, but YMMV depending on the source. m4g_hrm_v2.cfg is a custom matrix, find it on forum.doom9.org. for very grainy material, you should search for prestige_cqm.cfg as it is superior for grain preservation. CRF=18 THREADS=$number_of_cores+1 or auto DEBLOCK=-3,-3 OUTFILE=destination.264 INFILE=source.avi mencoder -vf scale -oac pcm -nosound -lavdopts threads=2 -x264encopts crf=$CRF:threads=$THREADS:cqm=m4g_hrm_v2.cfg:deblock=$DEBLOCK:bframes=3:b_pyramid:bime:weight_b:brdo:me=umh:frameref=5:mixed_refs:subq=7:trellis=1:8x8dct:nofast_pskip:nopsnr:nossim:direct_pred=auto -ovc x264 -of rawvideo -o $OUTFILE $INFILE Furthermore, if you have a lot of dark video material, you'll want to have a look at the x264 AQ patch. Note that this is a one-pass; you don't need a two pass unless you need a specific target bitrate. For archiving you shouldn't restrict yourself to a bitrate floor due to wasted space, nor ceiling due to quality loss. Hence a one-pass CRF. More technical info is on forums.doom9.org. Good luck!
infernix wrote:
m4g_hrm_v2.cfg is a custom matrix, find it on forum.doom9.org. for very grainy material, you should search for prestige_cqm.cfg as it is superior for grain preservation.
I searched both google, and the forums at doom9.org both of those custom matrix files, and could not find them. Do you have another link?
On Fri, Nov 16, 2007 at 09:53:54AM -0600, James Hastings-Trew wrote:
infernix wrote:
m4g_hrm_v2.cfg is a custom matrix, find it on forum.doom9.org. for very grainy material, you should search for prestige_cqm.cfg as it is superior for grain preservation.
I searched both google, and the forums at doom9.org both of those custom matrix files, and could not find them. Do you have another link?
Sometimes you need to be more creative with Google search: http://forum.doom9.org/showpost.php?p=989214&postcount=2 http://forum.doom9.org/showthread.php?p=887125#post887125 Giacomo
On Nov 16, 2007 3:53 PM, James Hastings-Trew <jimht@shaw.ca> wrote:
infernix wrote:
m4g_hrm_v2.cfg is a custom matrix, find it on forum.doom9.org. for very grainy material, you should search for prestige_cqm.cfg as it is superior for grain preservation.
I searched both google, and the forums at doom9.org both of those custom matrix files, and could not find them. Do you have another link?
http://forum.doom9.org/showthread.php?p=887125 I haven't tried them yet, but I found them.
Ross Clement wrote:
On Nov 16, 2007 3:53 PM, James Hastings-Trew <jimht@shaw.ca> wrote:
infernix wrote:
m4g_hrm_v2.cfg is a custom matrix, find it on forum.doom9.org. for very grainy material, you should search for prestige_cqm.cfg as it is superior for grain preservation.
I searched both google, and the forums at doom9.org both of those custom matrix files, and could not find them. Do you have another link?
http://forum.doom9.org/showthread.php?p=887125
I haven't tried them yet, but I found them
I wasn't in the mood for a google guessing game (searching for the filenames mentioned in the original post either resulted in far too few hits, or far too many.) Simply posting this link ( http://forum.doom9.org/attachment.php?attachmentid=6910&d=1173213612 ) would have been far too easy I guess.
infernix wrote:
Note that this is a one-pass; you don't need a two pass unless you need a specific target bitrate. For archiving you shouldn't restrict yourself to a bitrate floor due to wasted space, nor ceiling due to quality loss. Hence a one-pass CRF. More technical info is on forums.doom9.org.
This is a naive question. I understand the above reasoning, I think, but surely if one performs 1-pass crf, one will end up with some average bitrate. Wouldn't a 2-pass encode with that same bitrate give better quality due to superior distribution of bits? -- Michael Rozdoba
Michael Rozdoba wrote:
infernix wrote:
Note that this is a one-pass; you don't need a two pass unless you need a specific target bitrate. For archiving you shouldn't restrict yourself to a bitrate floor due to wasted space, nor ceiling due to quality loss. Hence a one-pass CRF. More technical info is on forums.doom9.org.
This is a naive question. I understand the above reasoning, I think, but surely if one performs 1-pass crf, one will end up with some average bitrate. Wouldn't a 2-pass encode with that same bitrate give better quality due to superior distribution of bits?
Going even a bit further, since bitrate is per-second, and not per-frame, isn't single-pass encoding always just plain wrong? My own experiments support this contention. And a disingenuous reference to the entire doom9 forum as support is feeble.
Phil Ehrens wrote:
This is a naive question. I understand the above reasoning, I think, but surely if one performs 1-pass crf, one will end up with some average bitrate. Wouldn't a 2-pass encode with that same bitrate give better quality due to superior distribution of bits?
Going even a bit further, since bitrate is per-second, and not per-frame, isn't single-pass encoding always just plain wrong? My own experiments support this contention.
And a disingenuous reference to the entire doom9 forum as support is feeble.
This is what I thought first, but http://forum.doom9.org/showthread.php?p=996195#post996195 and countless CRF18 x264 encodes later, I'm only using 2pass if i need to squeeze something in a specific filesize :) you might want to go over the entire thread but just that post suffices. I do wonder how you did that experimenting, did you compare visually? or did you compare PSNR/SSIM values? what source at what bitrate? what are the QP results after the encode for CRF versus 2pass? Besides, if you do go for 2pass, you have to make sure you are never undershooting, because then you'd have to encode it again at a higher bitrate.
infernix wrote:
This is what I thought first, but http://forum.doom9.org/showthread.php?p=996195#post996195 and countless CRF18 x264 encodes later, I'm only using 2pass if i need to squeeze something in a specific filesize :)
Maybe I don't have all the facts and I am sure someone here will correct me if I am wrong, but whoever is making the claim in that thread that a 2nd pass doesn't need to look any further ahead than 20 frames doesn't understand how the bits are allocated on the second pass. If I have a piece of video and the first half consists of a low motion scene of people talking to each other over a table in a kitchen, and the other half consists of people chasing around in a forest, and these two scenes are more than 20 frames apart from each other, how in the world is a 20 frame lookahead going to know that the bits need to be spent mostly in the second half, and not so much in the first half? Constant bitrate will end up with bits being wasted in the low motion scene, or not enough bits going into the high motion scene. Constant quality has it's own set of problems - you cannot predict the size of the file you are creating, which DOES become a problem for devices using certain file systems (FAT 16, FAT 32, etc). If your answer for 2 pass encoding is constant quality factor, you run into another problem -- bitrate control. There are a lot of devices that are rate limited, and when encoding for them you cannot exceed the maximum rate they can pull data from storage, decode it and display it. (Neuros OSD, Mvix, Apple TV, PSP, iPod, Zune, etc). So, you need some kind of rate control other than quality factor, and the only real way of achieving this is with two pass encode - pass one, find out where the bits need to be spent, pass 2 - encode the video.
With the x264 encoding as per this bash script: #!/bin/bash CRF=18 THREADS=auto DEBLOCK=-3,-3 OUTFILE=mvi_total.264 INFILE=mvi_total.avi mencoder -vf scale -oac pcm -nosound -lavdopts threads=2 -x264encopts \ crf=$CRF:threads=$THREADS:cqm=m4g_hrm_v2.cfg:deblock=$DEBLOCK:bframes=3:b_pyramid:bime:weight_b:brdo:me=umh:frameref=5:mixed_refs:subq=7:trellis=1:8x8dct:nofast_pskip:nopsnr:nossim:direct_pred=auto \ -ovc x264 -of rawvideo -o $OUTFILE $INFILE I get something not much more than a third of the size of the original motion jpeg. I haven't done careful comparisons of visual quality yet. BTW: As my camera is slightly noisy, I thought I'd denoise a bit first. Would I just put -vf scale,hqdn3d=3:3:3:3 at the start of the mencoder line, or do I need to put it elsewhere? Cheers, Ross
James Hastings-Trew wrote:
infernix wrote:
This is what I thought first, but http://forum.doom9.org/showthread.php?p=996195#post996195 and countless CRF18 x264 encodes later, I'm only using 2pass if i need to squeeze something in a specific filesize :)
Maybe I don't have all the facts and I am sure someone here will correct me if I am wrong, but whoever is making the claim in that thread that a 2nd pass doesn't need to look any further ahead than 20 frames doesn't understand how the bits are allocated on the second pass. If I have a piece of video and the first half consists of a low motion scene of people talking to each other over a table in a kitchen, and the other half consists of people chasing around in a forest, and these two scenes are more than 20 frames apart from each other, how in the world is a 20 frame lookahead going to know that the bits need to be spent mostly in the second half, and not so much in the first half? Constant bitrate will end up with bits being wasted in the low motion scene, or not enough bits going into the high motion scene.
Firstly I initially thought infernix's claim must be wrong or misunderstood. Then I looked at the reference. I don't think the post in isolation is sufficient, but the thread as a whole is very informative. I also realised at best there was an element of misunderstanding here; the quoted thread is certainly not wrong, since the main author is akupenguin the x264 author, who knows what he's talking about. After reading the lot I'm left with more questions & less certainty than before, but I think I can make a few observations. We are not comparing 2pass to a 1pass constant bit rate. The comparison is between 2pass & 1pass constant quality (ie option -crf <-> constant rate factor, certainly not -bitrate <-> constant bitrate or -qp <-> constant quantiser). Further, no one is claiming crf is better than 2pass, but rather that it gets very close & could get extremely close if it was able to look ahead about 20 frames. My immediate intuitive reaction is to say what if one has a video with 30 minutes of a static scene followed by 30 minutes of noise? 2pass surely allocates most bits to the 2nd half while CRF, whatever it does, can't allocate different bit distributions in awareness of the distinction between 1st & 2nd halves (*). The idea 2pass only looks 20 frames ahead surely can't be right? Right, well, by my reading of the doom9 thread, firstly, 20 frames is approximate - there's an exponential decay of weighting. One thing akupenguin does make clear though is that influence on bitrate distribution certainly doesn't extend further ahead than one gop. So that still leaves my dilemma (*) above. I think the only way to figure out what I'm misunderstanding (& others it seems) is to understand CRF better. It must already be doing a good enough job of bitrate shaping, that in the absence of any average bitrate constraints, 2pass doesn't need to do much more. As I said, it's just left me with more questions :-/ /snip other valid points about why bitrate control is often important in practice -- Michael Rozdoba
Hello, On Sat, Nov 17, 2007 at 08:26:11PM +0000, Michael Rozdoba wrote: [...]
My immediate intuitive reaction is to say what if one has a video with 30 minutes of a static scene followed by 30 minutes of noise? 2pass surely allocates most bits to the 2nd half while CRF, whatever it does, can't allocate different bit distributions in awareness of the distinction between 1st & 2nd halves (*).
Of course it does "allocate different bit distributions", it since it trivially reaches the desired quality in the first part so it uses very few bits, whereas in the second part it must use lots to get the desired quality. Actually I don't know why 2pass should provide better quality than CRF (except that it can be a pain, if not almost impossible to get the desired file size with CRF). Well, actually there is one case I can think of: If you know that e.g. the next frame will be a keyframe due to its immense complexity, then you can encode the current frame with less bits with hardly a _visible_ loss of quality - which is one information you don't know with one-pass CRF. Greetings, Reimar Döffinger
Reimar Döffinger wrote:
Hello, On Sat, Nov 17, 2007 at 08:26:11PM +0000, Michael Rozdoba wrote: [...]
My immediate intuitive reaction is to say what if one has a video with 30 minutes of a static scene followed by 30 minutes of noise? 2pass surely allocates most bits to the 2nd half while CRF, whatever it does, can't allocate different bit distributions in awareness of the distinction between 1st & 2nd halves (*).
Of course it does "allocate different bit distributions", it since it trivially reaches the desired quality in the first part so it uses very few bits, whereas in the second part it must use lots to get the desired quality.
Which is why I said 'in awareness of...'; it allocates them independently, which isn't a problem given no bitrate restrictions. The intuitive feeling however, which is probably wrong, is that awareness of the bit distribution needs across the entire video (from a first pass) should be of benefit in influencing the bit distributing in a subsequent pass. It seems this isn't needed.
Actually I don't know why 2pass should provide better quality than CRF (except that it can be a pain, if not almost impossible to get the desired file size with CRF). Well, actually there is one case I can think of: If you know that e.g. the next frame will be a keyframe due to its immense complexity, then you can encode the current frame with less bits with hardly a _visible_ loss of quality - which is one information you don't know with one-pass CRF.
Exactly, and one reason why it is necessary to look upto one gop ahead but probably no further. -- Michael Rozdoba
On Sat, 17 Nov 2007, Michael Rozdoba wrote:
Reimar D�ffinger wrote:
Hello, On Sat, Nov 17, 2007 at 08:26:11PM +0000, Michael Rozdoba wrote: [...]
My immediate intuitive reaction is to say what if one has a video with 30 minutes of a static scene followed by 30 minutes of noise? 2pass surely allocates most bits to the 2nd half while CRF, whatever it does, can't allocate different bit distributions in awareness of the distinction between 1st & 2nd halves (*).
Of course it does "allocate different bit distributions", it since it trivially reaches the desired quality in the first part so it uses very few bits, whereas in the second part it must use lots to get the desired quality.
Which is why I said 'in awareness of...'; it allocates them independently, which isn't a problem given no bitrate restrictions. The intuitive feeling however, which is probably wrong, is that awareness of the bit distribution needs across the entire video (from a first pass) should be of benefit in influencing the bit distributing in a subsequent pass. It seems this isn't needed.
Where you went wrong is thinking of bit distributing. "Distribution" carries a connotation that you have some bits and then decide where to put them. That's not how x264 works, CRF nor 2pass. It's better to think of "bit requisitioning": decide how many bits you need at any given time and take that many, out of an infinite reservoir. The limitation on bitrate is then not some quota, but rather a price tag attached to each bit. CRF buys bits until it can't justify the cost due to diminishing returns on quality-improvement-per-bit. Then it should be obvious that if you do have a bit quota (i.e. 2pass target bitrate), optimally allocating bits from that quota is equivalent to finding some quality-per-bit cost threshold such that all frames are satisfied within your quota. If that were not the case, then to get from CRF's choice to 2pass's choice there must be some pair of frames A and B such that A takes bits away from B. That means A can make better use of those bits than B could. But CRF uses the same quality-per-bit threshold everywhere, so it would have already made the same decision that A deserves more bits. Now the only factor that needs a lookahead is the estimation of how much quality you'd get out of a given bit, which is where the discussion of a 20 frame window came in. The repercussions of any decision are local; changes to objective metrics are strictly limited to one GOP and usually smaller, while psychovisual repercussions are not strictly limited but still can't possibly extend more than a few seconds. --Loren Merritt
Loren Merritt wrote:
Where you went wrong is thinking of bit distributing. "Distribution" carries a connotation that you have some bits and then decide where to put them. That's not how x264 works, CRF nor 2pass. It's better to think of "bit requisitioning"
/snip details Thanks very much. That's the clearest explanation I've come across & helps clear up my misunderstanding :) That should definitely be part of any doc explaining the basics of x264's approach. Most appreciated. -- Michael Rozdoba
Michael Rozdoba wrote:
Loren Merritt wrote:
Where you went wrong is thinking of bit distributing. "Distribution" carries a connotation that you have some bits and then decide where to put them. That's not how x264 works, CRF nor 2pass. It's better to think of "bit requisitioning"
/snip details
Thanks very much. That's the clearest explanation I've come across & helps clear up my misunderstanding :) That should definitely be part of any doc explaining the basics of x264's approach. Most appreciated. It's not really doing anything for me.
I guess I just don't understand, unless x264 can "magically" know where to requisition bits, and where not to, and still come out without over-spending or under-spending by the end of the file. If I aim for a 2Gb file (because that is the max size that will fit in my devices' storage), and it under-requisitions and ends up giving me a 1.8Gb file, then I can reasonably assume that there are some scenes in that file that could have been encoded at a higher quality, if only x264 had known it could requisition more bits for them. If it over-requisitions and I end up with a file that's 2.2Gb, well, maybe that is useless for my needs and I am going to have re-encode it at a lower bitrate. What am I missing? Also, is this list having technical issues? There have been at least 2 posts of mine that have gone missing.
James Hastings-Trew wrote:
I guess I just don't understand, unless x264 can "magically" know where to requisition bits, and where not to, and still come out without over-spending or under-spending by the end of the file.
Of course 2pass is modifying the quality it is aiming for in the 2nd pass to arrive at your target size; what however it isn't doing is making non local changes to the shape of the resulting bitrate distribution. AIUI now. -- Michael Rozdoba
On Mon, 19 Nov 2007 20:02:20 -0600 James Hastings-Trew <jimht@shaw.ca> wrote:
If I aim for a 2Gb file (because that is the max size that will fit in my devices' storage), and it under-requisitions and ends up giving me a 1.8Gb file, then I can reasonably assume that there are some scenes in that file that could have been encoded at a higher quality,
What am I missing?
You are missing the fact that some situations don't have a specific filesize quota. Let's say I have a 500GB hard drive, and I just store all my movies on there. The smallest video size, at an acceptible level of visual quality, is ideal. That is where 1-pass with CRF does quite well. The "buffer" issue is just about improving 1-pass quality slightly (vs. slower 2-pass). This isn't the same situation, as with MPEG-1/2/4 and most other codecs. A particular quantization level doesn't necessarily represent a consistent level of visual quality... CRF does.
On Tue, 20 Nov 2007, RC wrote:
This isn't the same situation, as with MPEG-1/2/4 and most other codecs. A particular quantization level doesn't necessarily represent a consistent level of visual quality... CRF does.
A particular H.264 quantization level doesn't necessarily represent a consistent quality either. There's no reason CRF couldn't be implemented in MPEG-1/2/4. --Loren Merritt
On Mon, Nov 19, 2007 at 08:02:20PM -0600, James Hastings-Trew wrote:
Michael Rozdoba wrote:
Loren Merritt wrote:
Where you went wrong is thinking of bit distributing. "Distribution" carries a connotation that you have some bits and then decide where to put them. That's not how x264 works, CRF nor 2pass. It's better to think of "bit requisitioning"
/snip details
Thanks very much. That's the clearest explanation I've come across & helps clear up my misunderstanding :) That should definitely be part of any doc explaining the basics of x264's approach. Most appreciated. It's not really doing anything for me.
I guess I just don't understand, unless x264 can "magically" know where to requisition bits, and where not to, and still come out without over-spending or under-spending by the end of the file. If I aim for a 2Gb file (because that is the max size that will fit in my devices' storage), and it under-requisitions and ends up giving me a 1.8Gb file, then I can reasonably assume that there are some scenes in that file that could have been encoded at a higher quality, if only x264 had known it could requisition more bits for them. If it over-requisitions and I end up with a file that's 2.2Gb, well, maybe that is useless for my needs and I am going to have re-encode it at a lower bitrate.
What am I missing?
In the thread on doom9 linked to earlier, akupenguin says at one point that both CRF and 2pass use heuristics which try to spend bits in a rate-distortion-optimal manner. i.e. where would spending another bit most improve the subjective quality of the overall movie? The main difference is that 2pass constrains the total number of bits that can be spent, while CRF targets a specific quality level, with unknown final file size. x264 pass=1 writes a file that says how complex each frame is, (in terms of bits needed to code it with reference to previous frames...) Frame decisions (I, P, or B) are made in pass 1. When pass 2 starts, it reads that file, and decides (roughly?) where it's going to spend its bits before even encoding the first frame. It takes a lot of bits to improve the quality of high-motion high-detail scene. Spending a bit improving the appearance of an I frame that is referenced for a long time (e.g. a background in a scene with no camera movement) will add more quality to the whole movie. (i.e. PSNR or SSIM as reported by x264). apparently crf does quite well. On the doom9 thread, some people, including akupenguin, say that crf is not worse than 2pass. OTOH, some guides I've seen say that some options don't really work with crf, e.g. trellis=1. (Also, some say that trellis and dct_decimate don't work well together, so I usually use trellis=1:no_dct_decimate). Since I usually archive to dvd+r, I tend to use crf to see what kind of ballpark bitrate I'm going to need (with crf=18 or 20, usually), then plan what all I'm going to try to fit onto a dvd. This is the biggest problem: do I group movies with the same director, the same genre, the same year, or what. And if I have a good copy of one movie and a crappy looking copy of another, I might find a better copy of the poor-looking one, so one of the movies on the disc would be obsolete. I usually keep movies like that on my hard drive, and only burn HD quality stuff, because it's so big. (and because it takes up a whole disc by itself, thus making the decision trivial.) Sometimes I'll transcode to 2.2GB and put 2 movies on a dvd, if they compress well and I don't like the movie enough to want a very high qual copy. -- #define X(x,y) x##y Peter Cordes ; e-mail: X(peter@cor , des.ca) "The gods confound the man who first found out how to distinguish the hours! Confound him, too, who in this place set up a sundial, to cut and hack my day so wretchedly into small pieces!" -- Plautus, 200 BC
On Sat, 24 Nov 2007, Peter Cordes wrote:
OTOH, some guides I've seen say that some options don't really work with crf, e.g. trellis=1. (Also, some say that trellis and dct_decimate don't work well together, so I usually use trellis=1:no_dct_decimate).
They're just wrong. If they're wikis, please provide a link so that I can fix them. If they're not wikis, please provide a link so that I can flame the authors. I'm not sure how the rumor started, unless it has something to do with the previous rumor that xvid's trellis is harmful with CQ. Which is both wrong in that it was due to incorrect measurements the benefits of trellis, and wrong in that it assumes x264 is the same. --Loren Merritt
On Mon, Nov 26, 2007 at 05:28:55AM -0700, Loren Merritt wrote:
On Sat, 24 Nov 2007, Peter Cordes wrote:
OTOH, some guides I've seen say that some options don't really work with crf, e.g. trellis=1. (Also, some say that trellis and dct_decimate don't work well together, so I usually use trellis=1:no_dct_decimate).
They're just wrong. If they're wikis, please provide a link so that I can fix them. If they're not wikis, please provide a link so that I can flame the authors.
Here's one: http://www.avidemux.org/admWiki/index.php?title=X264
I'm not sure how the rumor started, unless it has something to do with the previous rumor that xvid's trellis is harmful with CQ. Which is both wrong in that it was due to incorrect measurements the benefits of trellis, and wrong in that it assumes x264 is the same.
One of them actually has a justification that sounded reasonable to me (not knowing exactly how x264 works, but having some idea of video compression in general): dct_decimate throws away some detail and it's better to let trellis make all the decisions about what to throw away. I can't find that doc with google, even though I think I did stumble across it again recently. So you're saying that the dct blocks dct_decimate throws away would not always get thrown away by trellis when it would be Better to do so. (for some definition of better, such as PSNR-optimal.) Err, I've also seen it said in several places that trellis is not a good idea with crf rate control. e.g. in this doc from june 2006: http://www.digital-digest.com/articles/x264_options_page6.html Is this true now, if it ever was? I've seen akupenguin (x264 lead author) say that crf is close the the same quality as 2pass, and that would be more likely if there aren't options that are only good with 2pass. Thanks for setting me straight. -- #define X(x,y) x##y Peter Cordes ; e-mail: X(peter@cor , des.ca) "The gods confound the man who first found out how to distinguish the hours! Confound him, too, who in this place set up a sundial, to cut and hack my day so wretchedly into small pieces!" -- Plautus, 200 BC
On Wed, 28 Nov 2007, Peter Cordes wrote:
One of them actually has a justification that sounded reasonable to me (not knowing exactly how x264 works, but having some idea of video compression in general):
dct_decimate throws away some detail and it's better to let trellis make all the decisions about what to throw away.
I can't find that doc with google, even though I think I did stumble across it again recently.
So you're saying that the dct blocks dct_decimate throws away would not always get thrown away by trellis when it would be Better to do so. (for some definition of better, such as PSNR-optimal.)
The trellis option itself disables the part of dct_decimate that trellis can do better. Then the dct_decimate option only controls the part of decimation that trellis can't do, i.e. decimating a whole macroblock if all of its dct blocks are weak (because trellis can't see the whole macroblock, it applies only to one dct block at a time). Now, there are reasons one might want to disable decimation, mostly involving crazy people who want to preserve noise rather than signal. But that's unrelated to trellis.
Err, I've also seen it said in several places that trellis is not a good idea with crf rate control. e.g. in this doc from june 2006: http://www.digital-digest.com/articles/x264_options_page6.html Is this true now, if it ever was?
That was never true. The reasoning that started the rumor is: "CRF is constant quality, so we can try various options and whichever gives the lowest bitrate is the best. Trellis sometimes increases bitrate at a given CRF, so trellis doesn't work with CRF." The error in that reasoning is that CRF is only approximately constant quality. If trellis increases the bitrate, it also increases quality, so the quality-per-bitrate still improves. This is not specific to trellis: just about all x264 options affect both quality and bitrate, even with "constant quality" ratecontrol. It's just that most of the options increase quality and reduce bitrate, while a few options increase or decrease both, or even have different effects on different content. --Loren Merritt
infernix wrote:
Ross Clement wrote:
I'm sure I'll be able to steal many of your option settings and reuse them. Particularly if I install or have x264.
Here's a commandline that will give you near-lossless x264 encodes with mencoder. Depending on your usage you might want to turn off bframes completely, but if you convert to a different format anyway before you edit, leave as is.
CRF determines the quality here. I'd say 15 is as lossless as you can get, but I use 18 on nearly everything, sometimes even 19. Experiment with 10 and 18 and see if you can tell the difference. Generally, <15 is considered a waste of bits, but YMMV depending on the source.
m4g_hrm_v2.cfg is a custom matrix, find it on forum.doom9.org. for very grainy material, you should search for prestige_cqm.cfg as it is superior for grain preservation.
CRF=18 THREADS=$number_of_cores+1 or auto DEBLOCK=-3,-3 OUTFILE=destination.264 INFILE=source.avi
mencoder -vf scale -oac pcm -nosound -lavdopts threads=2 -x264encopts crf=$CRF:threads=$THREADS:cqm=m4g_hrm_v2.cfg:deblock=$DEBLOCK:bframes=3:b_pyramid:bime:weight_b:brdo:me=umh:frameref=5:mixed_refs:subq=7:trellis=1:8x8dct:nofast_pskip:nopsnr:nossim:direct_pred=auto -ovc x264 -of rawvideo -o $OUTFILE $INFILE I've done some playing with a variation of this command line and I do have to say, in situations where you don't care about the final file size or bitrate, this does produce a very high quality encode in about half the time of a two-pass. Here is my variation of it, eliminating bframe options and tweaked slightly for speed (since I am mostly encoding for the AppleTV at this point, which does not allow bframes) - (this is for a wide-aspect telecined NTSC DVD with no cropping).:
set crf=18 set threads=%NUMBER_OF_PROCESSORS% set deblock=-3.-3 set outfile=destination.mp4 set infile=DVD://3 -aid 128 set scale=848:480 set idclevel=31 mencoder %infile% -sws 9 -of lavf -lavfopts format=mp4 / -vf pullup,softskip,pp=lb,scale=%scale%,dsize=%scale%,harddup / -oac faac -faacopts mpeg=4:object=2:br=160:raw -channels 2 -srate 48000 -ovc x264 -x264encopts / crf=%crf%:cqm=m4g_hrm_v2.cfg:deblock=%deblock%:me=umh:frameref=6:mixed_refs:subq=6:/ trellis=1:8x8dct:nofast_pskip:nocabac:global_header:level_idc=%idclevel%:threads=%threads% / -ofps 24000/1001 -o temp.mp4 nicmp4box -add temp.mp4 %outfile% del temp.mp4 >NUL Works like a charm and the results are very high quality.
On Sat, 17 Nov 2007 15:49:58 -0600 James Hastings-Trew <jimht@shaw.ca> wrote:
in about half the time of a two-pass.
two-pass encoding shouldn't be remotely so slow. Are you using "turbo" on the first pass?
I posted this question the weekend, but it seems to have disappeared into the ether. I'm reposting it in a slightly edited form: I'm encoding a video to x264 from a DVD source. The length of the video is 53 mins, 2 seconds, at a frame rate of 23.976. This means the resulting video file will have 76291 frames in it. This particular video takes around 200 minutes to encode with the settings I am using: | mencoder c:\temp\title.vob -aid 128 -af volume=14.288 -sws 9 -of lavf -lavfopts format=mp4 -vf pullup,softskip,pp=lb,crop=720:480:0:0,scale=848:480,dsize=848:480,harddup,unsharp=l3x3:0.5 -oac faac -faacopts mpeg=4:object=2:br=160:raw -channels 2 -srate 48000 -ovc x264 -x264encopts crf=18:cqm=custom_matrix.cfg:me=umh:frameref=6:mixed_refs:subq=6:trellis=1:8x8dct:nofast_pskip:nocabac:global_header:level_idc=31:threads=2 -ofps 24000/1001 -o temp.mp4 | This means that the video is encoding at a rate of 6.36 frames per second. However, Mencoder's status line reports that it has processed 190727 frames, at a rate of 16 frames per second. This is 2.5 times the number of frames in the video, and 2.5 times the actual frame rate it is encoding at. Any idea why the status line is so woefully wrong in reporting how many frames it's working on, and at what speed? The time remaining calculation and the estimated file size seem to be correct. It is almost as if mencoder is treating the input frame rate as 60 frames per second - (24 x 2.5 = 60) which I guess means mencoder is counting each field of input before the pullup, as a frame? Help me to understand this.
James Hastings-Trew wrote:
I've done some playing with a variation of this command line and I do have to say, in situations where you don't care about the final file size or bitrate, this does produce a very high quality encode in about half the time of a two-pass.
The speed should be the same for a CRF run and the second pass of a 2pass run; the speed benefit is gained by not running a first pass at all. Now that you've experimented a bit more, you'll want to look at some possible patches to x264 that might be of further help. I'm using the following patches: x264_aq.5-654.diff x264_thread_pool.04.diff x264_faster-dia.r680.diff x264_cachesplit.02.diff You'll find them here: http://forum.doom9.org/showthread.php?t=130364 and here: http://akuvian.org/src/x264/ Thread pool is only relevant with multicore (4+). cachesplit is fairly new and is about code optimisation (same for faster-dia). the AQ patch is adaptive quantizing and is supposed to reduce blocking/banding in background scenes (it spends more bits on it depending on the used aq-strenght; I use 0.3 mostly). There's more patches out there as well. If you're conservative you can just stick with SVN, it'll do fine.
participants (11)
-
Francois Visagie -
Giacomo Comes -
infernix -
James Hastings-Trew -
Loren Merritt -
Michael Rozdoba -
Peter Cordes -
Phil Ehrens -
RC -
Reimar Döffinger -
Ross Clement