Avidemux Forum

Avidemux => Windows => Topic started by: guju on January 20, 2019, 05:42:41 PM

Title: Filter "Add Borders" decreases output quality?
Post by: guju on January 20, 2019, 05:42:41 PM
I take a movie, crop it to something only near (!) to 4:3,
set that DAR in stream and container, save as hevc.
Then play that and output a frame.

Then again in Avidemux I add borders above and below (2 x 6 pixels)
to make the frame dimension match exactly the DAR of 4:3.
Result:
The output frames have noticeably less details compared to the ones
from the non-DAR movie.

Can someone please explain that to me?
If anything at all, I would have expected the non-DAR frames being worse.
How can the addition of horizontal (!) borders decrease the overall quality?
Title: Re: Filter "Add Borders" decreases output quality?
Post by: eumagga0x2a on January 20, 2019, 11:16:26 PM
Each generation of lossy compression worsens the quality. The question should have been, if you don't apply any video filters and simply re-encode the video a second time, does the unfiltered output video exhibit a significantly better quality than with filters like "Add Borders"?
Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 20, 2019, 11:37:01 PM
The answer to your question is "Yes".

... as you got me wrong.
I did not take the result of the first as input of the second.

Starting point of BOTH was a cropped movie.
Test A is to save as-is, test B is to do "Add Border" before saving.
I saved it as hevc.
Loaded that movies into MPC-HC and let it export a single frame.

Frame of B is less detailed.
Title: Re: Filter "Add Borders" decreases output quality?
Post by: dosdan on January 21, 2019, 01:20:36 AM

Starting point of BOTH was a cropped movie.
Test A is to save as-is, test B is to do "Add Border" before saving.
I saved it as hevc.
Loaded that movies into MPC-HC and let it export a single frame.

Frame of B is less detailed.

Was the BPF, Bits/(Pixel*Frame), as reported by MediaInfo, similar for encoded clips A & B?

Dan.
Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 21, 2019, 09:42:35 AM
My MediaInfo (v18.03) doesn't report BPF for HEVC streams.
Still (on a 15s example) the borderless A strip is 5% larger (!)
than the one with added border (DAR exact 4:3).

However I didn't change encoding settings between A and B.

Strange enough today I have problems to reproduce the results,
although with all settings the same than yesterday (border-size etc.).
Today the frame contents are only different.
Yesterday the bordered movie was definitely worse/ less detailed.
Title: Re: Filter "Add Borders" decreases output quality?
Post by: mean on January 21, 2019, 09:50:13 AM
If the border size is not a multiple of 8 or 16, it will take a lot of bits to encode, hence worsening the quality at a given size
Additionally, the encoder presets are a good compromise between speed & quality
You can tweak them to increase quality, with a longer encoding time
Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 21, 2019, 10:07:47 AM
I have to ask.
Do you mean, mean, "border size" or "frame size"?

Actually the reason for me to add border was to match the set DAR of 4:3.
I knew already that some encoders (older ones) have a restriction in frame sizes.
Although I thought hevc would be free at that.
Still I chose a width as multiple of 8,
the height of non-bordered (A) is too,
the bordered is not, as I thought not too important.

But all this doesn't have anything to do with the loss of detail, if bordered ...

Or do I get something wrong?
Title: Re: Filter "Add Borders" decreases output quality?
Post by: eumagga0x2a on January 21, 2019, 10:33:01 AM
All dimensions should be a multiple of 8, better a multiple of 16, for better compressibility. Otherwise higher bitrates are required to keep the quality more or less the same.
Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 21, 2019, 10:46:41 AM
As said, the width was always a multiple of 8.

The height of non-bordered was too.
With added border (2 * 6), to meet DAR (4:3), its height was not.

Still, the non-bordered (multiple-conform) movie was larger.

I left the hevc encoding settings the same (standard config, preset "medium", quality 19)
and expected the same quality, with a larger file of bordered (as non-multiple).
But the opposite was the case !?


... a short addendum (although not exactly about the topic in this thread):

If I have a movie, whose size is multiple of 8 (or 16) minus say 6.

Why doesn't the Add-Border-filter let me add 2 * 3 pixels left and right
to meet the multiple restriction?
Title: Re: Filter "Add Borders" decreases output quality?
Post by: eumagga0x2a on January 21, 2019, 11:17:13 AM
The function which paints black stripes needs even values, it can't paint 3px. Don't forget that chroma has 1/2 resolution of luma, so the color information of a 720px wide and 576px high picture is only 360x288. You can't divide 3 by 2 without a remainder.
Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 21, 2019, 03:09:48 PM
All dimensions should be a multiple of 8, better a multiple of 16, for better compressibility. Otherwise higher bitrates are required to keep the quality more or less the same.

ALL dimensions?
I would have thought that this holds only for the width ...
Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 22, 2019, 11:19:52 AM
Meanwhile I reproduced the effect of detail-loss when AddBorder.
To sum it up again:
Saving a movie as hevc (DAR 4:3 in stream and container).
First scenario: 1456 x 1080 (= slightly off DAR).
Second scenario: Add Border (2 x 6) to match DAR: 1456 x 1092.
Export Frames.
Result: Second one is slightly less detailed.
If I enhance encoding quality (from 19 to 17) in second scenario it gets better.

Question:
Why decreases AddBorder the quality?
(1092 not being a multiple of 8 should only effect the compression effiency
but not the quality, to my thinking ...)
Title: Re: Filter "Add Borders" decreases output quality?
Post by: eumagga0x2a on January 22, 2019, 04:33:56 PM
All dimensions should be a multiple of 8, better a multiple of 16, for better compressibility. Otherwise higher bitrates are required to keep the quality more or less the same.

ALL dimensions?

Yes.

Quote
Why decreases AddBorder the quality?

(1092 not being a multiple of 8 should only effect the compression effiency
but not the quality, to my thinking ...)

I don't know the former as it is related to internal working of the x265 encoder and I'm not sure about the latter for the same reason.
Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 22, 2019, 06:26:08 PM
OK then, thankyou.

I'm a little bit on the loss now.

As increasing the hevc encoding quality to better than 19 actually leads to unaccetable compression time (and size).

And I only tried to do it right, when adding borders to match DAR ...
Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 22, 2019, 06:57:35 PM
... did another test then:

Increased border (to 1472 x 1104) to match not only DAR but also to be multiples of 8.

Frames are still less detailed.
Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 22, 2019, 08:57:46 PM
... made the same test with AVC1.

With that the "bordered" one is also less detailed.
But the difference between bordered or not is not as significant as with hevc comparisons

BTW:
Everything with quality crf = 19 I compared that to the hevc version.
Hevc should be much better with that, as the lowest meanigful value
is 18 for avc1 and 24 for hevc.
Well, coding with hevc took about double as long, and produced a half-sized file, BUT ...
... the quality is worse then with avc1.
So ... maybe something wrong with the version, config of Avidemux' hevc?

Anyone has a clue for all of that?
Title: Re: Filter "Add Borders" decreases output quality?
Post by: AQUAR on January 23, 2019, 05:08:59 AM
HEVC encodes more effectively than AVC.

If you halved the file size then you have also halved the bit rate.
At half the bit rate you are just about at the limit of what HEVC can do to maintain the same quality obtained by AVC.

You get a better result at the same bit rate or
Same result with a lower bit rate.
Or you need to fully optimise your settings in HEVC to get a near equivalent result (2 pass encoding!).

That said many prefer to use AVC for 1080P encodes.

Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 23, 2019, 08:41:40 AM
No, sorry, you got me wrong.

I did not "halve the bitrate".
I set the same option for quality (crf) for both avc and hevc.

As expected: more time for compression and smaller file size.
One would expect a better quality. But the opposite was the case.
One would expect comparable quality when add border. But it wasn't.
If the standard options of hevc do not suffice, and a "fully optimization"
should me necessary ... then hevc would be quite useless.

So to me it seems as if there is something wrong with hevc in Avidemux.
Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 23, 2019, 09:19:14 AM
... checked hevc in a different "host" (VirtualDub2).

Comparison within VirtualDub2:
Add Border leads to only very slightly worse frames ... if at all.

Comparision between Avidemux and VirtualDub2 (border-less):
very similar quality.
Title: Re: Filter "Add Borders" decreases output quality?
Post by: fish on January 23, 2019, 01:35:01 PM
No re-encode you can do will give 'better' quality, every re-encode tends to discard some detail from each frame, unless you go to a lossless codec but of course this tends to be an intermediate step, mainly for the purpose of adding effects, the result must then be recompressed.  Part of what HEVC  does to attain better compression is to cleverly discard  more detail in a way that will not be noticed when casually viewing the video.
If you resize the video by re-encoding, so that the same whole image of each frame doesn't fit exactly into an identical 8x8 or 16x16  grid pattern, then you are going to lose quite a bit of detail, the more movement and detail in each frame, the more you will lose from that frame.
Personally I have never seen a good reason for using HEVC. The encoding times have always been many times longer than can be justified by file size savings and the 'quality' may well be slightly worse than for example x264.

What is the original video and what is the result you desire?
Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 23, 2019, 02:43:12 PM
Must be the (third?) time in this thread, that I have to make clear, that I'm not about consecutive (de-)coding steps.
I have the simple task to crop an original movie, and have to take care of DAR (that's because I have to add horiz. borders).
I made the observation that when adding borders the quality of the result is worse is if not adding them.
Still I cannot do without adding borders as the viewing would be distorted then (or I would have to cut off vertical contents).

Your explanation gives me hint why this happen ("identical 8x8 or 16x16 pattern"), as my added border is 6 above and below.
(BTW: The original codec is AVC).

So there seem to be a lot of restraints to fullfil if cropping/ add border:
DAR, dimensions as multiple, adding/ cropping as multiple.
(An argument for helping/ preventing the user in the filter GUI ... see my proposal in that thread).

Moreover your experience about AVC vs HEVC was new to me.
I thought HEVC to be an improvement.
But it more seems to be (literally) eyewashing.
(And already the successor is in the tube ...).

OK then, the conclusion for me:
From now on no HEVC.
And every cropping, adding border as an exercise of discret algebra
(as long as the crop filter doesn't support).

Thankyou again  :)
Title: Re: Filter "Add Borders" decreases output quality?
Post by: fish on January 23, 2019, 04:58:03 PM
I have asked you twice what you are trying to do because you don't tell us. I can assume from what you do tell us that you MIGHT be taking a 16:9 or widescreen video and fitting it into a 4:3 format, hence the black bar padding top and bottom, am I getting warm?
As for HEVC, my computer is built round a very early i7 processor, which is hardly cutting edge and the graphics card isn't up to much either, so maybe a more up to date computer and graphics card that helps with the encoding, would show better results with HEVC encoding.
Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 23, 2019, 05:10:53 PM
... so maybe a more up to date computer and graphics card that helps with the encoding, would show better results with HEVC encoding.

No.
If my conjecture is right, than a quicker hw would purely deliver results quicker.
Bad results ... no matter how demanding you choose crf parameter.
Still I wonder, as it is said that from a certain quality crf the results would be "transparent".

I don't know.
Strange world.
Jack, Zack, I cannot to swim!
Title: Re: Filter "Add Borders" decreases output quality?
Post by: fish on January 23, 2019, 05:29:51 PM
From what you tell us the original video may be already heavily compressed and then you are cropping it, which will cause most of the content in each block of each frame to change slightly when re-encoded, that is likely to make things a lot worse than simply re-encoding without cropping.
Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 23, 2019, 05:40:58 PM
The starting (from both: non added border and added border) is the same.
Whatever it comes from, whatever compressed it is.
It does not matter.
Than I hevc saved them.
(4th time if I counted right).

But your explanation (if right) tells why there is that quality difference:
The add border is not of multiple of 8 or sweet 16 (if you know what I mean).
Title: Re: Filter "Add Borders" decreases output quality?
Post by: eumagga0x2a on January 23, 2019, 06:35:04 PM
The question how encoder react to specific changes in the source video like scaling, cropping or adding borders is surely interesting but also very academic. The best practices are to avoid all of them whenever possible.
Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 23, 2019, 07:52:07 PM
I don't have in mind to resume this topic endlessly ...  ;) ... still: I've to contradict.

It's not academic.

If I'm not completely wrong then Avidemux is for manipulating movies?
And if you have to (for whatever reason) manipulate it,
it's anything but academic to know the pitfalls to avoid.
Don't you agree?

And for me (being a normal user with some knowledge here and there, but no prof)
there were many effects/ restrictions I learned in this thread about I never expected.
And it is not academic if your resulting video has bad quality
when you only used some "harmless" manipulations.
Not paying attention to some things one does not know.
(As I posted former, to my opinion most users will simply use Avidemux
without noticing the degradation of quality, as they don't have the time
to have an as close look as I did this time.)

What was I about to say ...?

Thankyou!  :)

Title: Re: Filter "Add Borders" decreases output quality?
Post by: guju on January 24, 2019, 10:52:12 AM
... my experiences with AVC codec and adding border/ cropping.

When I dropped hevc coder (as its enhanced compression ratio
takes too much quality for my taste) I examined the effect
of cropping/ adding border in AVC.

There is no significant difference in quality if I set the
cropping/ add border on multiple of 8.
(The starting point is - as always - an AVC coded movie).

If one would expect the compression being better, when on
the 8-multiple: it wasn't, but the opposite. The "8-multiple" file
was slightly larger (due to the slightly larger frame dimensions I suppose).

Best quality was when not adding border.
But I had to to meet DAR.

So for me it's clear how to do up from now ...


BTW (as I was asked), why all this?
I got some older movies, AVC-coded and with format 16:9.
However there were large black borders encoded in,
as the actual content was about 4:3.
So it was my idea to reduce file size by cropping the black
and setting the DAR to 4:3.
With AVC now (crf = 18, "slower" encoding mode)
the file size is about 70%.
HEVC would reduce of more than another 50% (but with the
- for me - unacceptable degradation of the single frames.
Maybe - as it was stated by fish - not so much when "only"
watching the movie/ changing frames.)