Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > General > Newbies

Reply
 
Thread Tools Search this Thread Display Modes
Old 21st May 2013, 01:49   #1  |  Link
Alex-Kid
Antronio's DV ambassador
 
Alex-Kid's Avatar
 
Join Date: Mar 2006
Location: Santiago, Chile
Posts: 115
Advices on "hard scenes" encoding for DVD

I have a video stream (filmed with my miniDV camcorder ) that I want to encode for DVD-video. But when I try to encode it (I use HCEnc 0.26), some scenes look very ugly, especially the forest ones, which have many "textures" (Here's a sample pic). This happens even at 9200 kbps, so I made a quick encoding with these scenes to see if I was doing something wrong.

So I did a 1.00 CQ encoding with a max bitrate of 40 mbps, and realized that the "perfect" bitrate for the scenes were about 17-18 mbps. So I concluded that an acceptable quality would be around 10-12 mbps anyway, which surpasses the upper limit of DVD compliancy.

So I'm asking for tricks and hints (on filters for AVISynth, VirtualDub, etc.) to adequate the picture for a better compression and encoding, while keeping a "good watching" to the eyes.

Here's a sample vid for testing (Lagarith, 157 MB)

Thanks!
Alex-Kid is offline   Reply With Quote
Old 21st May 2013, 09:35   #2  |  Link
Warperus
Registered User
 
Join Date: Apr 2010
Location: Sain-Petersburg, Russia
Posts: 139
Just few random thoughts: deshaker, smoothing(blurring)
Warperus is offline   Reply With Quote
Old 21st May 2013, 10:34   #3  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 588
I'm not sure what you mean by textures, but if you mean the fine leaf detail that appears messed up by interlacing, that's one thing you don't need to worry about, assuming you're encoding interlaced. The hardware DVD player will take care of deinterlacing, and just make sure your software player does also.

Chances are that your camera records luma to the [16,255] range, which seems confirmed looking at the bright areas in the screen grab. Measure this with ColorYUV(analyze=true).Blur(1.0). If you see occasional values below 16, those will be legal undershoots you need not concern yourself with. RGB conversion in your workflow will clip luma to [16,235] causing clipped whites (if you want to do any processing in VirtualDub, you'd have to convert to RGB32, since VirtualDub messes up the chroma of interlaced YV12). If you take care to use the Avisynth PC conversion matrices you may avoid some of the clipping, but best is to normalise luma with something like Levels(0, 1.0, 255, 2, 235, coring=false) or ColorYUV(gain_y=-18, off_y=-2, gamma_y=0, cont_y=0). YLevels() also works. Beware that Levels() also modifies the chroma range (see the documentation). For my DV camera I use ColorYUV() - it just looks better to me.

For scenes with large difference between background and foreground exposure as in your sample screen grab, you could also try HDRAGC() and/or Local Contrast Enhancement. Do any luma and/or chroma manipulation like these after normalising levels.

PS. If you are prepared to put some effort into ensuring best encoding quality, read up and play with all HCEnc settings, one at a time*. Note which ones improve quality at the same bitrate, and intelligently combine those into your final encoding configuration.

*Note that some settings may need to be enabled by another before taking effect

Cheers,
Francois

Last edited by fvisagie; 22nd May 2013 at 12:53. Reason: Corrected "Local Contract Enhancement" to "Local Contrast Enhancement"!
fvisagie is offline   Reply With Quote
Old 21st May 2013, 12:03   #4  |  Link
Ghitulescu
Registered User
 
Ghitulescu's Avatar
 
Join Date: Mar 2009
Location: Germany
Posts: 5,769
That's the interlace "artifact".
If you don't see it on TV if you connect your camcorder to it, chances are that you won't see it from the DVD player either.
__________________
Born in the USB (not USA)
Ghitulescu is offline   Reply With Quote
Old 22nd May 2013, 06:06   #5  |  Link
Alex-Kid
Antronio's DV ambassador
 
Alex-Kid's Avatar
 
Join Date: Mar 2006
Location: Santiago, Chile
Posts: 115
No, I'm not talking about interlace artifact.

I leave you the resulting MPEG-2 file for better understanding. It's about MPEG-2 artifacts.

And here's the HCEnc INI file:
Code:
*INFILE           f:\iframe\marquez caceres\postprocessed\encode.avs
*OUTFILE          F:\Iframe\MARQUEZ CACERES\DVD1\test.m2v
*BITRATE          9200
*MAXBITRATE       9600
*FRAMES           164400 164900
*PROFILE          best
*AUTOGOP          18
*AQ               3
*DC_PREC          10
*INTERLACED
*BFF
*CLOSEDGOPS
*INTRAVLC         2
*MATRIX           mpeg
*LUMGAIN          3
Alex-Kid is offline   Reply With Quote
Old 22nd May 2013, 10:42   #6  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 588
You mean the blocking, e.g. on the backpack? That's usually from bitrate starvation. Two-pass encoding should help a lot. Beyond that, I'm not familiar with configuring HCEnc so can't help with that.

You may also find that blocking behaviour changes once you've done dynamic range corrections for luma and/or colour.
fvisagie is offline   Reply With Quote
Old 22nd May 2013, 12:28   #7  |  Link
TheSkiller
Registered User
 
Join Date: Dec 2007
Location: Germany
Posts: 632
Try a different quant matrix in HCenc. The "MPEG" matrix you are using is rather bitrate-hungry. I recommend "KVCD notch" matrix for your purpose (in HCenc this matrix is simply called "NOTCH").
You can also try other matrices, generally the higher the numbers the higher the compression but that doesn't mean a matrix with very high numbers will look good for your video...

A had a look at your video and yeah, it's definitely a very bitrate demanding one. Also your highlights are most likely clipped like fvisagie mentioned.

Edit: If you can't get rid of the blocking on the dark part of the backpack, I suggest you set "dead zone settings" to a fixed value of 1 or 2 for both.

Also I noticed the GOP structure of the video is constantly like IBPBPBP... You may be able to reduce the overall blocking by unticking "Autogop" which will result in a GOP like IBBPBBPBB... Make sure the GOP length is set to 18 frames in Settings 1.
Why are you using closed GOPs? That will eat valuable bitrate for no reason!

Last edited by TheSkiller; 22nd May 2013 at 12:45.
TheSkiller is offline   Reply With Quote
Old 28th May 2013, 20:13   #8  |  Link
Alex-Kid
Antronio's DV ambassador
 
Alex-Kid's Avatar
 
Join Date: Mar 2006
Location: Santiago, Chile
Posts: 115
First, I want to thank all your replies .

I tested several settings, following your suggestions: NOTCH matrix, dead zone settings and Autogop off with 18 frames of GOP length. Though the video is improved, it still shows many artifacts. I think I'll definitely have to smooth it a little.

About closed GOPs:
I understand this is mandatory for DVD compliancy.

About clipped whites:
I do all editing and filtering through AVISynth (with Cedocida DV codec). I only use VirtualDub for intermediate encoding (with YV12 Lagarith) and configured output and input as YV12. I never convert to RGB in my workflow. On the other hand, I already set the values for HDRAGC and NonLinUSM, but by your words, I guess it's not enough. But after all, do I check any other related settings?

In the last tests, I realized this scene doesn't demand the bitrate it needs, that means if I set a max bitrate of 9500 kbps, it's never reached in any part of the stream. Am I doing something wrong or is there something I'm not doing?
Alex-Kid is offline   Reply With Quote
Old 28th May 2013, 22:58   #9  |  Link
TheSkiller
Registered User
 
Join Date: Dec 2007
Location: Germany
Posts: 632
Quote:
Originally Posted by Alex-Kid View Post
About closed GOPs:
I understand this is mandatory for DVD compliancy.
Unless you are creating a multi angle video, open GOPs are DVD compliant and there's no point in using closed GOPs.
For chapter points you need one closed GOP before the I frame of a chapter point – in other words if you want to use chapters you need to define them in HCenc.

Quote:
Originally Posted by Alex-Kid View Post
In the last tests, I realized this scene doesn't demand the bitrate it needs, that means if I set a max bitrate of 9500 kbps, it's never reached in any part of the stream. Am I doing something wrong or is there something I'm not doing?
No, you're not doing it wrong. This is expected behaviour by HCenc, it never really hits the max bitrate.
I haven't ever tried this but maybe you can hit the desired bitrate better when using the new "1 pass VBR" mode which can be ticked in the main settings.

Edit: Tomorrow I will try and encode your sample myself.

Last edited by TheSkiller; 28th May 2013 at 23:07.
TheSkiller is offline   Reply With Quote
Old 29th May 2013, 10:23   #10  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 588
Quote:
Originally Posted by Alex-Kid View Post
About clipped whites:
I do all editing and filtering through AVISynth (with Cedocida DV codec). I only use VirtualDub for intermediate encoding (with YV12 Lagarith) and configured output and input as YV12. I never convert to RGB in my workflow. On the other hand, I already set the values for HDRAGC and NonLinUSM, but by your words, I guess it's not enough. But after all, do I check any other related settings?
According to the guys at forum.videohelp.com (see this post and the rest of pages 1 and 2 if you're interested), all displays operate in RGB, therefore at least that final conversion from YV12 to RGB will take place in your workflow. YUV values falling outside of the gamut of legal RGB values at that point will lead to clipped whites and/or crushed blacks (mostly illegal luma issues) and/or colour shifts (clipping of individual RGB channels) even for otherwise legal luma values. Although they weren't designed to, tools like HDRAGC help "a little" with reducing out-of-gamut values. However, to do a good job of preventing problems with YV12->RGB32 conversion you need to use one of the dedicated Levels(), ColorYUV() or YLevels() tools.

As mentioned, you can use ColorYUV(analyze=true).Blur(1.0) to measure the need for luma and/or chroma normalisation. Histogram("classic") and Histogram("levels") display luma and chroma values graphically.

The link above also mentions tools for checking legal YUV combinations (while Y, U and V values may be within range individually, their combination may still result in out-of-gamut RGB values). However, this is getting a little esoteric, in the sense that once normalisation e.g. Levels() and dynamic range adjustment e.g. HDRAGC() have been done, output is either within range or close to it and any remaining clipping will be hard to spot, except for the fanatic.

Last edited by fvisagie; 29th May 2013 at 10:28.
fvisagie is offline   Reply With Quote
Old 29th May 2013, 17:59   #11  |  Link
Alex-Kid
Antronio's DV ambassador
 
Alex-Kid's Avatar
 
Join Date: Mar 2006
Location: Santiago, Chile
Posts: 115
Quote:
Originally Posted by fvisagie View Post
all displays operate in RGB, therefore at least that final conversion from YV12 to RGB will take place in your workflow.
That is something I never took into account. So I must thank you for that.

By chance, last night I did some tests regarding the luma range issue and must say that it looks better. I added Ylevels(0, 1.0, 255, 2, 235) and then applied HDRAGC settings which resulted in better overall luminosity. I hope to test compression with these new values today.

However, I would like to return on the first line: Does this mean that luma range must always be stretched to the [16-235] interval? And if it does, why is low output set to 2 on the Levels settings you suggested? Shouldn't it be set to 16?

Last edited by Alex-Kid; 29th May 2013 at 19:20.
Alex-Kid is offline   Reply With Quote
Old 30th May 2013, 08:02   #12  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 588
Quote:
Originally Posted by Alex-Kid View Post
Does this mean that luma range must always be stretched to the [16-235] interval?
BT.709 and BT.601 require Y to be [16,235] and U & V to be [16,240]. Therefore many conversion mechanisms perform clipping to those values when converting between colourspaces. Clipping leads to loss of information which becomes visible as washed out whites (no gradation left) and crushed blacks (also no gradation). One way to avoid that is normalising to valid ranges as we're discussing here. Another way is to 1) use the Avisynth PC matrices when converting, 2) set the coring option to false wherever available and 3) hope that your display can handle the out-of-range values. See the Avisynth 2.6.0 ConvertTo...() and Levels() documentation for information on TV/PC matrices and coring.

Quote:
And if it does, why is low output set to 2 on the Levels settings you suggested? Shouldn't it be set to 16?
This post explains why.

By the way, do yourself the favour of comparing Levels() and ColorYUV() before deciding which to use. Levels() also shrinks the chroma range, unnecessarily in the case of my DV footage that has valid chroma. With ColorYUV() and YLevels() you can operate on luma alone. The effect on my footage of ColorYUV() + HDRAGC() is far more attractive than Levels() + HDRAGC(), no matter how I tweak Levels or HDRAGC to try compensate.

Cheers,
Francois
fvisagie is offline   Reply With Quote
Old 30th May 2013, 11:58   #13  |  Link
TheSkiller
Registered User
 
Join Date: Dec 2007
Location: Germany
Posts: 632
Simply using the PC matrix will result in washed out blacks (unless the camcorder stores black at 0 which I highly doubt any camcorder does).
The issue is simply the camcorder stores it's whitest white at 255 because it doesn't need to bother compressing it to 235 or clipping it.
You don't have to fix that, but it's advisable to do to make sure the video looks the same regarless of where it is played back.

Whether you use
Code:
Levels(0, 1.0, 255, 2, 235, false)
or
Code:
Levels(16, 1.0, 255, 16, 235, false)
to do that doesn't matter. The latter will clip anything below 16 but since there shouldn't be anything to begin with it doesn't matter. I always use the latter for my own camcorder videos but I recommend to use SmoothLevels() instead of Levels() or YLevels() because they create rounding errors which result in posterization.


Quote:
Originally Posted by fvisagie View Post
With ColorYUV() and YLevels() you can operate on luma alone.
Alternatively you can wrap Levels() inside MergeLuma() or MergeChroma() to affect only the luma.
Example
Code:
MergeChroma(Levels(16, 1.0, 255, 16, 235, false), last)
Edit: SmoothLevels() even has an option, chroma=0, to process only the luma.

Last edited by TheSkiller; 30th May 2013 at 12:05.
TheSkiller is offline   Reply With Quote
Old 31st May 2013, 07:06   #14  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 588
Quote:
Originally Posted by TheSkiller View Post
Simply using the PC matrix will result in washed out blacks
Are you sure that's what you meant? Can you show an example? As I understand it, the whole point behind behind using PC matrices (and coring=false) is to directly map [0,255] to [0,255], therefore none of the grey balance shifting that you mention.

PS.
Quote:
Originally Posted by TheSkiller View Post
Code:
Levels(16, 1.0, 255, 16, 235, false)
... The latter will clip anything below 16 but since there shouldn't be anything to begin with it doesn't matter.
While generally true preferences may vary. My camera, for instance, produces perfectly legal undershoot in dark scenes and clipping that visibly reduces accentuation. Alex-Kid may want to play around with some dark clips before deciding which handling is preferred for his camera.

Last edited by fvisagie; 31st May 2013 at 08:14.
fvisagie is offline   Reply With Quote
Old 10th June 2013, 23:46   #15  |  Link
Alex-Kid
Antronio's DV ambassador
 
Alex-Kid's Avatar
 
Join Date: Mar 2006
Location: Santiago, Chile
Posts: 115
Thanks fvisagie & TheSkiller, your posts helped me a lot.

But I have to say I give up with MPEG-2 DVD encoding. Though the video has been enhanced, the encoding artifacts are still there, even with "close-to-top" bitrate, and I ran out of ideas to increase compressibility without hurting quality too much. The best results I got was using x264 encoder.

Maybe the video still have some issues that can affect MPEG-2 encoding. Maybe noise, contrast, sharpness, etc., but at this point I feel I got stuck. I think this has became very challenging and it would be good that someone can use the sample posted some time ago and do the appropriate video processing to get a good MPEG-2 DVD encoding.
Alex-Kid is offline   Reply With Quote
Old 11th June 2013, 07:23   #16  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 588
Unfortunately I have very little experience with HCenc. In case you would like to compare results, these are the two-pass ffmpeg command lines I use for DVD MPEG-2 encoding ('-top 0' = BFF):
Code:
ffmpeg -y -top 0 -async 0 -i input.avi -muxrate 10080000 -acodec ac3 -ab 128000 -flags ildct+ilme+mv0 -g 15 -mbd 2 -trellis 1 -bufsize 1835000 -strict 0 -bf 2 -b_strategy 1 -mbcmp 6 -preme 2 -precmp 2 -pre_dia_size 2 -cmp 2 -dia_size 2 -subcmp 6 -last_pred 2 -mv0_threshold 0 -maxrate 9000000 -vcodec mpeg2video -b:v 6090000 -pass 1 output.mpg
ffmpeg -y -top 0 -async 0 -i input.avi -muxrate 10080000 -acodec ac3 -ab 128000 -flags ildct+ilme+mv0 -g 15 -mbd 2 -trellis 1 -bufsize 1835000 -strict 0 -bf 2 -mbcmp 6 -preme 2 -precmp 2 -pre_dia_size 2 -cmp 2 -dia_size 2 -subcmp 6 -last_pred 2 -mv0_threshold 0 -maxrate 9000000 -vcodec mpeg2video -b:v 6090000 -pass 2 output.mpg
(In case anyone wonders, I'm not using '-target pal-dvd' because it has a shortcoming - it forcibly scales 704x480/576 to 720x480/576.)
fvisagie is offline   Reply With Quote
Old 15th June 2013, 11:57   #17  |  Link
TheSkiller
Registered User
 
Join Date: Dec 2007
Location: Germany
Posts: 632
Quote:
Originally Posted by Alex-Kid View Post
I think this has became very challenging and it would be good that someone can use the sample posted some time ago and do the appropriate video processing to get a good MPEG-2 DVD encoding.
Sorry for the long delay.
I did some encoding tests with your sample. In addition to HCenc I also used ProCoder – as to be expected with this particular kind of video ProCoder delivers the least artefacts and most pleasant to look at video (of course fully DVD compliant).


The script I used was very basic, I just corrected the levels so that the luma is in the 16-235 range. Interestingly the brightest white in your video is not at 255 but rather around 243. There also is stuff below 16 which seems to come from the camcorder's contouring (edge enhancement) overshooting, i.e. it's not important and can/should be clipped.
So I used this
Code:
SmoothLevels(16,1,243, 16,235, chroma=0, limiter=2)
I would love to upload to MediaFire but they require an account these days which bugs me so I used another hoster...

ProCoder 1.5 result (mastering quality setting):
http://www28.zippyshare.com/v/84023600/file.html

HCenc_026_beta result:
http://www67.zippyshare.com/v/24331625/file.html

As you can see there is a small improvement over your own HCenc encoded version due to better settings but compared to ProCoder there's a huge difference. Every encoder has it's strong and weak sides. I'm afraid to say it but with this kind of video HCenc is being pushed over the edge. If it's of any consolation to you I can assure you that ProCoder looks rather bad with other kinds of video material.

HCenc settings
Code:
*INFILE           c:\neu avisynth script (6).avs
*OUTFILE          C:\test_hcenc.m2v
*BITRATE          9600
*MAXBITRATE       9600
*FRAMES           0 499
*PROFILE          best
*GOP              18 2
*AQ               4
*DEADZONE         0 1
*INTERLACED
*BFF
*INTRAVLC         2
*MATRIX           hclow
*LUMGAIN          1
*WAIT             0

Last edited by TheSkiller; 15th June 2013 at 12:31.
TheSkiller is offline   Reply With Quote
Old 18th June 2013, 07:06   #18  |  Link
Alex-Kid
Antronio's DV ambassador
 
Alex-Kid's Avatar
 
Join Date: Mar 2006
Location: Santiago, Chile
Posts: 115
@TheSkiller: thank you!

I watched the two samples and I must say that both look great, but Procoder's looks better.

I used Procoder some time ago, but I found that the output was too soft. And now that is an advantage!

On these days I tested HCEnc with a little softer input (used Unfilter, didn't test any others) but didn't like the output.

I think I'll follow your advice
Alex-Kid is offline   Reply With Quote
Reply

Tags
advices, dvd, hard, scenes

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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

Forum Jump


All times are GMT +1. The time now is 11:15.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.