Author Topic: Filter "Add Borders" decreases output quality?  (Read 2106 times)

guju

  • Newbie
  • *
  • Posts: 38
Filter "Add Borders" decreases output quality?
« 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?

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 3404
Re: Filter "Add Borders" decreases output quality?
« Reply #1 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"?

guju

  • Newbie
  • *
  • Posts: 38
Re: Filter "Add Borders" decreases output quality?
« Reply #2 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.

dosdan

  • Full Member
  • ***
  • Posts: 157
Re: Filter "Add Borders" decreases output quality?
« Reply #3 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.

guju

  • Newbie
  • *
  • Posts: 38
Re: Filter "Add Borders" decreases output quality?
« Reply #4 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.

mean

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 10974
Re: Filter "Add Borders" decreases output quality?
« Reply #5 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

guju

  • Newbie
  • *
  • Posts: 38
Re: Filter "Add Borders" decreases output quality?
« Reply #6 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?
« Last Edit: January 21, 2019, 10:10:29 AM by guju »

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 3404
Re: Filter "Add Borders" decreases output quality?
« Reply #7 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.

guju

  • Newbie
  • *
  • Posts: 38
Re: Filter "Add Borders" decreases output quality?
« Reply #8 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?

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 3404
Re: Filter "Add Borders" decreases output quality?
« Reply #9 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.
« Last Edit: January 21, 2019, 11:19:27 AM by eumagga0x2a »

guju

  • Newbie
  • *
  • Posts: 38
Re: Filter "Add Borders" decreases output quality?
« Reply #10 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 ...

guju

  • Newbie
  • *
  • Posts: 38
Re: Filter "Add Borders" decreases output quality?
« Reply #11 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 ...)

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 3404
Re: Filter "Add Borders" decreases output quality?
« Reply #12 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.

guju

  • Newbie
  • *
  • Posts: 38
Re: Filter "Add Borders" decreases output quality?
« Reply #13 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 ...

guju

  • Newbie
  • *
  • Posts: 38
Re: Filter "Add Borders" decreases output quality?
« Reply #14 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.