Author Topic: patch: avoid lying about mp4 dimensions  (Read 4564 times)

jicama

  • Newbie
  • *
  • Posts: 3
patch: avoid lying about mp4 dimensions
« on: March 08, 2012, 06:48:45 PM »
An MP4 file encoded via HandBrake will often have a height or width that's not a multiple of 8, due to automatic cropping.  Using Avidemux 2.6 to cut a section out of such a file results in a blocky section at the bottom and/or right side of the screen that wasn't there in the input.  This turns out to be because even though the MP4 accurately describes its own dimensions, Avidemux is rounding the dimensions up to be a multiple of 8, and so playback needs to guess about what those added pixels might be.

This patch removes that rounding.

Agent_007

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3163
Re: patch: avoid lying about mp4 dimensions
« Reply #1 on: March 08, 2012, 07:47:28 PM »
Bump this thread in next 5 days if nobody comments this thread. (so I remember to ticket this)
I am away between 15th of May - 15th of June. (yes, I am playing D3)

nibbles

  • Sr. Member
  • ****
  • Posts: 292
Re: patch: avoid lying about mp4 dimensions
« Reply #2 on: March 10, 2012, 11:48:14 AM »
Jicama I thought most codecs and color spaces dealt with 8x8 blocks of pixels, doing math on their similarities, and compressing them.  If you remove part of that 8x8 block, it can't compress along that edge, and the result is undefined.  Did I miss something interesting?

jicama

  • Newbie
  • *
  • Posts: 3
Re: patch: avoid lying about mp4 dimensions
« Reply #3 on: March 10, 2012, 02:19:52 PM »
I don't know how the codecs work, but I'd guess that when the size isn't a multiple of 8 they pad out the block with imaginary pixels for compression purposes without changing the reported size.
In any case, HandBrake is perfectly happy to create MP4s with such sizes, and players are happy to show them.

mean

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 10967
Re: patch: avoid lying about mp4 dimensions
« Reply #4 on: March 10, 2012, 03:18:23 PM »
i'll merge that when i'm back
thank!

indeed they padd the video

nibbles

  • Sr. Member
  • ****
  • Posts: 292
Re: patch: avoid lying about mp4 dimensions
« Reply #5 on: March 11, 2012, 01:55:59 AM »
I'm coming from a point of view where the addition of black borders to fill in a few missing pixels to make the height a multiple of 8 is a poor practice, because it yields a macroblock of 8x8 that contains a solid black bar mixed with normal video.  That doesn't compress well, and the result is chromatic aberration along the edge.

In this, case, what I was thinking about doesn't apply.  Handbrake is cropping at non-multiples of 8 and their encoder is not padding the output.  Avidemux wrongly figures things will be multiples of 8, even though they probably should be.  Thank you for crafting a patch.