I'm trying to convert a video with black bars, to one without and if the source is 4k, I want the video to be converted to 1080p
Now to do this, I'm using the following command:*
ffmpeg -i input ... -filter:v "crop=..." -filter:V "scale=1920:-1" ouput
But running this, I found that the end product still has said black bars and is 1920x1080 as opposed to the 1920x800 I'd expect.
What gives, why does this not work?
*: Other settings have been left out for convenience.
I got it to work by putting both the crop and the scale in the same -vf tag. I was cropping and then increasing the size of an old video game, and I just did this:
-vf crop=256:192:2:16,scale=-2:1080:flags=neighbor
I knew it worked as soon as I saw it display the output file size as 1440x1080 (4:3 ratio at 1080p).
Related
I'm using ffmpeg to join frames into a video with some parameters.
Here is a sample of the commands I run :
"ffmpeg -y -r 24 -f image2 -i "C:\Users\Pictures\me\frame%04d.bmp" -filter_complex "[0:v]select=between(n,0,76)[selected];[selected]crop=in_w:in_h-60-60:0:60[cropped];[cropped]scale=w=2ceil(2048.0/20.5):h=2ceil(858.0 /20.5) " -c:v libx264 -q:v 1 -b:v 2M "C:\Users\me\Video\output.mp4""
When I run this command I have calculated the size of my cropping on the frames to remove black rectangles at the top and bottom of the frame (I tried using cropdetect but it doesn't fit my usecase so I'm using another soft).So my first that was that ffmpeg would crop on the input stream so it would only crop my black rectangles. But when I change my scale it crops a part of the image.
So my understanding is that ffmpeg crops after scaling (maybe I'm wrong) and if I get the crop parameters on the input images it is sure the they will be wrong if I apply them on the scaled video.
I tried using ";" and "," to separate my filters. I tried naming and not naming my streams between filters. Nothing seems to solve my issue.
What could I do to fix that or am I understanding the issue incorrectely?
Thanks in advance
So actually I didn't understand the problem correctly. The filters are indeed applied in the correct order but it seems like "scale" crops my video again so I'm losing the bottom of my images.
I'm gonna investigate that.
I have two problems with FFmpeg, when I use it to join DNG files sequence into mp4 video file. I also need to downgrade the resolution of the video from 6016x3200 to 2030x1080.
First of all I got almost black screen in the resulting video. Had to play with gamma and brightness options. But it was not enough!
New problems:
something strange happens with aspect ratio in resulting video file: in the first frame aspect is normal, just like in the original picture, but all the rest frames are getting squeezed. can't figure out why this happen!? (see picture attached).
colors are desaturated. despite the fact that I set "saturation" option to the maximum value. and also, the first frame of the video is different from the rest (while DNG files are all similar, first is no exception)
I tried prores codec as well, with the same result.
command I use is simple:
ffmpeg.exe -start_number 1 -i "K:\video\copter_R%5d.dng" -c:v libx264 -vf "fps=25,format=yuv420p, eq=gamma=3.2:brightness=0.2:contrast=1.6:saturation=3, scale=w=2030:h=1080" e:\output.mp4
I tried to use different variants of scale parameter: "scale=-1:1080" as well.
Illustration:
UPDATE: ffmpeg log report for operation:
https://drive.google.com/file/d/1H6bdpU0Eo4WfR3h-SRtgf7WBNYVFRwz2/view?usp=sharing
I have an FMPEG command to scale down a video and add a blur to the background to fill the remaining height to 1136, plus add an overlay image, but it comes out at double the size I want. I am trying to get the whole video down to a 640 width without the overlay video being cropped or sized up. I've tried switching around every number but can't seem to get it to work with a width of 640. Thank you for any help.
ffmpeg -i '/z.mp4' -i '/a.png' -filter_complex "[0:v]scale=128/81*iw:128/41*ih,boxblur=luma_radius=min(h\,w)/40:luma_power=3:chroma_radius=min(cw\,ch)/40:chroma_power=1[bg];[bg][0:v]scale=1280:720,overlay=(W-w)/2:(H-h)/2,setsar=1,crop=w=iw*81/128[bg];[bg][1:v]overlay=82.8:118.8" '/h.mp4';
Use
ffmpeg -i '/z.mp4' -i '/a.png'
-filter_complex
"[0:v]scale=-1:1136,
boxblur=lr=min(h\,w)/40:lp=3:cr=min(cw\,ch)/40:cp=1,crop=640:1136[bg];
[0:v]scale=640:-1[vid];
[bg][vid]overlay=(W-w)/2:(H-h)/2[bg];
[bg][1:v]overlay=82.8:118.8,setsar=1" '/h.mp4'
I am generating an animated gif from an mp4 ... but due (I think) to color reduction (gif requires -pix_fmt rgb24) the result is somewhat ... blotchy? like running an image through an oil paint (or maybe "posterize") special effect filter. I think that the quality could be better, but I don't know what to tweak.
Not sure about this ... but ooking at the color palette of the resulting gif in an image editor it does not even appear to have attempted to create a color palette specific to this clip, but instead is attempting to us a generic palette ... which wastes a lot of pixmap space. That is, if I am interpreting this correctly.
Any tips on preserving the original video image instead of getting a "posterized" animated gif?
To get better looking gifs, you can use generated palettes. palettegen filter will generate a png palette to use with the paletteuse filter.
ffmpeg -i input.mkv -vf palettegen palette.png
ffmpeg -i input.mkv -i palette.png -lavfi paletteuse output.gif
You can try using -vf format=rgb8,format=rgb24.
I want to create a slideshow of my images with fade in & fade out transitions between them and i am using FFmpeg fade filter.
If I use command:
ffmpeg -i input.mp4 "fade=in:5:8" output.mp4
To create the output video with fade effect, then it gives output video with first 5 frames black and than images are shown with fade in effect but i want fade:in:out effect between frame change.
How can i do that?
Please tell a solution for Centos server because i am using FFmpeg on this server only
To create a video with fade effect, just break the video into parts and create separate videos for each image. For instance, if you have 5 images then firstly, create 50-60 copies of each image and obtain a video for that:
$command= "ffmpeg -r 20 -i images/%d.jpg -y -s 320x240 -aspect 4:3 slideshow/frame.mp4";
exec($command." 2>&1", $output);
This will allow you to create 5 different videos. Then, you need 10-12 different copies of those five images and again create separate videos with fade effects.
ffmpeg -i input.mp4 "fade=in:5:8" output.mp4
After this you will have videos like: video for image 1 and its fade effect then for image 2 and its fade effect and so on. Now combine those videos in respective order to get the whole video.
For combining the videos you need:
$command = "cat pass.mpg slideshow/frame.mpg > final.mpg";
This means to join the videos using cat and then you need to convert them to mpg, join them and again reconvert them to mp4 or avi to view them properly. Also the converted mpg videos will not be proper so do not bother. When you convert them to mp4, it will be working fine.
You can make a slideshow with crossfading between the pictures, by using the framerate filter. In the following example 0.25 is the framerate used for reading in the pictures, in this case 4 seconds for each picture. The parameter fps sets the output framerate. The parameters interp_start and interp_end can be used for changing the fading effect: interp_start=128:interp_end=128 means no fading at all. interp_start=0:interp_end=255 means continuous fading. When one picture has faded out and the next picture has fully faded in, the third picture will immediately begin to fade in. There is no pause for showing the second picture. interp_start=64:interp_end=191 means half of the time is pause for showing the pictures and the other half is fading. Unfortunately it won't be a full fading from 0 to 100%, but only from 25% to 75%. That's not exactly what you might want, but better than no fading at all.
ffmpeg -framerate 0.25 -i IMG_%3d.jpg -vf "framerate=fps=30:interp_start=64:interp_end=192:scene=100" test.mp4
You can use gifblender to create the blended, intermediary frames from your images and then convert those to a movie with ffmpeg.