FFMPEG CROP BLACK BARS BAD QUALITY - ffmpeg

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.

Related

Merge/Blend/Composite transparent webm files with a jpg/png using ffmpeg

I previously had generated color.webm and alpha.webm files withffmpeg using png images.
However, when I play the generated videos in my application it consumes quite some resources so I have decided to create a standard video(No alpha needed), I cannot re-record the videos as there are a lot of them at this point.
I am generating the alpha and color video using the following command ffmpeg -framerate 30 -i img%d.png -filter_complex "alphaextract[a]" -map 0:v -c:v libvpx-vp9 -pix_fmt yuv420p -auto-alt-ref 0 -crf 15 -b:v 0 color.webm -map "[a]" -c:v libvpx-vp9 -pix_fmt yuv420p -auto-alt-ref 0 -crf 15 -b:v 0 alpha.webm
I am looking to get a final video output where in alpha values are replaced with the png/jpg image, it's more like replacing the green screen with a background however in my case greenscreen is the alpha channel.
Could any one let me know how to combine alpha.webm, color.webm with a jpg/png image without minimal or no quality loss?
.

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

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.

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

Scale watermark in ffmpeg based on video size [duplicate]

i have some videos and i want to add watermark to them
but problem is coz in every video "watermark size" is different
(in some videos watermark is smaller and in some is bigger - i think because of video input size coz its different)
here is my ffmpeg command (just link is different)
ffmpeg -i "http://VIDEO-LINK" -i "/var/www/logo/logo.png" -filter_complex 'overlay=17:17' -vcodec h264 -crf 25 -preset veryfast -maxrate 600k -bufsize 600k -aspect '640:360' -s '640:360' -acodec libfdk_aac -hls_time 10 -hls_wrap 10 -start_number 1 -y "1.m3u8"
is there a way to make any percentage or fixed watermark based on output which is 640x360
coz if input video is 640x360 it show big watermark with this command
if input link is 1280x720 then watermark is so small
You can use the scale2ref filter.
-filter_complex "[1][0]scale2ref=iw/8:ih/8[wm][vid];[vid][wm]overlay=17:17[out]"
If the aspect ratio of your watermark is not the same as your video inputs, then the scale2ref will distort your logo. It's best to perform a one-time operation where the logo is padded so that the image has the same aspect ratio as your videos.

Resources