logo Sign In

Info wanted: General Encoding Question from Projects - Scripters opinions wanted.

Author
Time
 (Edited)

I’m searching for a way to encode a file for best possible constant quality, based on a specific size.

I was wondering if there was a way to tell an encoder to CRF up to the credits (specifiying a specific frame), at which point the credits are encoded using two pass to achieve an overall average bitrate, acknowledging the size of the CRF encoded portion as well.

You would set a minimum bitrate so that the credits weren’t totally botched. The encoder would look at the CRF portion, then see if the credits could be encoded at the minimum bitrate to reach the desired size. If not, the encoder would repeat the CRF encode at one value lower, and repeat the process. Otherwise, the two pass would be completed on the credits to allow for potentially better quality

All of you scripters… has this been done, or is there any way that you could look into a way to do this for mpeg2 and h.264?

Preferred Saga:
1/2: Hal9000
3: L8wrtr
4/5: Adywan
6-9: Hal9000

Author
Time
 (Edited)

I think what you want is x264 ZONES.

https://en.wikibooks.org/wiki/MeGUI/x264_Settings#zones

Where you set an overall CRF normally, and then specify another CRF for a zone.

===

Yes you can encode __MAIN using CRF and then the credits separately using 2pass, both with the --stitchable option, and join using MKVnix. Any acknowledgement would be purely up to the user. Or you can write a script to try & try again to match an overall size. I think this is retarded and not worth pursuing. After all, __MAIN is the bulk of your filesize, not the creds. Any dealbreaker for filesize typically would have long passed before the credits.

===

1pass CRF is the highest quality mode x264 has to offer, better than 2pass, because the encoder is not concerned about filesize issues.

===

you can use x262 for encoding MPEG2, and it apparently supports zones

https://www.videolan.org/developers/x262.html

Author
Time

Thank you for that, it helps a lot. I see your point on the credits - while it may seem useless to some, perhaps a simple script that checks the final size of a CRF encode, and discards it if over a certain size, starting over to encode again with a CRF value one lower (a smart script might even be able to judge how much larger the encode is than the desired size, and choose between 1, 2, or 3 lower depending on the overage).

Oddly, I see the potential in zones evening out quality in projects using different sources. Maybe CRF 16 for Upscaled HD footage, while bluray footage gets CRF 20+ to degrade the quality of the film through encoding the same way SD footage was originally degraded through encoding. I'd imagine this would work far better than any unsharp tool.

Preferred Saga:
1/2: Hal9000
3: L8wrtr
4/5: Adywan
6-9: Hal9000

Author
Time
 (Edited)

No, I think you're better off using a consistent CRF or a consistent 2-pass bitrate setting. There are other ways to degrade picture quality without using different bitrates - for instance you could resize the scenes surrounding your inserted SD footage to make the transition more smooth, if desired (downscale to a resolution in-between and then upscale it again to degrade the quality).

The credits take up a negligible amount of space compared to the rest of the film anyway. So I agree with junh1024 on that one. For instance, in my encode for Jurassic Park the video file came to 3542.2 MB, yet the credits are only 147.1 MB of that. So by compressing that area of the film further I could only really save an extra 50 or 60 MB and that's being generous. Out of 3.45 GB, 50 MB is nothing.

However, he's wrong about 2-pass. CRF and 2-Pass are equivalent. The only difference is that CRF maintains consistent quality and achieves the desired level of quality, whereas 2-Pass maintains consistent quality and achieves the desired average bitrate. If you have a 2-Pass file and a CRF file that come out at the same size then they will be exactly the same quality. Which you can test yourself easily - set CRF quality to something low like 26 or 28 and encode, then take the average bitrate from the file you just encoded and encode again using 2-pass. The two encoded files will be exactly the same quality - they just came to it using two different routes.

Here's another tip... with 2-Pass you can't know the quality in advance. So my suggestion is you set the CRF to what you want and encode the file. Let's say you want the CRF at 18 or perhaps 19. Encode it and see what size it comes to. If it's well outside the size you're wanting then you should find a way to make the file more compressible instead of lowering the encoding quality to force it to fit the desired size. You could resize from 1080p to 720p for instance. De-grain, De-noise, etc. Once you get it to encode around the right size at the right quality then use 2-pass to get the exact size that you need.

[ Scanning stuff since 2015 ]

Author
Time

My experience is that x264's "2-pass" mode is broken and should not be used. If it worked like xvid's 2-pass that would be another story.

"Right now the coffees are doing their final work." (Airi, Masked Rider Den-o episode 1)

Author
Time

Well xvid didn't have crf (constant rate factor), it only had cq (constant quantizer) which is not the same. x264's 2-Pass works exactly as it should, if it didn't then CRF wouldn't work either since CRF is based off the same principal as 2-Pass - that is it keeps constant quality. CQ does not... it aims to keep the quantizers to a constant level, even when a scene doesn't need it, therefore 2-Pass will give you a better quality output at the same size as CQ-based encode.

[ Scanning stuff since 2015 ]

Author
Time

Is there a way to tell MeGUI to only encode between certain frames?

e.g. encode between frame 1000 and 2000

she/her
mwah

Author
Time
 (Edited)

Molly said:  My experience is that x264's "2-pass" mode is broken and should not be used.

 What makes you say that, Molly?

clutchins said:

Is there a way to tell MeGUI to only encode between certain frames?

e.g. encode between frame 1000 and 2000

 Edit the AviSynth script that you feed MeGUI.

WhateverSource()

Trim(X,Y)

Author
Time

I say because from experience 2-pass doesn't actually appear to *do* anything with the data from the first pass - the running bitrate average is like that of a 1-pass encode.

"Right now the coffees are doing their final work." (Airi, Masked Rider Den-o episode 1)

Author
Time

I don't go there. But I've talked to other more experienced anime encoders and they almost invariably say "CRF or bust", unless you're making BDMVs.

"Right now the coffees are doing their final work." (Airi, Masked Rider Den-o episode 1)

Author
Time

All in all, unless you're willing to invest a lot of time, what you're asking isn't worth it and this thread just seems like flame-bait.

I'm not an expert, however from what I've read, just use CRF settings because multi-pass isn't necessary with more recent encoders.

For allocating less bits or custom encoding scheme just for the credits, I echo my 1st statement.

Author
Time

saying 2-pass vbr doesn't work is just silly. The first pass is solely to in depth inspect the source file and then use the data collected to find the best way to run the second pass.  

Author
Time

In theory, at least.  In practice, that's another story - I can't think of any instance where analyzing the source file should suggest the proper way to handle any file as almost CBR, which is what x264 almost universally did when I used its 2pass mode.

"Right now the coffees are doing their final work." (Airi, Masked Rider Den-o episode 1)

Author
Time

With a file I encoded not long ago I compared the bitrates and it's only slightly "more cbr" when encoded with 2-pass. That could be due to the faster first pass settings, I certainly didn't use --slow-firstpass after all. But overall does it look like CBR? No it doesn't, it looks like a proper VBR.

[ Scanning stuff since 2015 ]

Author
Time

You guys are doing multi-pass? Why, oh why? Oh wait, I'm talking many people who prefer byte bloated encodes. Doh! Just don't do it, ok!

Author
Time

Because I needed it to fit on a DVD-R.

[ Scanning stuff since 2015 ]