VFR to constant frame Rate, resampleFps VideoFilter

Started by butterw, May 08, 2021, 06:08:19 PM

Previous topic - Next topic

butterw

- Many phone and internet videos are encoded as variable frame rate. These videos are typically constant frame rate (with some jitter on frame times), and can be converted to constant frame rate without issues
- When re-encoding in Avidemux, it's possible to convert to constant frame Rate with the resampleFps VideoFilter. Other tools may allow converting to constant frame rate without encoding.
- Does Avidemux have the capacity (like MediaInfo) to detect whether a video is Variable Frame Rate mode ?
- Avidemux can measure average frame rate. Can resampleFps set the output frame Rate based on the input frame Rate automatically ? (29.97fps vfr -> 29.97fps cfr)
In resampleFps VideoFilter, it should be noted that 29.97(NTSC)= 30000/1001 is different from Custom: 29.97=29970/1000

- If the average frame rate is not the exact expected values (ex: 30.002 instead of 30fps) the video is likely Variable Frame Rate. 
A video can have the exact average frame rate and still be variable frame rate. Would resampleFps with the same bitrate be safe to use on constant frame rate video ?

eumagga0x2a

Quote from: butterw on May 08, 2021, 06:08:19 PM- Many phone and internet videos are encoded as variable frame rate. These videos are typically constant frame rate (with some jitter on frame times), and can be converted to constant frame rate without issues

All videos shot by Android smartphones I owned were truly variable frame rate videos with 1/90000 timebase and the average fps close but not equal 30 fps. Sample videos made available for me, shot with iDevices, were VFR too, with a 1/600 timebase, almost CFR, but not perfectly.

Quote from: butterw on May 08, 2021, 06:08:19 PMOther tools may allow converting to constant frame rate without encoding.

I plan to investigate the viability of such a feature.

Quote from: butterw on May 08, 2021, 06:08:19 PM- Does Avidemux have the capacity (like MediaInfo) to detect whether a video is Variable Frame Rate mode ?

Please look for the line with "Histogram map" in Avidemux log from loading a MP4 or QuickTime file.

Quote from: butterw on May 08, 2021, 06:08:19 PM- Avidemux can measure average frame rate. Can resampleFps set the output frame Rate based on the input frame Rate automatically ? (29.97fps vfr -> 29.97fps cfr)

Not going down this road.

Quote from: butterw on May 08, 2021, 06:08:19 PMA video can have the exact average frame rate and still be variable frame rate. Would resampleFps with the same bitrate be safe to use on constant frame rate video ?

resampleFps is always safe to use. You probably meant the changeFps filter.

butterw

#2
The videos seem to be near-enough to CFR that they can be converted to CFR without issues.

Ex of MediaInfo display: 
Frame rate mode                : Variable
Frame rate                     : 30.000 FPS
Minimum frame rate             : 29.970 FPS
Maximum frame rate             : 30.030 FPS

Avidemux has a frame-time Histogram map entry in the logfile:
[parseStbl] 20:07:20-584 stts:0
[parseStbl] 20:07:20-585 Time stts atom found (8371)
[parseStbl] 20:07:20-585 Using myscale 30000
[parseStbl] 20:07:20-587 Stss:94
[parseStbl] 20:07:20-587 ctts:0
[parseStbl] 20:07:20-589 Found 8371 elements
[parseStbl] 20:07:20-589 0 frames /8371 nbsz..
[parseStbl] 20:07:20-590 nbCo: 8371
[indexify] 20:07:20-591 Build Track index, track timescale: 30000
[indexify] 20:07:20-591 Histogram map has 3 elements.
Frame duration 999 count: 2790
Frame duration 1000 count: 2790
Frame duration 1001 count: 2790
[indexify] 20:07:20-592 Checking whether we need to fix jitter from rounding errors...
[indexify] 20:07:20-592 Yes, enforcing CFR, frame duration 1000 ticks.
[indexify] 20:07:20-592 Video index done.
[indexify] 20:07:20-592 Setting video timebase to 1000 / 30000
[parseStbl] 20:07:20-592 Movie duration = 279033
[parseStbl] 20:07:20-592 # images = 8371
[parseStbl] 20:07:20-593 Avg fps 30000.035156
[updateCtts] 20:07:20-593 [MP4]**************** Updating CTTS **********************

The average framerate provided by adm.getFps1000() is 30000 in this case, and
Custom 30.0fps is be the default value if adm.addVideoFilter("resampleFps") is added.
The info about the source video having non constant frame time is not provided.


Unrelated question: does Avidemux always know the number of frames of a mp4 video file after reading it ?

butterw

#3
QuoteresampleFps is always safe to use. You probably meant the changeFps filter.
No, I've never used changeFps. But there is some potential for confusion with such similar names.

The Transform filter category is too crowded for me and I hate to have to scroll to get to crop/resize, so my post-install script just deletes the filters I don't use.
It may make sense to regroup similar filters such as Horizontal and Vertical Flip.
EDIT: The Transform could probably be split in two, between the filters which change the video resolution, fps and those that don't (ex: Blacken Borders).

eumagga0x2a

Quote from: butterw on May 09, 2021, 08:34:42 PM[indexify] 20:07:20-591 Build Track index, track timescale: 30000
[indexify] 20:07:20-591 Histogram map has 3 elements.
Frame duration 999 count: 2790
Frame duration 1000 count: 2790
Frame duration 1001 count: 2790
[indexify] 20:07:20-592 Checking whether we need to fix jitter from rounding errors...
[indexify] 20:07:20-592 Yes, enforcing CFR, frame duration 1000 ticks.
[indexify] 20:07:20-592 Video index done.
[indexify] 20:07:20-592 Setting video timebase to 1000 / 30000

Can it be that you didn't read the lines following "Histogram map"? Avidemux has detected that the file is actually a CFR file with deviations caused by rounding errors typical for earliler Avidemux versions and has forced CFR. No filtering is needed. The video is perfectly CFR.

Quote from: butterw on May 09, 2021, 08:34:42 PMdoes Avidemux always know the number of frames of a mp4 video file after reading it ?

Of course it does. Please don't confuse the number of (compressed) frames for the number of decoded pictures.

butterw

In the previous example, the input video has non constant frame times.
Current Avidemux versions detects this file as having rounding error jitter and automatically treat the video as CFR.
The Avidemux output (whether in Copy or reencode mode) will be CFR.
resampleFps VideoFilter is not required here, but would also be safe to use.

Mobile phone videos are typically (near CFR) VFR, it would be good to have information on the number of frames and whether the file was treated as CFR available to scripts.
 
I'm not sure what pictures means here. I'm referring to frame count as used by Virtualdub, Avisynth. I haven't had to deal with interlaced content in years.

eumagga0x2a

Quote from: butterw on May 10, 2021, 08:18:59 AMMobile phone videos are typically (near CFR) VFR

In short, they are VFR :-)

Quote from: butterw on May 10, 2021, 08:18:59 AMit would be good to have information on the number of frames and whether the file was treated as CFR available to scripts.

The number of frames which matters for you is the number of pictures. The only way to obtain a meaningful number of pictures is to decode the entire video and count how many pictures the decoder was able to decode.

It should be possible to query timebase numerator and denominator which would allow an educated guess about CFR/VFR property when compared with the output of getFps1000(). However, for many applications, a gap (a missing picture) in video would make it VFR, but for the Mp4 demuxer in Avidemux, the only thing which matters for CFR are decode timestamps of compressed frames.

Quote from: butterw on May 10, 2021, 08:18:59 AMI'm referring to frame count as used by Virtualdub, Avisynth.

Could you please explain how frame count is used by these applications? I don't use any of them.

Quote from: butterw on May 10, 2021, 08:18:59 AMI haven't had to deal with interlaced content in years.

Unfortunately, interlaced and field-encoded interlaced content is far from being extinct (I wish it were).

szlldm

Quote from: eumagga0x2a on May 10, 2021, 06:47:23 PM
QuoteI'm referring to frame count as used by Virtualdub, Avisynth.

Could you please explain how frame count is used by these applications? I don't use any of them.

I think the operation modii of the mentioned softwares are similar to that pre 2.6.