How to Configure FFmpeg Output Presets for Different Target Platforms in Video-Use

Configure FFmpeg output presets in the browser-use/video-use repository by modifying the extract_segment() function in helpers/render.py and apply_grade() in helpers/grade.py to map platform-specific flags to custom libx264 presets, CRF values, and scaling options.

The browser-use/video-use repository provides a lightweight FFmpeg wrapper for video processing that uses hard-coded encoding presets optimized for speed versus quality trade-offs. By default, the pipeline supports three rendering modes—draft, preview, and final—but you can extend this architecture to target specific social platforms like TikTok, YouTube, or Instagram with tailored encoding parameters. Understanding where these presets live in the source code allows you to configure FFmpeg output presets for different target platforms without breaking the existing rendering workflow.

Where FFmpeg Presets Are Defined

The repository constructs FFmpeg commands in two primary locations, each handling different stages of the video pipeline.

Per-Segment Extraction in helpers/render.py

The extract_segment() function (lines 99-106) builds the core FFmpeg command used when extracting video segments. This is where the libx264 preset (ultrafast, medium, fast) and CRF (Constant Rate Factor) values are injected into the command line. By default, this function selects presets based on the rendering mode flag passed by the user.

Full-Clip Grading in helpers/grade.py

The apply_grade() function (lines 75-89) handles final color grading and output generation. This helper uses a fixed -preset fast configuration for the final copy, regardless of the mode selected during segment extraction. To maintain consistent platform targeting, you may need to modify this function to accept preset overrides as well.

Default Preset Profiles

The repository ships with three built-in quality profiles that balance encoding speed against file size and visual fidelity:

  • Draft (--draft): Uses ultrafast preset with CRF 28 for rapid quality control checks and timeline scrubbing
  • Preview (--preview): Uses medium preset with CRF 22 for near-final quality review builds that render faster than final output
  • Final (default): Uses fast preset with CRF 20 for social-ready exports suitable for YouTube, Instagram Reels, and TikTok

These values are hard-coded as Python variables (preset, crf) within the helper functions, making them straightforward to override or extend.

Adding Platform-Specific Preset Mappings

To configure FFmpeg output presets for different target platforms, create a mapping dictionary that associates platform names with specific encoding parameters and resolution scaling.

Step 1: Define Platform Presets

Add a platform flag (e.g., --platform tiktok) and mapping dictionary to your argument parsing logic in helpers/render.py:


# helpers/render.py – add after existing flag parsing

platform_presets = {
    "tiktok":    ("fast", "20", "scale=-2:1920"),    # 1080×1920 portrait

    "youtube":   ("medium", "22", "scale=1920:-2"),  # 1920×1080 landscape

    "instagram": ("fast", "20", "scale=-2:1920"),    # Same as TikTok

}

# Choose platform preset if supplied

if args.platform:
    preset, crf, scale_opt = platform_presets.get(args.platform, (None, None, None))
    if preset:
        args.preset = preset
        args.crf = crf
        args.scale_override = scale_opt

Step 2: Modify extract_segment() Logic

Update the extract_segment() function to respect the new args.scale_override when constructing the FFmpeg filter chain:

if args.scale_override:
    scale = args.scale_override
elif draft:
    scale = "scale=-2:1280" if portrait else "scale=1280:-2"
elif preview:
    scale = "scale=-2:1920" if portrait else "scale=1920:-2"
else:
    scale = "scale=-2:1920" if portrait else "scale=1920:-2"

Step 3: Execute Platform-Specific Renders

With these modifications in place, invoke the renderer with your platform flag:

python helpers/render.py my.edl -o final.mp4 --platform tiktok
python helpers/render.py my.edl -o final.mp4 --platform youtube

The resulting FFmpeg command automatically receives the platform-specific preset, CRF, and scaling:

ffmpeg -y -ss … -i src.mp4 -t … -vf scale=-2:1920,eq=… -c:v libx264 -preset fast -crf 20 …

Key Files for Configuration

Understanding these source files is essential for maintaining your custom preset configurations:

  • helpers/render.py (lines 99-106): Contains the extract_segment() function that constructs the primary FFmpeg command and determines which preset to use based on quality flags
  • helpers/grade.py (lines 75-89): Houses the apply_grade() function for final color grading; currently uses a fixed -preset fast that you may want to make configurable
  • README.md: Documents the existing --preview and --draft flags and general usage patterns for the rendering pipeline

Summary

  • The browser-use/video-use repository controls FFmpeg encoding through helpers/render.py and helpers/grade.py, specifically within the extract_segment() and apply_grade() functions
  • Default presets include draft (ultrafast, CRF 28), preview (medium, CRF 22), and final (fast, CRF 20)
  • You can configure FFmpeg output presets for different target platforms by adding a platform_presets mapping dictionary and passing platform-specific libx264 presets, CRF values, and scaling filters
  • Modify extract_segment() to check for args.scale_override before applying default scaling logic to ensure platform-specific resolutions are respected

Frequently Asked Questions

How do I add a new platform preset for LinkedIn or Twitter?

Create a new entry in the platform_presets dictionary in helpers/render.py with the desired libx264 preset, CRF value, and scaling option. For example, LinkedIn typically prefers 1920×1080 landscape video, so you would add "linkedin": ("medium", "22", "scale=1920:-2") to the mapping, then run with --platform linkedin.

Why does the final grading step use a fixed preset in helpers/grade.py?

The apply_grade() function currently hard-codes -preset fast (lines 75-89) to ensure consistent processing speed during the color-grading phase. To support platform-specific final outputs, modify this function to accept a preset parameter from the command line arguments, similar to the changes made in extract_segment().

Can I use different codecs instead of libx264 for specific platforms?

Yes, but you must modify the FFmpeg command construction in extract_segment() (lines 99-106). The current implementation assumes libx264 via the -c:v libx264 flag. To support platforms requiring HEVC (H.265) or AV1, add a codec key to your platform_presets dictionary and update the command builder to use -c:v libx265 or -c:v libsvtav1 when those platforms are specified.

What CRF value should I use for 4K YouTube exports?

For 4K content targeting YouTube, use a CRF between 18 and 20 with the slow or veryslow preset to maximize quality while maintaining reasonable file sizes. Add a "youtube4k": ("slow", "18", "scale=3840:-2") entry to your platform presets, though be aware that slower presets significantly increase encoding time compared to the default fast preset.

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 →