axiomatic-systems / Bento4

Full-featured MP4 format, MPEG DASH, HLS, CMAF SDK and tools
http://www.bento4.com
1.93k stars 478 forks source link

mp4mux: How to set frame rate to 59.940 (60000/1001) instead of 59.940 (59940/1000) #829

Open nilaoda opened 1 year ago

nilaoda commented 1 year ago

After mux with mp4mux, video frame rate changed to 59.940 (59940/1000).

mp4mux.exe --track "h265:638110311955762453.hevc#dv_profile=5,frame_rate=59.94" "638110311955762453.hevc.mp4"

Mediainfo:

Frame rate                               : 59.940 (59940/1000) FPS
Original frame rate                      : 59.940 (60000/1001) FPS
barbibulle commented 1 year ago

Hi. When you specify frame_rate=59.94 as an argument, the mp4mux app will use that value to set the frame rate, regardless of what's in the input. The value 60000/1001, is actually 59.94005994005994... in decimal, not 59.94. Also, the notion of frame rate for an mp4 file is not a well-defined notion, as technically each frame can have a duration independent of the other frames. This is why, for example, when you use mp4info, it will show you the frame rate as a frame rate (computed) value, where it divides the media duration by the number of frames and infers an average frame rate. There's no 'frame rate' header per-se. So, the question here is: which notion of 'frame rate' are you interested in? (the one that can be inferred from the duration and number of frames), or some other metadata? I'm not sure what the 59.940 (60000/1001) FPS in your example refers to (what tool is used to print that, what notion of frame rate is it using?).

nilaoda commented 1 year ago

@barbibulle Thanks for response, I just test Dolby Vision remux using mp4mux.

MP4 File: http://media.developer.dolby.com/DolbyVision_Atmos/mp4/iOS_P5_GlassBlowing2_3840x2160%4059.94fps_15200kbps.mp4

My workflow:

Check info with mediainfo:

MediaInfo.exe iOS_P5_GlassBlowing2_3840x2160@59.94fps_15200kbps.mp4
General
Complete name                            : iOS_P5_GlassBlowing2_3840x2160@59.94fps_15200kbps.mp4
Format                                   : MPEG-4
Format profile                           : Base Media / Version 2
Codec ID                                 : mp42 (mp42/isom/iso5)
File size                                : 331 MiB
Duration                                 : 2 min 58 s
Overall bit rate                         : 15.6 Mb/s
Encoded date                             : UTC 2020-10-06 22:26:52
Tagged date                              : UTC 2020-10-06 22:26:52

Video
ID                                       : 1
Format                                   : HEVC
Format/Info                              : High Efficiency Video Coding
Format profile                           : Main 10@L5.1@Main
HDR format                               : Dolby Vision, Version 1.0, dvhe.05.09, BL+RPU
Codec ID                                 : dvh1
Duration                                 : 2 min 55 s
Bit rate                                 : 15.2 Mb/s
Width                                    : 3 840 pixels
Height                                   : 2 160 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 59.940 (60000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 10 bits
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.031
Stream size                              : 317 MiB (96%)
Default                                  : Yes
Alternate group                          : 1
Color range                              : Full
Codec configuration box                  : hvcC+dvcC

Audio
ID                                       : 2
Format                                   : E-AC-3 JOC
Format/Info                              : Enhanced AC-3 with Joint Object Coding
Commercial name                          : Dolby Digital Plus with Dolby Atmos
Format settings                          : Dolby Surround EX
Codec ID                                 : ec-3
Duration                                 : 2 min 58 s
Bit rate mode                            : Constant
Bit rate                                 : 640 kb/s
Channel(s)                               : 6 channels
Channel layout                           : L R C LFE Ls Rs
Sampling rate                            : 48.0 kHz
Frame rate                               : 31.250 FPS (1536 SPF)
Compression mode                         : Lossy
Stream size                              : 13.6 MiB (4%)
Service kind                             : Complete Main
Default                                  : Yes
Alternate group                          : 2
Complexity index                         : 16
Number of dynamic objects                : 15
Bed channel count                        : 1 channel
Bed channel configuration                : LFE

and mp4info:

mp4info.exe iOS_P5_GlassBlowing2_3840x2160@59.94fps_15200kbps.mp4
File:
  major brand:      mp42
  minor version:    1
  compatible brand: mp42
  compatible brand: isom
  compatible brand: iso5
  fast start:       yes

Movie:
  duration:   178112 (media timescale units)
  duration:   178112 (ms)
  time scale: 1000
  fragments:  yes

Found 2 Tracks
Track 1:
  flags:        7 ENABLED IN-MOVIE IN-PREVIEW
  id:           1
  type:         Video
  duration: 175008 ms
  language: und
  media:
    sample count: 0
    timescale:    60000
    duration:     0 (media timescale units)
    duration:     0 (ms)
    bitrate (computed): 15185.007 Kbps
    sample count with fragments: 10490
    duration with fragments:     10500490
    duration with fragments:     175008 (ms)
  display width:  3840.000000
  display height: 2160.000000
  Sample Description 0
    Coding:       dvh1 (Dolby Vision (H.265))
    Codec String: dvh1.05.09
    HEVC Profile Space:       0
    HEVC Profile:             2 (Main 10)
    HEVC Profile Compat:      20000000
    HEVC Level:               5.1
    HEVC Tier:                0
    HEVC Chroma Format:       1 (4:2:0)
    HEVC Chroma Bit Depth:    10
    HEVC Luma Bit Depth:      10
    HEVC Average Frame Rate:  0
    HEVC Constant Frame Rate: 0
    HEVC NALU Length Size:    4
    HEVC Sequences:
      {
        Array Completeness=1
        Type=32 (VPS_NUT - Video parameter set)
        40010c01ffff022000000300b0000003000003009998903000003e90000ea605
      }
      {
        Array Completeness=1
        Type=33 (SPS_NUT - Sequence parameter set)
        420101022000000300b00000030000030099a001e020021c4d94626491b6bc05b81010102000007d20001d4c0c25bdefc00073f78000e7ef10
      }
      {
        Array Completeness=1
        Type=34 (PPS_NUT - Picture parameter set)
        4401c1625b981ed9
      }
    Width:       3840
    Height:      2160
    Depth:       24
    Dolby Vision:
      Version:     1.0
      Profile:     dvhe.stn
      Level:       9
      RPU Present: true
      EL Present:  false
      BL Present:  true
      BL Signal Compatibility ID:  0
Track 2:
  flags:        7 ENABLED IN-MOVIE IN-PREVIEW
  id:           2
  type:         Audio
  duration: 178112 ms
  language: und
  media:
    sample count: 0
    timescale:    48000
    duration:     0 (media timescale units)
    duration:     0 (ms)
    bitrate (computed): 640.000 Kbps
    sample count with fragments: 5566
    duration with fragments:     8549376
    duration with fragments:     178112 (ms)
  Sample Description 0
    Coding:       ec-3 (Dolby Digital Plus (Enhanced AC-3))
    Codec String: ec-3
    Sample Rate: 48000
    Sample Size: 16
    Channels:    2
    E-AC-3 Data Rate: 640
    E-AC-3 Substream 0:
        fscod       = 0
        bsid        = 16
        bsmod       = 0
        acmod       = 7
        lfeon       = 1
        num_dep_sub = 0
        chan_loc    = 0
    Dolby Digital Plus with Dolby Atmos: Yes
    Dolby Atmos Complexity Index: 16
    E-AC-3 dec3 payload: [1400200f000110]

Extract ES:

ffmpeg -i iOS_P5_GlassBlowing2_3840x2160@59.94fps_15200kbps.mp4 -c copy v.hevc
MediaInfo.exe v.hevc
General
Complete name                            : v.hevc
Format                                   : HEVC
Format/Info                              : High Efficiency Video Coding
File size                                : 317 MiB

Video
Format                                   : HEVC
Format/Info                              : High Efficiency Video Coding
Format profile                           : Main 10@L5.1@Main
Width                                    : 3 840 pixels
Height                                   : 2 160 pixels
Display aspect ratio                     : 16:9
Frame rate                               : 59.940 (60000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 10 bits
Color range                              : Full

Mux with mp4mux

mp4mux --track "h265:v.hevc#dv_profile=5,frame_rate=59.94" "v.hevc.mp4"
MediaInfo.exe v.hevc.mp4
General
Complete name                            : v.hevc.mp4
Format                                   : MPEG-4
Format profile                           : Base Media / Version 2
Codec ID                                 : mp42 (isom/mp42/dvh1/dby1)
File size                                : 317 MiB
Duration                                 : 2 h 54 min
Overall bit rate                         : 254 kb/s
Encoded date                             : UTC 2023-02-06 02:49:17
Tagged date                              : UTC 2023-02-06 02:49:17

Video
ID                                       : 1
Format                                   : HEVC
Format/Info                              : High Efficiency Video Coding
Format profile                           : Main 10@L5.1@Main
HDR format                               : Dolby Vision, Version 1.0, dvhe.05.09, BL+RPU
Codec ID                                 : dvh1
Duration                                 : 2 h 54 min
Source duration                          : 2 min 55 s
Bit rate                                 : 237 kb/s
Width                                    : 3 840 pixels
Height                                   : 2 160 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 59.940 (59940/1000) FPS
Original frame rate                      : 59.940 (60000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 10 bits
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.000
Stream size                              : 296 MiB (93%)
Source stream size                       : 317 MiB (100%)
Color range                              : Full
Codec configuration box                  : hvcC+dvcC
mp4info.exe v.hevc.mp4
File:
  major brand:      mp42
  minor version:    1
  compatible brand: isom
  compatible brand: mp42
  compatible brand: dvh1
  compatible brand: dby1
  fast start:       yes

Movie:
  duration:   628142458 (media timescale units)
  duration:   10479520 (ms)
  time scale: 59940
  fragments:  no

Found 1 Tracks
Track 1:
  flags:        7 ENABLED IN-MOVIE IN-PREVIEW
  id:           1
  type:         Video
  duration: 10479520 ms
  language: und
  media:
    sample count: 10490
    timescale:    59940
    duration:     10490000 (media timescale units)
    duration:     175008 (ms)
    bitrate (computed): 15182.088 Kbps
  display width:  3840.000000
  display height: 2160.000000
  frame rate (computed): 59.940
  Sample Description 0
    Coding:       dvh1 (Dolby Vision (H.265))
    Codec String: dvh1.05.09
    HEVC Profile Space:       0
    HEVC Profile:             2 (Main 10)
    HEVC Profile Compat:      20000000
    HEVC Level:               5.1
    HEVC Tier:                0
    HEVC Chroma Format:       1 (4:2:0)
    HEVC Chroma Bit Depth:    8
    HEVC Luma Bit Depth:      8
    HEVC Average Frame Rate:  0
    HEVC Constant Frame Rate: 0
    HEVC NALU Length Size:    4
    HEVC Sequences:
      {
        Array Completeness=1
        Type=32 (VPS_NUT - Video parameter set)
        40010c01ffff022000000300b0000003000003009998903000003e90000ea605
      }
      {
        Array Completeness=1
        Type=33 (SPS_NUT - Sequence parameter set)
        420101022000000300b00000030000030099a001e020021c4d94626491b6bc05b81010102000007d20001d4c0c25bdefc00073f78000e7ef10
      }
      {
        Array Completeness=1
        Type=34 (PPS_NUT - Picture parameter set)
        4401c1625b981ed9
      }
    Width:       3840
    Height:      2160
    Depth:       24
    Dolby Vision:
      Version:     1.0
      Profile:     dvhe.stn
      Level:       9
      RPU Present: true
      EL Present:  false
      BL Present:  true
      BL Signal Compatibility ID:  0

Both Duration and Frame rate are different with source?