custom ffmpeg produces vfr on mkv and cfr on mp4 with same encoder settings

Hi.
I use custom ffmpeg with h264/aac inside.
if I use mkv as container the video stream is variable frame rate 62.5 fps if i use mp4 with the same settings (just switching container)
it is constant framerate 60 like it should.

there is no change if i remux mkv records to mp4 it stays vfr.

if I use the "normal" output and chose mkv, it is also cfr just like mp4
so it has something to do with custom ffmpg in combination with mkv container.
 

Suslik V

Active Member
Some useful info about the CFR (constant frame rate) in mkv vs mp4 containers, and remux:

Edit:
in general, encoding is already VFR (variable frame rate) no matter what container you choose. But actually, it is very small deviation from the average value. And usually, it shouldn't cause huge problems for edit.
I misread your report. You have mkv with VFR. Sorry.
 
Last edited:

rockbottom

Active Member
I'm not seeing that behavior anymore with v28.0.1.

AAC

Format :Matroska
Format version :Version 4
File size :10.1 MiB
Duration :9 s 770 ms
Overall bit rate mode :Variable
Overall bit rate :8 706 kb/s
Writing application :Lavf59.16.100
Writing library :Lavf59.16.100
ErrorDetectionType :Per level 1

Video​

ID :1
Format :AVC
Format/Info :Advanced Video Codec
Format profile :Main@L5
Format settings :CABAC / 8 Ref Frames
Format settings, CABAC :Yes
Format settings, Reference frames :8 frames
Format settings, GOP :M=1, N=30
Codec ID :V_MPEG4/ISO/AVC
Duration :9 s 250 ms
Bit rate mode :Variable
Maximum bit rate :108 Mb/s
Width :1 920 pixels
Height :1 080 pixels
Display aspect ratio :16:9
Frame rate mode :Constant
Frame rate :60.000 FPS
Color space :YUV
Chroma subsampling :4:2:0
Bit depth :8 bits
Scan type :Progressive
Default :No
Forced :No
Color range :Limited
Color primaries :BT.709
Transfer characteristics :BT.709
Matrix coefficients :BT.709

Audio​

ID :2
Format :AAC LC
Format/Info :Advanced Audio Codec Low Complexity
Codec ID :A_AAC-2
Duration :9 s 770 ms
Channel(s) :2 channels
Channel layout :L R
Sampling rate :48.0 kHz
Frame rate :46.875 FPS (1024 SPF)
Compression mode :Lossy
Delay relative to video :-21 ms
Default :No
Forced :No





PCM


Format :Matroska
Format version :Version 4
File size :6.80 MiB
Duration :5 s 333 ms
Overall bit rate mode :Variable
Overall bit rate :10.7 Mb/s
Writing application :Lavf59.16.100
Writing library :Lavf59.16.100
ErrorDetectionType :Per level 1


Video​

ID :1
Format :AVC
Format/Info :Advanced Video Codec
Format profile :Main@L5
Format settings :CABAC / 8 Ref Frames
Format settings, CABAC :Yes
Format settings, Reference frames :8 frames
Format settings, GOP :M=1, N=30
Codec ID :V_MPEG4/ISO/AVC
Duration :4 s 800 ms
Bit rate mode :Variable
Bit rate :8 180 kb/s
Maximum bit rate :108 Mb/s
Width :1 920 pixels
Height :1 080 pixels
Display aspect ratio :16:9
Frame rate mode :Constant
Frame rate :60.000 FPS
Color space :YUV
Chroma subsampling :4:2:0
Bit depth :8 bits
Scan type :Progressive
Bits/(Pixel*Frame) :0.066
Stream size :4.68 MiB (69%)
Default :No
Forced :No
Color range :Limited
Color primaries :BT.709
Transfer characteristics :BT.709
Matrix coefficients :BT.709


Audio​

ID :2
Format :PCM
Format settings :Little / Signed
Codec ID :A_PCM/INT/LIT
Duration :5 s 333 ms
Bit rate mode :Constant
Bit rate :2 304 kb/s
Channel(s) :2 channels
Sampling rate :48.0 kHz
Bit depth :24 bits
Stream size :1.46 MiB (22%)
Default :No
Forced :No
 
strange, I'm using 28.0.1 as well
here are my settings and media info
do you use libx264 or h264_nvenc? im using nvenc
 

Attachments

  • greenHell.mkv.txt
    7.2 KB · Views: 32
  • obs-settings.jpg
    obs-settings.jpg
    114.3 KB · Views: 70
libx264 gives me constant framerate but with 60.123 fps
strange

General
Unique ID : 24761241943350269630402303743912954221 (0x12A0D77BBDC2328A41398D2577F5C96D)
Complete name : E:\OBS\2022-09-22 06-51-04.mkv
Format : Matroska
Format version : Version 4
File size : 7.42 MiB
Duration : 7 s 402 ms
Overall bit rate : 8 412 kb/s
Writing application : Lavf59.16.100
Writing library : Lavf59.16.100
ErrorDetectionType : Per level 1

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L5.2
Format settings : CABAC / 4 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference : 4 frames
Codec ID : V_MPEG4/ISO/AVC
Duration : 6 s 388 ms
Width : 3 840 pixels
Height : 2 160 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 60.132 FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Writing library : x264 core 164 r3095 baee400
Encoding settings : cabac=1 / ref=2 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=4 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=48 / lookahead_threads=12 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=1 / keyint=30 / keyint_min=3 / scenecut=40 / intra_refresh=0 / rc_lookahead=20 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Default : No
Forced : No
Color range : Limited
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709

Audio #1
ID : 2
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : A_AAC-2
Duration : 7 s 402 ms
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Default : No
Forced : No

Audio #2
ID : 3
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : A_AAC-2
Duration : 7 s 402 ms
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Default : No
Forced : No

Audio #3
ID : 4
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : A_AAC-2
Duration : 7 s 402 ms
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Default : No
Forced : No

Audio #4
ID : 5
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : A_AAC-2
Duration : 7 s 402 ms
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Default : No
Forced : No
 

rockbottom

Active Member
I can't reproduce it but I'm checking my recordings with MediaInfo, looks like you're using MediaTab. I don't have that installed but I think that may be the reason we're seeing different results.

If you haven't used it in the past, try remuxing with Avidemux.
 
i usually remux with ffmpeg
ffmpeg -i source.mkv -map 0 -c copy out.mp4
but i will try avidemux
i also tried just adding one audio stream (instead of my common four) but this has not changed anything
 
this is the result of ffprobe btw - it also says 62.5 fps just like adobe premiere detects it

Input #0, matroska,webm, from 'greenHell.mkv':
Metadata:
ENCODER : Lavf59.16.100
Duration: 01:13:39.93, start: 0.000000, bitrate: 68059 kb/s
Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 3840x2160 [SAR 1:1 DAR 16:9], 62.50 fps, 60 tbr, 1k tbn
Metadata:
DURATION : 01:13:39.921000000
Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp
Metadata:
DURATION : 01:13:39.925000000
Stream #0:2: Audio: aac (LC), 48000 Hz, stereo, fltp
Metadata:
DURATION : 01:13:39.925000000
Stream #0:3: Audio: aac (LC), 48000 Hz, stereo, fltp
Metadata:
DURATION : 01:13:39.925000000
Stream #0:4: Audio: aac (LC), 48000 Hz, stereo, fltp
Metadata:
DURATION : 01:13:39.925000000
 
I remuxed the file with avidemux, see both attachements with latest mediainfo (not mediatab)
also here is now the ffprobe of the avidemux remuxed mp4 - it now looks like cfr

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'greenHell.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.76.100
Duration: 01:13:39.94, start: 0.017000, bitrate: 68083 kb/s
Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 3840x2160 [SAR 1:1 DAR 16:9], 67112 kb/s, 60 fps, 60 tbr, 90k tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 315 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream #0:2[0x3](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 255 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream #0:3[0x4](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 240 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream #0:4[0x5](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 120 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
 

Attachments

  • mediainfo_mkv.txt
    4.7 KB · Views: 12
  • mediainfo_mp4_remoux_avidemux.txt
    6.1 KB · Views: 8

rockbottom

Active Member
strange, I'm using 28.0.1 as well
here are my settings and media info
do you use libx264 or h264_nvenc? im using nvenc

NVENC HEVC w/24/48 PCM

Encoder Settings:

1080p
preset=p7 profile=main tier=high rc=constqp rc-lookahead=0 init_qpI=15 init_qpP=18 init_qpB=20 bf=0 b_ref_mode=disabled refs=4

2160p
preset=p4 profile=main tier=high rc=constqp rc-lookahead=0 init_qpI=18 init_qpP=21 init_qpB=23 bf=0 b_ref_mode=disabled
 
How's Premiere handling the remux, any issues?
I'm not remuxing in my usual workflow. I'm using influx for mkv support within premiere. it works pretty well with mkv and also vfr is no problem but i get tons of warnings, but thats ok so far.
I just opened a thread because this might be an issue because OBS should not produce vfr in my oppinion because the cancas should be rendered straight in constant 60fps - and i have no frame drops, and also simple mkv output is cfr so that means there must be a difference between simple and custom ffmpeg and that's always bad :)

I'm testing your settings, and will report back.
Also i checked out the source, but I'm not a C developer but I try to find the spot and have a look whats going on.
 

rockbottom

Active Member
One or a combination of the other settings you were using could possibly be the cause.

I already tested going back to the old Presets & added B frames, output is still CFR.
 
One or a combination of the other settings you were using could possibly be the cause.

I already tested going back to the old Presets & added B frames, output is still CFR.
I FOUND IT

I changed audio encoder from aac to flac and now i have cfr. Also tested ac3 but this didnt work. pcm_s16le also produces cfr.
so it has to do with AUDIO encoder. thats interesting
 

rockbottom

Active Member
Yes it is, look above. I get CFR with AAC. I don't have CoreAudio installed, do you?

I took a look at your settings, some of them weren't valid with NVENC. The OBS log will show when a setting is rejected.

You'll need these links.

https://gist.github.com/nico-lab/c2d192cbb793dfd241c1eafeb52a21c3



 
Top