How to Precisely Control Output Video Quality in video-use Beyond Default Settings

Yes, output video quality can be precisely controlled by modifying the FFmpeg CRF and preset constants in helpers/render.py, using the built-in --draft or --preview flags, or extending the CLI to accept custom quality parameters.

The browser-use/video-use repository renders MP4 videos by orchestrating FFmpeg through Python helper functions. While default settings target social media workflows with specific CRF values and encoder presets, the rendering pipeline exposes these controls directly in the source code. Understanding where these parameters are set allows you to override defaults and achieve precise output video quality for any production requirement.

Where Output Video Quality Is Configured

The visual quality of rendered videos is determined by two Python functions in helpers/render.py that construct FFmpeg commands. These functions insert the -preset and -crf arguments directly into the encoder configuration at specific line ranges.

Per-Segment Extraction in extract_segment()

The extract_segment() function (lines 66-70, 94-100, and 122-127) builds FFmpeg commands for individual video segments. It selects quality parameters based on CLI flags using a conditional ladder:

if draft:                     # 720p, ultrafast, CRF 28

    preset, crf = "ultrafast", "28"
elif preview:                 # 1080p, medium, CRF 22

    preset, crf = "medium", "22"
else:                         # final, 1080p, fast, CRF 20

    preset, crf = "fast", "20"

These values are inserted into the FFmpeg command at -c:v libx264 -preset <preset> -crf <crf> (lines 99-106).

Final Compositing in build_final_composite()

After concatenation, the build_final_composite() function (lines 155-162) encodes the final output with hard-coded settings:


# Hard-coded values for final composite

preset = "fast"
crf = "18"

This applies a slightly higher quality (CRF 18) to the final render regardless of which mode was used for segment extraction.

The Default Quality Ladder

video-use provides three distinct quality presets through command-line flags, each optimized for different stages of production.

Draft Mode (--draft)

Activate with the --draft flag for rapid iteration and cut-point verification:

python helpers/render.py my_edl.json -o draft.mp4 --draft

This configures CRF 28 with the ultrafast preset at 720p resolution. The high CRF value produces smaller files with visible compression artifacts, prioritizing encoding speed over visual fidelity.

Preview Mode (--preview)

Use --preview for moderate quality review:

python helpers/render.py my_edl.json -o preview.mp4 --preview

This sets CRF 22 with the medium preset at 1080p, offering a balance between quality and processing time suitable for client approvals.

Final Production Mode (Default)

Running without quality flags triggers the default final settings:

python helpers/render.py my_edl.json -o final.mp4

Segments render at CRF 20 with the fast preset, while the final composite receives CRF 18 for improved visual fidelity after overlays and subtitles are applied.

Three Methods to Control Quality Beyond Defaults

Because quality values are literals in the source code, you have three approaches to achieve precise control over output video quality.

Using Built-In CLI Flags

For immediate control without code changes, select from the existing three-tier system:

  • --draft: CRF 28, fastest encoding, lowest quality
  • --preview: CRF 22, medium speed, moderate quality
  • No flag: CRF 20 (segments) and CRF 18 (composite), best default quality

Modifying Hard-Coded Constants

Edit helpers/render.py directly to change default behavior permanently. For example, to force super-high-quality exports, modify the constants in extract_segment():


# Inside extract_segment() - line ~122

preset, crf = "slow", "16"   # Higher quality, slower encode

Or adjust the final composite quality in build_final_composite():


# Inside build_final_composite() - line ~155

preset, crf = "slow", "16"

Adding New Command-Line Arguments

Extend the argument parser to expose quality controls to users without requiring source edits:


# Add to argument parser

ap.add_argument("--crf", type=int, help="Override CRF for final composite")

# Later in build_final_composite()

crf = args.crf if args.crf else 18
cmd = ["ffmpeg", "-y", *inputs, "-filter_complex", filter_complex,
       "-c:v", "libx264", "-preset", "fast", "-crf", str(crf), ...]

Now users can invoke precise quality settings directly:

python helpers/render.py my_edl.json -o master.mp4 --crf 14

Summary

  • Quality control exists at two stages: segment extraction (extract_segment()) and final compositing (build_final_composite()) in helpers/render.py.
  • Default CRF values range from 28 (draft) to 18 (final composite), with presets from ultrafast to fast.
  • Three CLI flags (--draft, --preview, default) provide immediate quality selection without code changes.
  • Precise control requires source modification or CLI extension, as the CRF and preset values are hard-coded literals in the rendering functions.
  • CRF 18 in final compositing provides a modest quality boost over the CRF 20 used for segments to preserve fidelity after overlays.

Frequently Asked Questions

Can I set a custom CRF value without editing the source code?

No, the current implementation only supports the three built-in quality modes via --draft and --preview flags. To use a specific CRF value like 16 or 23, you must either modify the hard-coded constants in helpers/render.py or extend the CLI to accept a --crf argument as shown in the code examples above.

Why does the final composite use CRF 18 while segments use CRF 20?

The final composite applies CRF 18 (lines 155-162) to compensate for generation loss that occurs when concatenating multiple compressed segments and adding overlays or subtitles. This slightly lower CRF preserves visual fidelity in the final output without significantly increasing file size or encoding time.

What do the preset values control in video-use?

The preset values (ultrafast, medium, fast, slow) control the encoding speed versus compression efficiency trade-off in FFmpeg's libx264 encoder. According to the source code in helpers/render.py, faster presets like ultrafast produce larger files at lower quality (CRF 28), while slower presets compress more efficiently but require longer processing times.

How do I render in maximum quality for archival purposes?

To achieve maximum output video quality, edit helpers/render.py to set preset="veryslow" and crf="16" (or lower) in both the extract_segment() function and build_final_composite() function. Alternatively, implement a --crf CLI argument to pass these values dynamically without modifying the source code each time.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →