Handbrake not producing constant frame rate when told to

General questions or discussion about HandBrake, Video and/or audio transcoding, trends etc.
Post Reply
WadeMasshardt
Posts: 8
Joined: Tue Mar 21, 2023 5:26 pm

Handbrake not producing constant frame rate when told to

Post by WadeMasshardt »

Hello all, I've been using Handbrake for a number of years to encode DVDs & blu-rays, but am far from a Handbrake expert. Recently trying something new and am running into the following problem:

Description of problem or question:

I am wanting to edit video captured from US over-the-air broadcast (mpeg2 1080i telecined 29.97fps) to remove the commercials and interlacing. My first step is to use Handbrake to detelecine into a 23.98fps progressive video which I can then edit in Kdenlive to remove the commercials. The problem I'm running into is that Handbrake is outputting variable frame rate even though I've selected "Constant Framerate" on the "video" tab.


Steps to reproduce the problem (If Applicable):

Feed Handbrake a video file, select "Constant Framerate", get variable instead.


HandBrake version (e.g., 1.0.0):

1.6.1 (x86_64 linux & macOS/Arm64)


Operating system and version (e.g., Ubuntu 16.04 LTS, macOS 10.13 High Sierra, Windows 10 Creators Update):

Tried it both on linux (Manjaro stable with kernel 6.2.7) and macOS (Ventura 13.2.1) with the same results (MediaInfo reported both as having variable frame rate and Kdenlive agreed.) Below is the log from the macOS run.


HandBrake Activity Log ***required*** (see How-to get an activity log)

Code: Select all

[18:46:09] macgui: Handbrake Version: 1.6.1 (2023012200)
[18:46:09] Compile-time hardening features are enabled
[18:46:10] hb_init: starting libhb thread
[18:46:57] macgui: ScanCore scanning titles with a duration of 10 seconds or more
[18:46:57] CPU: 
[18:46:57]  - logical processor count: 8
[18:46:57] hb_scan: path=/Volumes/Working/working/Handbrake detelecine test source.ts, title_index=0
udfread ERROR: ECMA 167 Volume Recognition failed
disc.c:333: failed opening UDF image /Volumes/Working/working/Handbrake detelecine test source.ts
disc.c:437: error opening file BDMV/index.bdmv
disc.c:437: error opening file BDMV/BACKUP/index.bdmv
[18:46:57] bd: not a bd - trying as a stream/file instead
libdvdread: DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdnav: vm: vm: failed to read VIDEO_TS.IFO
[18:46:57] dvd: not a dvd - trying as a stream/file instead
[18:46:57] file is MPEG Transport Stream with 188 byte packets offset 0 bytes
[18:46:58] Found the following PIDS
[18:46:58]     Video PIDS : 
[18:46:58]       0x100 type MPEG2 (0x2) (PCR)
[18:46:58]     Audio PIDS : 
[18:46:58]       0x101 type AC3 (0x81)
[18:46:58]       0x102 type AC3 (0x81)
[18:46:58]     Subtitle PIDS : 
[18:46:58]     Other PIDS : 
[18:46:58] stream id 0x101 (type 0x81 substream 0x0) audio 0x101
[18:46:58] stream id 0x102 (type 0x81 substream 0x0) audio 0x102
[18:46:58] scan: decoding previews for title 1
[18:46:58] file is MPEG Transport Stream with 188 byte packets offset 0 bytes
[18:46:58] scan: audio 0x101: ac3, rate=48000Hz, bitrate=384000 English (AC3) (5.1 ch) (384 kbps)
[18:46:58] scan: audio 0x102: ac3, rate=48000Hz, bitrate=192000 español (AC3) (2.0 ch) (192 kbps)
[18:46:58] stream: 57 good frames, 0 errors (0%)
[18:46:58] scan: 10 previews, 1920x1080, 29.970 fps, autocrop = 0/0/2/0, aspect 16:9, PAR 1:1, color profile: 1-1-1, chroma location: left
[18:46:58] libhb: scan thread found 1 valid title(s)
[18:46:58] macgui: ScanCore scan done
[swscaler @ 0x138018000] [swscaler @ 0x138028000] No accelerated colorspace conversion found from yuv420p to bgra.
   (70 additional repetitions of the above line edited out)
[18:48:12] Compile-time hardening features are enabled
[18:48:12] hb_init: starting libhb thread
[18:48:12] macgui: fr.handbrake.HandBrakeXPCService scanning specifically for title: 1
[18:48:12] CPU: 
[18:48:12]  - logical processor count: 8
[18:48:12] hb_scan: path=/Volumes/Working/working/Handbrake detelecine test source.ts, title_index=1
udfread ERROR: ECMA 167 Volume Recognition failed
disc.c:333: failed opening UDF image /Volumes/Working/working/Handbrake detelecine test source.ts
disc.c:437: error opening file BDMV/index.bdmv
disc.c:437: error opening file BDMV/BACKUP/index.bdmv
[18:48:12] bd: not a bd - trying as a stream/file instead
libdvdread: DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdnav: vm: vm: failed to read VIDEO_TS.IFO
[18:48:12] dvd: not a dvd - trying as a stream/file instead
[18:48:12] file is MPEG Transport Stream with 188 byte packets offset 0 bytes
[18:48:12] Found the following PIDS
[18:48:12]     Video PIDS : 
[18:48:12]       0x100 type MPEG2 (0x2) (PCR)
[18:48:12]     Audio PIDS : 
[18:48:12]       0x101 type AC3 (0x81)
[18:48:12]       0x102 type AC3 (0x81)
[18:48:12]     Subtitle PIDS : 
[18:48:12]     Other PIDS : 
[18:48:12] stream id 0x101 (type 0x81 substream 0x0) audio 0x101
[18:48:12] stream id 0x102 (type 0x81 substream 0x0) audio 0x102
[18:48:13] scan: decoding previews for title 1
[18:48:13] file is MPEG Transport Stream with 188 byte packets offset 0 bytes
[18:48:13] scan: audio 0x101: ac3, rate=48000Hz, bitrate=384000 English (AC3) (5.1 ch) (384 kbps)
[18:48:13] scan: audio 0x102: ac3, rate=48000Hz, bitrate=192000 español (AC3) (2.0 ch) (192 kbps)
[18:48:13] stream: 57 good frames, 0 errors (0%)
[18:48:13] scan: 10 previews, 1920x1080, 29.970 fps, autocrop = 0/0/2/0, aspect 16:9, PAR 1:1, color profile: 1-1-1, chroma location: left
[18:48:13] libhb: scan thread found 1 valid title(s)
[18:48:13] macgui: fr.handbrake.HandBrakeXPCService scan done
[18:48:13] macgui: fr.handbrake.HandBrakeXPCService started encoding Handbrake detelecine test source-detel.m4v
[18:48:13] macgui: fr.handbrake.HandBrakeXPCService with preset Detelecine 29.97->23.976 (Modified)
[18:48:13] Starting work at: Tue Mar 28 18:48:13 2023

[18:48:13] 1 job(s) to process
[18:48:13] Starting Task: Encoding Pass
[18:48:13] Skipping crop/scale filter
[18:48:13] work: only 1 chapter, disabling chapter markers
[18:48:13] job configuration:
[18:48:13]  * source
[18:48:13]    + /Volumes/Working/working/Handbrake detelecine test source.ts
[18:48:13]    + title 1, chapter(s) 1 to 1
[18:48:13]  * destination
[18:48:13]    + /Volumes/Working/working/Handbrake output/Handbrake detelecine test source-detel.m4v
[18:48:13]    + container: MPEG-4 (libavformat)
[18:48:13]      + optimized for HTTP streaming (fast start)
[18:48:13]      + align initial A/V stream timestamps
[18:48:13]  * video track
[18:48:13]    + decoder: mpeg2video 8-bit (yuv420p)
[18:48:13]      + bitrate 200 kbps
[18:48:13]    + filters
[18:48:13]      + Detelecine (pullup) (skip-left=1:skip-right=1:skip-top=4:skip-bottom=4:plane=0)
[18:48:13]      + Framerate Shaper (mode=1:rate=27000000/1126125)
[18:48:13]        + frame rate: 29.970 fps -> constant 23.976 fps
[18:48:13]    + Output geometry
[18:48:13]      + storage dimensions: 1920 x 1080
[18:48:13]      + pixel aspect ratio: 1 : 1
[18:48:13]      + display dimensions: 1920 x 1080
[18:48:13]    + encoder: H.264 (libx264)
[18:48:13]      + preset:  ultrafast
[18:48:13]      + tune:    fastdecode
[18:48:13]      + profile: auto
[18:48:13]      + level:   auto
[18:48:13]      + quality: 0.00 (RF)
[18:48:13]      + color profile: 1-1-1
[18:48:13]      + chroma location: left
[18:48:13]  * audio track 1
[18:48:13]    + decoder: English (AC3) (5.1 ch) (384 kbps) (track 1, id 0x101)
[18:48:13]      + bitrate: 384 kbps, samplerate: 48000 Hz
[18:48:13]    + AC3 Passthru
[18:48:13] file is MPEG Transport Stream with 188 byte packets offset 0 bytes
[18:48:13] sync: expecting 2746 video frames
[18:48:13] encx264: min-keyint: 24, keyint: 240
[18:48:13] encx264: encoding at constant RF 0.000000
[18:48:13] encx264: unparsed options: ref=1:scenecut=0:bframes=0:no-deblock=1:cabac=0:analyse=none:8x8dct=0:weightp=0:me=dia:subme=0:mixed-refs=0:trellis=0:aq-mode=0:mbtree=0:rc-lookahead=0
x264 [info]: using SAR=1/1
x264 [info]: using cpu capabilities: ARMv8 NEON
x264 [info]: profile High 4:4:4 Predictive, level 4.0, 4:2:0, 8-bit
[18:48:13] sync: first pts audio 0x101 is 0
[18:48:13] sync: first pts video is 4746
[18:48:22] hb_ts_stream_decode - eof
[18:48:22] hb_ts_stream_decode - eof
[18:48:22] reader: done. 1 scr changes
[18:48:22] work: average encoding speed for job is 304.234131 fps
[18:48:22] vfr: 2199 frames output, 31 dropped and 0 duped for CFR/PFR
[18:48:22] vfr: lost time: 1555554 (0 frames)
[18:48:22] vfr: gained time: 1555554 (2072 frames) (0 not accounted for)
[18:48:22] stream: 2750 good frames, 0 errors (0%)
[18:48:22] ac3-decoder done: 2867 frames, 0 decoder errors
[18:48:22] mpeg2video-decoder done: 2749 frames, 0 decoder errors
[18:48:22] sync: got 2749 frames, 2746 expected
[18:48:22] sync: framerate min 14.985 fps, max 29.970 fps, avg 29.959 fps
x264 [info]: frame I:10    Avg QP: 0.00  size:696815
x264 [info]: frame P:2189  Avg QP: 0.00  size:620041
x264 [info]: mb I  I16..4: 100.0%  0.0%  0.0%
x264 [info]: mb P  I16..4: 65.1%  0.0%  0.0%  P16..4: 30.0%  0.0%  0.0%  0.0%  0.0%    skip: 4.9%
x264 [info]: coded y,uvDC,uvAC intra: 88.2% 85.1% 84.8% inter: 73.7% 67.0% 66.9%
x264 [info]: i16 v,h,dc,p: 37% 62%  1%  0%
x264 [info]: i8c dc,h,v,p: 15% 56% 28%  1%
x264 [info]: kb/s:118995.98
[mp4 @ 0x158f109f0] Starting second pass: moving the moov atom to the beginning of the file
[18:48:30] mux: track 0, 2199 frames, 1364238302 bytes, 118887.82 kbps, fifo 256
[18:48:30] mux: track 1, 2867 frames, 4403712 bytes, 383.77 kbps, fifo 256
[18:48:30] Finished work at: Tue Mar 28 18:48:30 2023

[18:48:30] libhb: work result = 0
[18:48:31] macgui: Queue Done, there are no more pending encodes
[18:48:31] macgui: fr.handbrake.HandBrakeXPCService work done

User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: Handbrake not producing constant frame rate when told to

Post by JohnAStebbins »

Handbrake uses a 90khz clock for timestamps. A 23.976 fps frame's duration at 90khz is 3753.754 ticks. Since duration must be represented as an integer number of ticks, most frames will be 3754 ticks and about every 4th frame will be 3753 ticks. This 1/90000th second jitter every 4th frame is what your applications are calling "variable" framerate.
WadeMasshardt
Posts: 8
Joined: Tue Mar 21, 2023 5:26 pm

Re: Handbrake not producing constant frame rate when told to

Post by WadeMasshardt »

Aha! Thank you, John! Armed with this information, I reran my test sample through Handbrake again, this time selecting 30fps as my output, and as a result it's constant framerate. Success! The resulting file is slightly larger than the 23.976fps version (not a big deal, as that file is temporary) and now every group of five frames has the pattern 1-2-3-4-4 (the fifth frame is a repeat of the fourth), which is the expected behavior and is not noticeable in the final output. Problem solved!

Big thank you to the Handbrake team for making this software, and to John for answering this question!
mduell
Veteran User
Posts: 8187
Joined: Sat Apr 21, 2007 8:54 pm

Re: Handbrake not producing constant frame rate when told to

Post by mduell »

Why not do 24 fps? A lot fewer duplicated frames, and avoids/reduces mistiming all the frames.
Deleted User 11865

Re: Handbrake not producing constant frame rate when told to

Post by Deleted User 11865 »

Or output/remux to MKV using mkvmerge or Mkvtoolnix GUI, that way no frames are duplicated at all, and IIRC mkvmerge will use a different timebase that may be unaffected by the issue.
WadeMasshardt
Posts: 8
Joined: Tue Mar 21, 2023 5:26 pm

Re: Handbrake not producing constant frame rate when told to

Post by WadeMasshardt »

mduell wrote: Wed Mar 29, 2023 7:43 pm Why not do 24 fps? A lot fewer duplicated frames, and avoids/reduces mistiming all the frames.
Because I didn't think to check if 24fps goes into 90kHz evenly, which it does. Whoopsie! Thank you for pointing this out, this makes a lot more sense than using 30fps.
WadeMasshardt
Posts: 8
Joined: Tue Mar 21, 2023 5:26 pm

Re: Handbrake not producing constant frame rate when told to

Post by WadeMasshardt »

Rodeo wrote: Thu Mar 30, 2023 6:42 pm Or output/remux to MKV using mkvmerge or Mkvtoolnix GUI, that way no frames are duplicated at all, and IIRC mkvmerge will use a different timebase that may be unaffected by the issue.
I was not aware of this tool, I've now installed it on my linux system. However, when I searched the documentation for mkvmerge for "telecine", it didn't find anything. Are you saying mkvtoolnix and take the 29.97 telecined file and remux it into the source 23.976 file without doing any re-encoding?
Deleted User 11865

Re: Handbrake not producing constant frame rate when told to

Post by Deleted User 11865 »

No, I'm suggesting encoding to 23.976 either directly to MKV or to MP4 then remuxing to MKV.
WadeMasshardt
Posts: 8
Joined: Tue Mar 21, 2023 5:26 pm

Re: Handbrake not producing constant frame rate when told to

Post by WadeMasshardt »

Rodeo wrote: Fri Mar 31, 2023 6:07 pm No, I'm suggesting encoding to 23.976 either directly to MKV or to MP4 then remuxing to MKV.
Thank you for taking the time to help my, and my apologies, but I'm new enough at this that I'm not sure how I would do that. Would I use Handbrake to encode to 23.976 MKV? Seems like I'd have the same variable frame rate problem I'm trying to escape.
Post Reply