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

求助:使用FFMPEG实现绿幕片头叠加至视频开头

How to Add a Green-Screen Intro to the Start of a Video with FFmpeg

Got it, let's break this down clearly. You want to take a green-screen video, key out the green, and either play it as a standalone intro before your target video, or overlay it on top of the target video's opening seconds before letting the original video play normally. Here are the two common solutions, with explanations for each part:

Option 1: Play the Keyed Intro First, Then the Target Video (Concatenation)

This is if you want the intro to play fully first, then transition straight to the original video.

Command:

ffmpeg -i green_screen_intro.mp4 -i target_video.mp4 -filter_complex "[0:v]chromakey=0x00FF00:0.1:0.2[intro_v];[intro_v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" final_video.mp4

What each part does:

  • -i green_screen_intro.mp4 -i target_video.mp4: Loads both your green-screen intro and the target video as inputs.
  • [0:v]chromakey=0x00FF00:0.1:0.2[intro_v]: Processes the intro's video stream to remove the green. 0x00FF00 is pure green—if your green screen is a different shade, use ffmpeg -i green_screen_intro.mp4 -vf "colorinfo" to get the exact hex code. The 0.1 is the similarity threshold (higher = more colors get keyed out), and 0.2 is the blend threshold (higher = softer edges around your intro content).
  • [intro_v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]: Concatenates the keyed intro (video + audio) with the target video (video + audio). n=2 means we're joining 2 segments, v=1/a=1 keeps one video and one audio stream.
  • -map "[v]" -map "[a]" final_video.mp4: Outputs the combined video/audio to your final file.

Option 2: Overlay the Keyed Intro on the Target Video's Opening Seconds

This is if you want the target video to start playing immediately, but have the intro overlayed on top for the first X seconds before disappearing.

Command (example for 3-second overlay):

ffmpeg -i target_video.mp4 -i green_screen_intro.mp4 -filter_complex "[1:v]chromakey=0x00FF00:0.1:0.2[intro_v];[0:v][intro_v]overlay=0:0:enable='between(t,0,3)'[v];[0:a][1:a]amix=inputs=2:duration=first[a]" -map "[v]" -map "[a]" final_video.mp4

What each part does:

  • [1:v]chromakey=...[intro_v]: Same keying logic as Option 1, applied to the intro video.
  • [0:v][intro_v]overlay=0:0:enable='between(t,0,3)'[v]: Overlays the keyed intro at the top-left corner (0:0) of the target video, but only between 0 and 3 seconds. Adjust the 3 to match your intro's length.
  • [0:a][1:a]amix=inputs=2:duration=first[a]: Mixes the intro's audio with the target video's audio. duration=first ensures the mix stops when the target video's audio would normally play on its own (or adjust to shortest if you want the mix to stop when the intro ends).

Pro Tips:

  • If your intro and target video have different resolutions, add a scale filter to the intro to match the target: e.g., [0:v]scale=1920:1080,chromakey=...[intro_v] (replace 1920:1080 with your target video's resolution).
  • To smooth the keying edges, add a format=yuva420p before the chromakey: [0:v]format=yuva420p,chromakey=...[intro_v].

Let me know if you need to tweak any part—like adjusting the key color, timing, or audio handling to fit your exact use case!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 07:28:56