Difference between revisions of "User:Mjb/MP4Box"

From Offset
Jump to navigationJump to search
(PAR calculation)
 
Line 45: Line 45:
  
 
(If remainder had been, say, 5, we would be dividing 12 by 5 in the next step.)
 
(If remainder had been, say, 5, we would be dividing 12 by 5 in the next step.)
 +
 +
 +
[[Category:Video]]

Latest revision as of 03:51, 25 June 2018

MP4Box download

This is the GPAC installer. When running the installer, untick every box except the one for MP4Box. On Windows, it will put mp4box.exe and supporting files in your "%ProgramFiles(x86)%\GPAC" folder.

Command-line examples

Rewrite the PAR (pixel aspect ratio)

My input video was a YouTube rip at 1920×1080, and was 4:3 NTSC TV content that was playing back horizontally stretched. FFmpeg reports it has SAR 1:1 DAR 16:9, i.e. 1920×1080 stored image size @ 1:1 SAR = 1920×1080 displayed image size = 16:9 DAR (display aspect ratio). So I ran it through MP4Box like this:

  • mp4box -add "input.mp4" -par 1=3:4 -new "output.mp4"

FFmpeg reports output.mp4 has SAR 3:4 DAR 4:3, and indeed it plays back correctly as 4:3. Hooray!

FFmpeg numbers its streams starting with 0, but MP4Box starts at 1, hence the "1=" to say that the new PAR applies to stream 1 of the input.

PAR calculation

The "3:4" in the example above is calculated thusly:

Given the DAR of 16:9, we need to solve for x and y (the PAR) in this equation:

  • ( 16 ⁄ 9 ) × ( xy ) = 4:3

So divide both sides by 16:9:

  • ( xy ) = ( 4 ⁄ 3 ) ÷ ( 16 ⁄ 9 )

Division by a fraction is the same thing as multiplication by the inverse of that fraction:

  • ( xy ) = ( 4 ⁄ 3 ) × ( 9 ⁄ 16 )

Multiplication of two fractions is a new fraction where the top is the product of the tops, and the bottom is the product of the bottoms:

  • ( xy ) = ( 4 × 9 ) ⁄ ( 3 × 16 )
  • ( xy ) = 36 ⁄ 48

So 36:48 is the answer!

Now you can use the Euclidian algorithm to get the greatest common divisor so you can reduce 36:48 to an irreducible fraction (optional, but ideal):

  • Divide larger number by smaller one, and look at remainder: 48 ÷ 36 = 1 R 12.
  • As long as remainder is not zero, divide last divisor (bottom number) by it: 36 ÷ 12 = 3 R 0.
  • We're already done; the common divisor is 12.

Dividing 36 and 48 by 12 gives us 3 and 4, the irreducible form of 36:48. So 3:4 is the PAR we want!

(If remainder had been, say, 5, we would be dividing 12 by 5 in the next step.)