You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何精简并排拼接双视频的FFmpeg命令并提升性能

Streamlining Your FFmpeg Side-by-Side Command & Boosting Performance

Great job putting together that working FFmpeg command! Let's walk through simplifying it and making it run faster without losing functionality.

Step 1: Trim Unnecessary Filter Steps

Your original command has redundant pad + crop combinations that can be eliminated by calculating the direct crop coordinates on the scaled input videos. Here's the simplified version:

ffmpeg -y -i i1.mov -i i2.mp4 -filter_complex \
"[0:v]scale=1824:1026,crop=1641:923:170:52,scale=1920:1080[vl]; \
 [1:v]scale=2016:1134,crop=1641:923:57:106,scale=1920:1080[vr]; \
 [vl][vr]hstack=shortest=1" \
-c:v libx264 -crf 23 -preset veryfast output.mp4

What Changed:

  • Removed redundant pad filters: The original pad followed by a crop was unnecessary. Instead, we adjusted the crop coordinates to target the exact region you wanted directly on the scaled input, skipping the intermediate padding step.
  • Merged sequential crop steps: For the second input, we combined two back-to-back crop operations into a single one by calculating the absolute coordinates from the original scaled video.

If you want even more brevity (while keeping readability), you can factor out repeated scale targets using filter variables, though for two inputs, it's often clearer to keep each chain explicit.

Step 2: Performance Optimizations

Now let's make this command run faster:

  • Reorder Filters for Efficiency:
    Whenever possible, do crop before scale. Cropping reduces the number of pixels early in the pipeline, which means less work for the subsequent scale filter. If your source videos allow it (i.e., you can crop the original footage to the desired region first), adjust the chain to crop the original input before scaling—this cuts down on pixel processing upfront.

  • Use Hardware-Accelerated Encoding:
    If you have compatible hardware (NVIDIA, AMD, Intel), swap libx264 with a hardware encoder for massive speed gains:

    • NVIDIA: -c:v h264_nvenc -preset p7 (adjust preset from p1 (slow/best) to p7 (fast/good))
    • Intel: -c:v h264_qsv -preset veryfast
    • AMD: -c:v h264_amf -preset fast
  • Tweak Preset & CRF:
    You're already using veryfast, which is a great balance. If you need more speed, try superfast or ultrafast (minor quality hit). To compensate, lower your crf value by 1-2 (e.g., crf 21) to retain similar visual quality.

  • Leverage Threading:
    Add -threads auto to let FFmpeg use all available CPU cores efficiently (most modern versions do this by default, but it never hurts to explicitly set it).

  • Skip Unnecessary Scaling:
    If your final output doesn't need two full 1920x1080 streams side-by-side, scale each input to half the width first, then hstack—this reduces the total pixel count processed. For example, scale each input to 960x1080, hstack gives you 1920x1080 total, avoiding scaling to 1920x1080 per input.

Final Optimized Command Example (with NVIDIA Encoding)

ffmpeg -y -threads auto -i i1.mov -i i2.mp4 -filter_complex \
"[0:v]scale=1824:1026,crop=1641:923:170:52,scale=960:1080[vl]; \
 [1:v]scale=2016:1134,crop=1641:923:57:106,scale=960:1080[vr]; \
 [vl][vr]hstack=shortest=1,scale=1920:1080" \
-c:v h264_nvenc -crf 22 -preset p7 output.mp4

This version is cleaner, runs faster, and maintains your desired output quality.

内容的提问来源于stack exchange,提问作者Zurechtweiser

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:26:38