Skip to content

Allow to override ffmpeg path and options#41007

Open
azmeuk wants to merge 1 commit into
microsoft:mainfrom
azmeuk:17217-screencast-quality
Open

Allow to override ffmpeg path and options#41007
azmeuk wants to merge 1 commit into
microsoft:mainfrom
azmeuk:17217-screencast-quality

Conversation

@azmeuk
Copy link
Copy Markdown

@azmeuk azmeuk commented May 26, 2026

Oops. I misclicked, I did not want to open the PR here yet, just on my own fork to trigger the CI. I'll update the description soon with all the details.

Sorry for that noise ☝️

I am a contributor of sphinxcontrib-screenshot, which is an extension that takes screenshots and screencasts for integration in Python sphinx documentations. I use it to automatically generate videos and demonstrate reactive behaviors in other apps documentations.

The current static quality settings generate some glitches in the videos, and too much blur. The end quality is not fitting professional documentation, so I opened this PR to add quality customization parameters that are passed to ffmpeg. I evoked this in #17217

This PR adds an optional field to recordVideo to control ffmpeg encoding quality:

recordVideo: {
  dir: 'videos/',
  size: { width: 640, height: 480 },
  quality: { mode: 'crf', value: 30 },     // or { mode: 'bitrate', value: 1_000_000 }
}
  • mode: 'crf' — constant rate factor (constant visual quality, variable file size). value is an integer between 0 (lossless) and 63 (worst).
  • mode: 'bitrate' — target bitrate (variable visual quality, predictable file size). value is in bits per second.

When quality is omitted, the ffmpeg command line stays identical to today. The tests just check that the command run. I am not really sure how to check deterministically which quality parameters were passed from the output video.

Let me know if the quality tweaking seems right but the implementation feel wrong, and I will update the PR.

Regards

related to to #22257

@azmeuk azmeuk marked this pull request as draft May 26, 2026 19:54
@azmeuk
Copy link
Copy Markdown
Author

azmeuk commented May 26, 2026

@microsoft-github-policy-service agree

@azmeuk azmeuk force-pushed the 17217-screencast-quality branch 2 times, most recently from d3cf0da to 7cad89a Compare May 26, 2026 20:39
@azmeuk azmeuk marked this pull request as ready for review May 26, 2026 20:45
@azmeuk azmeuk force-pushed the 17217-screencast-quality branch from 7cad89a to 7a34702 Compare May 26, 2026 20:47
Copy link
Copy Markdown
Member

@pavelfeldman pavelfeldman left a comment

Choose a reason for hiding this comment

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

I'd rather make it lower level and allow passing ffmpeg properties that would override our defaults.

@azmeuk
Copy link
Copy Markdown
Author

azmeuk commented May 27, 2026

Thanks for the feedback. To make sure I'm building what you have in mind: would recordVideo: { ffmpegOptions: { crf: 30, 'b:v': '500k', codec: 'libvpx-vp9' } } work - a dict of ffmpeg option name -> value that overrides the built-in defaults?

@Skn0tt
Copy link
Copy Markdown
Member

Skn0tt commented May 27, 2026

I'd try to mirror what we have for browser launching: https://playwright.dev/docs/api/class-browsertype#browser-type-launch-option-ignore-default-args

@pavelfeldman
Copy link
Copy Markdown
Member

Thanks for the feedback. To make sure I'm building what you have in mind: would recordVideo: { ffmpegOptions: { crf: 30, 'b:v': '500k', codec: 'libvpx-vp9' } } work - a dict of ffmpeg option name -> value that overrides the built-in defaults?

That works for me.

@pavelfeldman
Copy link
Copy Markdown
Member

I'd try to mirror what we have for browser launching: https://playwright.dev/docs/api/class-browsertype#browser-type-launch-option-ignore-default-args

Browsers arsgs are generally used for additional args, which is not override-friendly. I'd use object notation as proposed - ignore-default-args is overall horrible.

@azmeuk azmeuk force-pushed the 17217-screencast-quality branch from 7a34702 to 70c48fe Compare May 28, 2026 11:45
@azmeuk azmeuk changed the title Add quality option to recordVideo Allow to override ffmpeg path and options May 28, 2026
@azmeuk
Copy link
Copy Markdown
Author

azmeuk commented May 28, 2026

Updated. So there are two options:

  • ffmpegPath which can be a path to a custom ffmpeg, for support for codecs additional than vp8
  • ffmpegOptions which is the form { 'c:v': 'libvpx-vp9', crf: 30, 'b:v': null } and can override the default options. null value can delete a default value

@azmeuk azmeuk force-pushed the 17217-screencast-quality branch from 70c48fe to e2a84af Compare May 28, 2026 13:59
@pavelfeldman
Copy link
Copy Markdown
Member

I love the custom `ffmpeg path option. We discussed it at the API review meeting and are thinking that we want to give you full control over the options (both input and output, even though we produce the input), for simplicity. So we are now thinking that { ffmpegExecutable: string, ffmpegOptions: string, fps: number, outputExtension: string } should be sufficient for you to produce any content desired. Sorry for going back and forth on this one. Wdyt?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants