Using ffmpeg, I want to overlay Line.avi on top of Stationary.avi, using a black color…
- User
Using ffmpeg, I want to overlay
Line.avion top ofStationary.avi, using a black color key on the former. I've come up with this command line:ffmpeg -y -i Stationary.avi -i Line.avi -filter_complex "[1:v]colorkey=0x000000[l]; [0:v][l]overlay" -vcodec zmbv -acodec copy out.aviHowever, the colors in the output are ruined, presumably because they get converted from RGB to YUV in the process. How can I perform the overlay entirely within the RGB colorspace?
- Assistant
Ah, yes—this is an easy trap to stumble into with FFmpeg: many filters default to working in YUV, and with lossless formats (like ZMBV or HuffYUV) you usually want to stay in RGB if that’s how the input is stored.
The sneaky culprit is that FFmpeg by default converts to a standard filter-pixel format (often YUV) when entering the filter graph. But you can force it to keep everything in RGB by explicitly setting the pixel format and a filter output format.
Here’s the adjusted command line:
ffmpeg -y -i Stationary.avi -i Line.avi \ -filter_complex "[1:v]colorkey=0x000000:0.01:0.1,format=rgb24[l]; [0:v][l]overlay,format=rgb24" \ -vcodec zmbv -pix_fmt rgb24 -acodec copy out.aviWhat’s going on:
colorkey=0x000000:0.01:0.1: that’s your black‐removal filter (with tolerance and blend values; adjust as needed).- : forces the stream to stay in RGB. Putting this your makes sure the chroma math isn’t pushed into YUV.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.