Log in

View Full Version : x264 mod to encode mixed framerate in CFR container


cubicibo
11th January 2025, 15:32
I was reading Blu-ray.com, found about a new release with mixed framerate content that used hard pulldown, and I decided I had enough.

So, here are two tools to encode VFR content in CFR containers, exploiting the soft pull-down capabilities of H.264. x265 support to come later. Blu-ray compatible, of course.

VS-PicStruct (https://github.com/cubicibo/vs-picstruct) - VapourSynth tool to analyze a VFR clip and produce a sequence of pulldown instructions that have to be used by the encoder to achieve the container framerate. Porting this to AviSynth should be straightforward.
x264 (https://github.com/cubicibo/x264) - x264 mod adding a --psfile option to parse the pull-down instructions and put them in the stream appropriately.

All pull-downs supported (18/1.001 -> 23.976, 24/1.001 -> 29.97, 23.976->29.97, 23.976 -> 59.94p, etc.) and the pattern can change anytime according to your own desires! A test x264 build is provided on the release page, enjoy.

Emulgator
12th January 2025, 00:09
Beautiful, many thanks cubicibo ! Will come handy for silent films, Regular 8, Super 8.

cubicibo
12th January 2025, 15:53
You are welcome. You are right, all low framerate films can benefit from it. Any movie or anime with VFR content too!

The versatility of H.264 pic struct enables for exotic framerates to fit in 23.976/24/25/29.97. VS-PicStruct determines the pattern programmatically, you don't have to figure them out yourself: they can be nasty. The pulldown pattern is also written in the output file as comments, you can verify them.

For those who care, the rules to see if there's a pulldown are:
- (container_framerate)/(clip_to_pd_framerate) = repetitions/cycles should be in [1; 3]
- cycles must be smaller than container_fps, else PD goes over gop-second boundary.
If both conditions are satisfied, there should be a pulldown pattern. VS-PicStruct will happily crash if it can't find a pattern. No garbage guaranteed!

cubicibo
30th January 2025, 22:11
I updated both VS-PicStruct and the x264 binaries after extensive testing on HW decoders. The new versions should work flawlessly on both Blu-ray (or any STB AVC) players and software decoders. Enjoy.

javieracdc
26th March 2025, 01:45
Hi
I'm sorry but how can I run the python script?
I have all tools, but how can I select the video to be analyzed?
I downloaded vspicstruct.py and the script of the usage on github but i dont know how to select the video

cubicibo
26th March 2025, 13:29
Hi,
vspicstruct.py should be in the same folder as your VapourSynth script. Then you can simply import PicStructFileV1 in your VPY script, and specify the target FPS and default field order.

If your input video is VFR and ready to be encoded, you can simply load it with BestSource or FFMS2. Please refer to VapourSynth tutorials for that.

from vspicstruct import PicStructFileV1

psf = PicStructFileV1(fps_num, fps_den, './psfile.txt', default_field_order)

# some VFR clip from filtering or source
# clip = ...

#Write psfile index for encode
psf.index(clip)

#Set as VS out
clip.set_output()