Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend plain background in a video

Is there any easier way to achieve this?, I'd like to make a .bat file that modify 148 videos that are 3840x2160

They belong to the COLORFUL platform video set 1.8.0

Every video has a system or console in the middle of it and it has a plain color as background. I want to keep the resolution, 3840x2160 but I need to displace the image a 15% to the right so it will be neccesary to fill the left area with the same color it's being use as color of the background.

This is a snapshot from one of these videos:

Snapshot of the original video

The result should be something like this:

Snapshot of the video I'd like to get

So far I was trying lot of things with no success, I maybe did it harder than it is really. I did a first script that crop the video:

for %%X in (*.mp4) do .\ffmpeg\bin\ffmpeg.exe -threads 4 -i "%%X" -filter:v "crop=2688:ih" -c:a copy -threads 4 "second_script\%%X"

The new video will be stored in the second_script folder, then there is a second script that will use ffmpeg to export a picture from the video and magick.exe will help me to identify the color, after that it will use ffmpeg again to add an are of that color, but ... for some reason I don't know the color result is not the same

for %%X in (*.mp4) do (
..\ffmpeg\bin\ffmpeg.exe -threads 4 -i "%%X" -vf "select=eq(n\,100)" -vframes 1 %%~nX.png

magick.exe .\%%~nX.png -format "%%[hex:u.p{0,0}]" info: > temp.txt

for /f "delims=" %%i in (temp.txt) do (
..\ffmpeg\bin\ffmpeg.exe -threads 4 -i "%%X" -filter_complex "[0]pad = w=3840 : h=ih: x=3840-2688 : y=0 : color=#%%i" -movflags +faststart  -c:a copy -threads 4 "final\%%X"
)

)

What I get is something like this:

Final result, it doesn't look like I expected

Would there be any easy way to do this? any recommendation is really appreciate

like image 225
Maiki Avatar asked Oct 17 '25 17:10

Maiki


1 Answers

You can do it in one command, like this

ffmpeg -i in.mp4 -vf "split=2[bg][img];[bg]trim=end_frame=1,crop=128:ih,scale=3840:2160:flags=neighbor,setsar=1[bg];[bg][img]overlay=w=0.15*W:h=0" -c:a copy out.mp4

like image 199
Gyan Avatar answered Oct 20 '25 13:10

Gyan