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

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

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

How does FFMPEG change fps without dropping frames?

Here I got a video which has the FPS 30, duration 10s, and has 300 frames. How could I turn the video to 25FPS without dropping frames.
I suppose the -r or fps=fps=25 is kind of resampling method or not working.
My commands are like:
ffmpeg -i input.flv -vf "scale=800:450, fps=25" output1.flv
or
ffmpeg -i intput.flv -filter:v fps=fps=25 -c:v libx264 -c:a copy -pix_fmt yuv420p -profile:v high -f mp4 -vf scale=800:450 output2.mp4
The result is that output1.flv dropped frames, and output2.mp4 didn't work.
If you're re-encoding the video stream, then
ffmpeg -r 25 -i input.flv ...
If there's audio, you'll have to adjust its tempo as well by adding
-af atempo=0.834
where 0.834 is 25/30.

ffmpeg rtmp stream taking 100% CPU

I am creating a small script to stream a images on rtmp server but FFMPEG command taking 100% CPU. Please have a look on my code.
ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -loop 1 -i "Digital-Wallet-.jpg" -t 00:30:00 -r 1 -c:v libx264 -c:a aac -preset:v ultrafast -pix_fmt yuv420p -f flv "rtmp://rtmpserver"
Encoding is CPU intensive. Remove -r 1 and add -framerate 1, -re, and -shortest.
ffmpeg -f lavfi -i anullsrc -loop 1 -framerate 1 -re -i "Digital-Wallet-.jpg" -t 00:30:00 -c:v libx264 -c:a aac -preset:v ultrafast -pix_fmt yuv420p -shortest -f flv "rtmp://rtmpserver"
The default image demuxer frame rate is 25, so your command was unnecessarily converting 25 frames per second to 1 frame per second which is inefficient. The above changes fixes that.
-re will slow down the reading of the input to the native frame rate of the input. It is useful for real-time output and live streaming. Otherwise ffmpeg will attempt to encode as fast as possible.
I added -shortest to end the output when the shortest stream ends (the image) because anullsrc was set to encode indefinitely.

FFMPEG (windows7) can't get the output video to show more than 3 out of 10 jpgs

I have 10 jpg files (image0.jpg, image1.jpg, image2.jpg ... image9.jpg) and one .mp3 and I'm trying to create a video but I can't get it to show more than the first 3 images in the output.
I played with the output -r option and for example if I change it to 30 it shows all of them but very fast so the whole video plays for under a second.
This is my code:
ffmpeg -i image%d.jpg -i audio.mp3 -r 1 -c:v libx264 -tune stillimage -c:a aac -strict experimental -b:a 192k -r 1/5 -pix_fmt yuv420p -shortest out.mp4
What am I doing wrong ?
The image file demuxer by default uses a frame rate of 25 fps if you do not tell it otherwise. Since you used -r 1/5 as an output option the frame rate will be converted resulting in duplicated or, as in your case, dropped frames to compensate. To change this use -framerate as an input option (this is a private option of the image file demuxer):
ffmpeg -framerate 1/5 -i image%d.jpg output
Some crappy players may not like a "non-standard" frame rate, so you can add an output frame rate to change it while keeping the "timing" of the input:
ffmpeg -framerate 1/5 -i image%d.jpg -r 25 output

animation between images using FFmpeg

Hi I am new in FFmpeg,
I have made video from slideshow of sequential images (img001.jpg, img002.jpg, img003.jpg....). Using following commands in Ubuntu 14.04
ffmpeg -framerate 1/5 -i img%03d.jpg -c:v libx264 -r 30 -pix_fmt yuv420p -vf scale=320:240 out.mp4
But now I want to put animation like fade-in, fade-out between each sequential images, I want to generate video,
can anybody help me how to make it, i have searched lots of things but could not get....
The best way to do this is create intermediate mpeg's for each image and then concatenate them all into a video. For example, say you have 5 images; you would run this for each one of the images to create the intermediate mpeg's with a fade in at the beginning and a fade out at the end.
ffmpeg -y -loop 1 -i image -vf "fade=t=in:st=0:d=0.5,fade=t=out:st=4.5:d=0.5" -c:v mpeg2video -t 5 -q:v 1 image-1.mpeg
where t is the duration, or time, of each image. Once you have all of these mpeg's, you use ffmpeg's concat command to combine them all into an mp4.
ffmpeg -y -i image-1.mpeg -i image-2.mpeg -i image-3.mpeg -i image-4.mpeg -i image-5.mpeg -filter_complex '[0:v][1:v][2:v][3:v][4:v] concat=n=5:v=1 [v]' -map '[v]' -c:v libx264 -s 1280x720 -aspect 16:9 -q:v 1 -pix_fmt yuv420p output.mp4
This gives you the desired video and is the simplest and highest quality solution with ffmpeg. Let me know if you have any questions about how the above command works.

Resources