FFmpeg Drawtext Fade Out Performance - ffmpeg

I am developing an application that makes system calls to FFmpeg.
I found a way to get the drawtext filter isolated and fade out, but the render time increased about 5x.
I just want to see if there is something obviously wrong with the command I came up with.
ffmpeg -y -i input.mp4 -c:v libx264 -filter_complex "[0]scale=1920:1080,format=rgba, split[base][text];[text]drawtext=fontfile=font1.ttf:text='Text1':fontcolor= 'white':fontsize=34:box=1:boxcolor=mediumpurple:boxborderw=50:x=0:y=690,format=yuva444p,drawtext=fontfile=./resources/fonts/font2.ttf:text='Text2':fontcolor='white':fontsize=26:x=0:y=725,fade=t=out:st=12:d=0.2:alpha=1[title];[base][title]overlay" -force_key_frames "expr:gte(t,n_forced*0.05)" output.mp4

Yes! There is something obviously wrong with it. There is no need to split the stream and process both.
After some trial and error, I was able to put together this command which runs much much faster; virtually no overhead to add the fading title card.
ffmpeg -i input.mp4 -filter_complex "scale=1920:1080,drawtext=fontfile=font1.ttf:text=Text1':fontcolor='white':fontsize=34:box=1:boxcolor=mediumpurple:boxborderw=50:x=12:y=690:alpha='min(between(t,0,2.2),lerp(0,1,(1+((2-t)/0.2))))',drawtext=fontfile=font2.ttf:text='Text2':fontcolor='white':fontsize=26:x=12:y=730:alpha='min(between(t,0,2.2),lerp(0,1,(1+((2-t)/0.2))))'" output.mp4

Related

ffmpeg how to place still image over full vstack?

Im trying to build a simple video editor and im using ffmpeg on the background. I want as much different filters/properties in one command but im not succeeding in placing a still image before everything else (first frame). I want a vstack after the image has shown in a video.
I tried a lot of different commands etc. and most of the time the video renders but the image included in the vstack, or the video doesn't start for the amount of seconds I want the still image to be shown.
ffmpeg -hide_banner -i "header.jpg" -i "video.mp4" -i "footer" -i "still-image.jpg" -filter_complex "[1][3]overlay=0:0:enable='between(t,0,4)';vstack=inputs=3" -pix_fmt yuv420p -c:a copy -y output.mp4
Most of the time I don't get an error. It just isn't doing what's expected. The above command is one of the many I tried but is basically what I want. Can someone help please?
There are several ways to do this. This method delays the vstack and overlays still-image.jpg during the delay.
ffmpeg -i "header.jpg" -i "video.mp4" -i "footer.jpg" -i "still-image.jpg" -filter_complex "[0][1][2]vstack=inputs=3[v0];[v0]tpad=start_duration=4[bg];[bg][3]overlay=(W-w)/2:(H-h)/2:enable='between(t,0,4)',format=yuv420p[v];[1:a]adelay=4s:all=true[a]" -map "[v]" -map "[a]" output.mp4
Requires FFmpeg 4.2 or newer.

The audio disappears from 2/3 of the video after speeding up with ffmpeg

I have tried to speed up a video file (with the audio stream) 8 times with ffmpeg using the script below. All works well that from a 50 hour video I get a 7-hour video with the audio sped up also, yet in the resulting file the audio lasts for just over 2 hours and silences after that, i.e. there video without audio.
ffmpeg -i video.mp4 -filter_complex "[0:v]setpts=0.5*PTS,setpts=0.5*PTS,setpts=0.5*PTS[v];[0:a]atempo=2.0,atempo=2.0,atempo=2.0[a]" -map "[v]" -map "[a]" video_x8.mp4
EDIT:
video.mp4 file
video_x8.mp4 file (naming is different for the clear picture)
EDIT 1.
Here are the full 100MB logs. https://gofile.io/?c=L0Au2e
EDIT 2: Thank you Gyan. But could you please help me write it in 1 command so that it works in 1 go?
As far as I can tell, the atempo (whether due to the chaining or otherwise), is not updating timestamps correctly, so the remedy is to insert asetpts afterwards.
ffmpeg -i video.mp4 -vf "setpts=0.125*PTS" -af "atempo=8.0,asetpts=N/SR/TB" video_x8.mp4

Converting multiple ffmpeg command into one line (burn subtitle & watermark)

i'm first burning subtitles of mkv and then adding watermark which is taking so long to convert one video. It takes like x2 time i guess. For example on my current server it takes 30 min on each command. My server may not be good enough. But i was thinking if there way to do this in one command instead? will it effect the speed? i really have almost zero knowledge on ffmpeg:
here is command for burning subtitle. I'm using python for achieving this:
ffmpeg -i subtitles=/Users/Test/Desktop/test.mkv -vf subtitles=subtitles=subtitles=/Users/Test/Desktop/test.mkv -c:v libx264 -c:a aac -preset ultrafast -strict -2 /Users/Test/Desktop/test.mp4
command for adding watermark:
ffmpeg -i /Users/Test/Desktop/test.mp4 -i /Users/Test/Desktop/watermark-logo.png -filter_complex "[1][0]scale2ref=w='iw*10/100':h='ow/mdar'[wm][vid]; [vid][wm]overlay=main_w-overlay_w-5:main_h-overlay_h-5" /Users/Test/Desktop/output.mp4
If there are more ways to speed up then kindly let me know. All i want to achieve this faster and expecting best result.
Thank you.
First apply the subtitles on the video and then feed that to scale2ref inside the complex filtergraph.
Use
ffmpeg -i /Users/Test/Desktop/test.mkv -i /Users/Test/Desktop/watermark-logo.png -filter_complex "[0]subtitles=/Users/Test/Desktop/test.mkv[v];[1][v]scale2ref=w='iw*10/100':h='ow/mdar'[wm][vid]; [vid][wm]overlay=main_w-overlay_w-5:main_h-overlay_h-5" -preset fast /Users/Test/Desktop/output.mp4

FFMPEG - Speed up video for time lapse - quicker/faster?

Okay, I know this question has been asked a bajillion times. However, I have one small addition to the question that I haven't seem to have been able to find in my googling.
I'm certainly not a pro at FFMPEG...I've been using the standard speed up/slow down template for FFMPEG, the one I'm using is:
ffmpeg -i input.mp4 -filter:v "setpts=PTS/60" -an output.mp4
I'm currently working with an hour long 4K/60FPS video...I want to shrink it down to about 30 seconds or so, so I'm using PTS/100, and I don't need audio...the problem is, this is taking FOREVER...which I completely expected it to.
But as I'm sitting here waiting for it to finish...I can't help but wonder...is there a faster/more efficient way to accomplish this? I know there's a lot of weird things about FFMPEG in regards to the order of the commands you use to speed up seek time, and presets and etc.
You can use
ffmpeg -itsscale 0.016667 -i input.mp4 -c copy -an output.mp4
where 0.016667 is 1/60.
However, this will keep all frames, and if the input timebase doesn't have sufficient resolution, you'll have incorrect timestamps. You can work around that by creating a temp file first.
ffmpeg -i input.mp4 -c copy -video_track_timescale 90k -an temp.mp4
and then running the first command on this temp file.
This sequence of commands may be helpful to solve that issue:
ffmpeg -i source.avi -r 0.016667 image/image%05d.bmp
ffmpeg -i image/image%05d.bmp -vcodec libx264 -b:v 500k -f avi video.avi

overlay audio volume histogram over static image

I'm actually working to a project for music video generation using ffmpeg.
I'd like to know if it's possibile to use ffmpeg itself or a combination of command line component under windows environment to make a visualization of audio spectrum (ahistogram ?) over a static background image like the one I found on the web:
Any ideas or coding tips?
ffmpeg -loop 1 -i background.png -i music.mp3 -filter_complex "[1]ahistogram=s=789x50:rheight=1[fg];[0][fg]overlay=(W-w)/2:H-h-10:shortest=1,scale='iw-mod(iw,2)':'ih-mod(ih,2)',format=yuv420p[v]" -map "[v]" -map 1:a -movflags +faststart output.mp4
Not exactly what you want, there is no option to create bars as in your image, but perhaps this will be good enough. See the ahistogram filter documentation for more options.

Resources