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

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.

Related

ffmpeg only shows one Image?

Here are the images I have in my folder:
img001.png
img002.png
They are stored in c:/frames.
Because that my frames are not shown correctly, used the FPS filter video shown below (documentation from https://trac.ffmpeg.org/wiki/Slideshow):
ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4
I tried running on my VLC media player but it still doesn't work. It only shows one image.
The last frame of an image sequence will only be shown for an instant. Use tpad filter to clone it once and then apply other filters like fps.
ffmpeg -framerate 1/5 -i img%03d.png -vf "tpad=stop=1:stop_mode=clone,fps=25" -pix_fmt yuv420p -c:v libx264 out.mp4

FFMPEG CROP BLACK BARS BAD QUALITY

Hello im using this command to remove the black bars and make the video fullscreen ,
ffmpeg -i 1.mkv -vf "crop=1920:800:0:140,scale=1920:1080,setsar=1" -c:v h264_nvenc -rc:v vbr_hq -cq:v 0 -b:v 27000k -maxrate:v 26000k -profile:v high -preset slow og1.mkv
It works good ,
But the problem is the quality of the video, there is a lot of difference between the original and the new,and apart from that it's like the video is a bit stretched because of the new crop settings.

FFMPEG, any video to 16:9

Help me find a command or script that will convert any video to 16:9, h264 and ~2500kbps. I have a server where people upload videos of different quality, size and length. It can be either 640x480 or 1216x2160. Ultimately, I need to get any resolution to 16:9 (with black borders, if needs) and bitrate without visible loss of quality, which will be acceptable for online broadcasting.
I have this command, but it does not check the resolution of the video. And if the video was 560x448 1000kbps and 700mb, then after conversion it will be 1280x720 3000kbps and 1.5gb, that's not right.
ffmpeg -i 5.avi -vcodec libx264 -crf 23 -preset veryfast -vf scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1 -tune zerolatency highoutput.mp4
Please try the following as a starting point:
ffmpeg -i "5.avi" -vcodec libx264 -crf 23 -vf "scale=w=trunc(ih*dar/2)*2:h=trunc(ih/2)*2, setsar=1/1, scale=w=1920:h=1080:force_original_aspect_ratio=1, pad=w=1920:h=1080:x=(ow-iw)/2:y=(oh-ih)/2:color=#000000" "output.mp4"
Please tweak the crf value depending on the picture quality.
Use
-vf scale=iw*sar:ih,setsar=1,pad='max(iw+mod(iw,2),2*trunc(ih*16/9/2))':'max(ih+mod(ih,2),2*trunc(iw*9/16/2))':-1:-1

Add unique color watermark per frame with 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

Creating video from audio and resized image using FFMPEG

Im trying to create an mp4 video from an mp3 and an image with ffmpeg. The video should be the size of 640x360 with black background and the image should be resized to fit in this dimensions and centred in the middle. The video's length must match the mp3's length.
Its basically a video creation for youtube from a song and an artwork.
For now i was able to achieve this with 3 steps:
resize image:
-i %image% -vf scale='if(gt(a,4/3),640,-1)':'if(gt(a,4/3),-1,360)' %resized_image%
create a music video with black background:
-f lavfi -i color=s=640x360 -i %audio_file% -c:v libx264 -s:v 640x360 -c:a aac -strict experimental -b:a 320k -shortest -pix_fmt yuv420p %video%
put the resized image centred in the video:
-i %video% -i %resized_image% -filter_complex "overlay=(W-w)/2:(H-h)/2" -codec:a copy %final_video%
Is it possible to achieve all this with one ffmpeg command ?
Single command would be
ffmpeg -loop 1 -i image -i audio
-vf scale='if(gt(a,4/3),640,-1)':'if(gt(a,4/3),-1,360)',pad=640:360:(ow-iw)/2:(oh-ih)/2,format=yuv420p
-c:v libx264 -c:a aac -b:a 320k -strict -2 -shortest final.mp4

Resources