Add unique color watermark per frame with FFMpeg - ffmpeg

I've been able to add a random color watermark with this code:
ffmpeg -y -r 100 -i "N%3d.tif" -c:v libx264 -vf "drawbox=y=0:color=random#1:width=8:height=ih:t=fill,scale=1920:1080" -crf 30 -g 10 -profile:v high -level 4.1 -pix_fmt yuv420p test.mp4
And I know that it's doable with a script and processing each input frame individually, but I would really like to find a way with FFMpeg to add the watermark during the actual video encoding. It needs to be a unique color per frame. Any ideas on how to accomplish this?
Thanks!

The drawbox expression is only evaluated once. But the hue filter can be used to vary the color.
In the command below, a small portion from the left side of the frame is cropped off, a color is drawn once, and then its hue varied. This is then overlaid on the full frame.
ffmpeg -y -framerate 100 -i "N%3d.tif"
-filter_complex "[0]split=2[wm][vid];[wm]crop=8:ih,drawbox=color=random#1:t=fill,
hue=n*random(1234)[wm];[vid][wm]overlay,scale=1920:1080"
-c:v libx264 -crf 30 -g 10 -profile:v high -level 4.1 -pix_fmt yuv420p test.mp4

Related

FFMPEG Overlay 1080X1920 video over 1280X720 video at a particular vertical position

I have a 1080X1920 (vertical) video with alpha channel with a blank spot 500px north of the bottom. This blank spot is 1080X607.
I have a 1280X720 sized video I want to position in that spot, so the 1280 video will have to be sized down to 1080 wide and then positioned 500px from the bottom and UNDER the video on top.
This is what I currently have, but it is failing beautifully.
/usr/local/bin/ffmpeg -i 1080x1920.mov -i 1280x720.MOV
-filter_complex "[1][0]overlay=main_w-overlay_w-0:main_h-overlay_h-500"
-c:v libx264 -profile:v high444 -pix_fmt yuv420p -level 3.1 -y final.mp4
You have to pad the rescaled 720p video with the correct margins and then carry out the overlay.
ffmpeg -i 1080x1920.mov -i 1280x720.MOV
-filter_complex "[1]scale=1080:-1,pad=1080:1920:0:1920-500-607[1v];[1v][0]overlay=0:0"
-c:v libx264 -profile:v high444 -pix_fmt yuv420p -level 3.1 -y final.mp4
Note that high444 profile bitstream may not be compatible with many players.

FFMPEG is zoompan works on first and last only

I want to convert images to video which works fine with ffmpeg but i need to add ken burns effect to every images.
the code i was to get only only works on the last and first images (the effect i mean).
ffmpeg -y -i %d.jpg -t 25 -pix_fmt yuv420p -vf zoompan=z='zoom+0.001':s=1280x800,scale=hd1080 -c:v libx264 -preset fast -crf 22 -t 300 -threads 2 zoomout.mp4
SOLVED
the problem is from the images, so i used new set of images

Crop, Resize and Cut all in one command - FFMPEG

I am trying to do three tasks with FFMPEG
Crop a video without losing quality
Resize (upscale) the cropped video with good quality
Cut specific part of a the upscaled vided without losing quality
Here are the command line I use:
to crop: video og.mp4 to video og1.mp4
ffmpeg -i og.mp4 -vf "crop=1330:615:22:120" -c:v libx264 -crf 1 -preset veryslow -c:a copy og1.mp4
to resize: video og1.mp4 (converted above) to video og2.mp4
ffmpeg -i og1.mp4 -vf scale=1920:-1 -c:v libx264 -crf 1 -preset veryslow -c:a copy og2.mp4
to cut: video og2.mp4 (converted above) to og3.mp4
ffmpeg -i og2.mp4 -ss 00:00:08.190 -t 00:00:11.680 -c:v libx264 -crf 1 -preset veryslow -c:a copy og3.mp4
I want to achieve highest quality of 1920 width video (irrespective of height and size of the file)
Is there a way to get the above tasks in one command or shorter time with best quality?
Also advice if there is a better command or parameters to be used.
Thanks
You can combine all commands by using a single filterchain, and adding the trim as well
ffmpeg -ss 8.190 -t 11.680 -i og.mp4 -vf "crop=1330:615:22:120,scale=1920:-2" -c:v libx264 -crf 1 -c:a copy og1.mp4
With crf 1, a slow preset is unnecessary.

Efficient command line to crop a video, overlay another crop from it and scale the result with ffmpeg

I need to convert many videos in such a way that I take 2 different crops from each frame of a single video, stack them one over the other and scale down the result, creating a new smaller video.
I want to convert this fullHD frame (two crop areas are marked red) to this small stacked frame.
Right now I use the following code:
ffmpeg -i "video.mkv" -filter:v "crop=560:416:0:0" out1.mp4
ffmpeg -i "video.mkv" -filter:v "crop=560:384:1060:128" out2.mp4
ffmpeg -i out1.mp4 -vf "movie=out2.mp4[inner]; [in][inner] overlay=0:32,scale=280:208[out]" -c:v libx264 -preset veryfast -crf 30 result.mp4
It works but it is very inefficient and requires temporary files (out1 and out2). And the problem is I have over 100.000 of such videos (they are big and stored on a NAS and not directly on my computer's HDD). Converting all of them with a Windows batch script (for loop) will take...48 days. Can you help me to optimize the script?
Use the crop, vstack, scale, and format filters:
ffmpeg -i input.mkv -filter_complex "[0:v]crop=560:24:0:0[top];[0:v]crop=560:384:1076:128[bottom];[top][bottom]vstack,scale=280:-2[out]" -map "[out]" -c:v libx264 -preset veryfast -crf 30 -movflags +faststart result.mp4
If you want to complicate it somewhat for faster filtering (maybe) then you can try scaling first:
ffmpeg -i input.mkv -filter_complex "[0:v]scale=iw/2:-1,split[v0][v1];[v0]crop=560/2:24/2:0:0[top];[v1]crop=560/2:384/2:1076/2:128/2[bottom];[top][bottom]vstack[out]" -map "[out]" -c:v libx264 -preset veryfast -crf 30 -movflags +faststart result.mp4
You'll have to experiment to see which is fastest for you.

Fade out in ffmpeg when creating a video from a still image is wonky?

I'm creating a video that:
uses a still image as a source
has a text overlay
fades in and out
has a silent stereo audio track.
So far, I have this, and it (almost) works correctly:
ffmpeg -f lavfi -i "aevalsrc=0|0" -loop 1 -i turtle-2.jpg -c:v libx264 -t 5 -r 30 -s 1920x1080 -aspect 16:9 -pix_fmt yuv420p -filter:v drawtext="fontsize=130:fontfile=comic.ttf:text='hello world':x=(w-text_w)*.25:y=(h-text_h)*.75",fade=in:0:60,fade=out:90:60 -acodec aac turtle11.mp4
The only problem is that the fade out doesn't seem to be going to black, even tho this is a 150 frame video and I believe I am following the ffmpeg documentation correctly.
The resulting video is here:
http://video.blivenyc.com/vid-from-image/turtle11.mp4
Any thoughts?
Well, I'm not sure why but this works, even tho it appears to be equivalent:
ffmpeg -f lavfi -i "aevalsrc=0|0" -loop 1 -i turtle-2.jpg -c:v libx264 -t 5 -r 30 -s 1920x1080 -aspect 16:9 -pix_fmt yuv420p -filter:v drawtext="fontsize=130:fontfile=comic.ttf:text='hello world':x=(w-text_w)*.25:y=(h-text_h)*.75",fade=t=in:st=0:d=1,fade=t=out:st=4:d=1 -acodec aac turtle12.mp4
Basically, frame-based syntax:
fade=in:0:60,fade=out:90:60
gets substitued with time-based:
fade=t=in:st=0:d=1,fade=t=out:st=4:d=1
And somehow it works. Not sure why this is.
The video stream on which the fade filter operates is not 150 frames long. Input and output framerates are different here. The use of -r to set output rate happens after all filtering is done. At that stage, ffmpeg will drop or duplicate frames to obtain the output rate.
The input rate for an image or image sequence is 25, unless expressly set otherwise. In your command, since there is no override, it's 25. So fade out of 60 frames starting at frame 90, will end at frame 125 (5 seconds x 25). ffmpeg will duplicate 5 frames of each input second to get it to 30.
To get the desired result, use
ffmpeg -f lavfi -i "aevalsrc=0|0" -loop 1 -framerate 30 -i turtle-2.jpg -c:v libx264 -t 5 -s 1920x1080 -aspect 16:9 -pix_fmt yuv420p -filter:v drawtext="fontsize=130:fontfile=comic.ttf:text='hello world':x=(w-text_w)*.25:y=(h-text_h)*.75",fade=in:0:60,fade=out:90:60 -acodec aac turtle11.mp4

Resources