Skip to content

Conversation

@Dan-Flores
Copy link
Contributor

This PR adds output frame_rate to the API.

Previously, we always encoded videos using the same frame_rate as the input frames.

Now, we can set the output frame_rate when calling to_file/to_tensor/to_filelike (as in AudioEncoder), to adjusts the encoded video's frame durations. If no output frame_rate is specified, fallback to reusing the input frame_rate.

Testing:

To test, I added test_frame_rate_parameter which slows and speeds up a test video and ensures the video metadata is updated correctly. I also observed the video plays back slower or faster.

API after changes:

The complete API now looks as follows:

  encoder = VideoEncoder(frames=frames, frame_rate=25)
  encoder.to_file(
      dest="video.mp4",
      codec="libx264",
      pixel_format="yuv420p",
      crf=20,
      preset="medium",
      extra_options={
		"tune": "fastdecode",		
		"x264-params": "deblock=-1,-1:aq-mode=2
	  },
      frame_rate=25,
  )

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 14, 2025
pixel_format: Optional[str] = None,
crf: Optional[Union[int, float]] = None,
preset: Optional[Union[str, int]] = None,
frame_rate: Optional[int] = None,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to bikeshed on parameter order. sample_rate is the last param in AudioEncoder, but that constructor is much smaller. Here, having it last might make frame_rate less discoverable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My views:

  1. Optional parameters should always be keyword-only.
  2. codec should be the first keyword-only parameter, as it's likely to be the most used.
  3. extra_options should be the last keyword-only parameter, as "catch-all" parameters tend to be last.

I don't have a preference for the order of the rest. 🚲 🛖 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants