Ffmpeg speed processing time - ffmpeg

I have made this ffmpeg code but it is very slow to process. The backgroundvideo.mp4 is 4k but the final output is 960x540. Is ffmpeg processing the effects in 4k and than scale the video? Should I write the script in other order or should I downscale the video and than apply the other filters?
ffmpeg -t 00:00:09 -i "backgroundvideo.mp4" -i "photo.jpg" -i logo.png \
-filter_complex "[0]boxblur=20[video];[1][video]scale2ref=w=oh*mdar:h=ih/1.2[photo][video];\
[video][photo]overlay=(W-w)/2:(H-h)/2:format=auto[bg];\
[bg][2]overlay=0:0,subtitles=subtitle.ass:force_style='WrapStyle=0,format=yuv420p" \
-i "audio.wav" -map 0:v:0 -map 3:a:0 -vcodec h264_nvenc \
-s 960x540 -shortest -r 25 -crf 17 -aspect 16/9 output.mp4
thanks

Downscale before adding more filters:
ffmpeg -t 00:00:09 -i "backgroundvideo.mp4" -i "photo.jpg" -i logo.png -i "audio.wav" -filter_complex "[0]scale=960:-2,boxblur=20[video];[1][video]scale2ref=w=oh*mdar:h=ih/1.2[photo][vid];[vid][photo]overlay=(W-w)/2:(H-h)/2:format=auto[bg];[bg][2]overlay=0:0,subtitles=aegisub.ass:force_style='WrapStyle=0',format=yuv420p[v]" -map "[v]" -map 3:a:0 -vcodec h264_nvenc -shortest -r 25 -crf 17 output.mp4

Related

How to combine this 2 ffmpeg commands?

I need to combine this 2 ffmpeg commands:
"-i videoFile.mp4 -c:a copy -c:v libx264 -vf pad=$length:height=$length:x=-1:y=-1:color=#195766 resultFile"
and
"-i videoFile.mp4 -i waterMark.png -filter_complex 'overlay=10:main_h-overlay_h-10' resultFile.mp4"
Is it possible? How result command will look like?
I hope I have got it right...
The combined command is:
ffmpeg -y -i videoFile.mp4 -i waterMark.png -c:a copy -c:v libx264 -filter_complex "[0:v]pad=384:height=216:x=-1:y=-1:color=#195766[t];[t][1:v]overlay=10:main_h-overlay_h-10[v]" -map "[v]" -map 0:a resultFile.mp4
For mobile FFmpeg on android (according to OP's comment):
"-y -i ${videoFile.absolutePath} -i $waterMarkPath -c:a copy -c:v libx264 -filter_complex pad=$length:height=$length:x=-1:y=-1:color=#195766[t];[t][1:v]overlay=10:main_h-overlay_h-10[v] -map [v] -map 0:a ${resultFile.absolutePath}"
I used the following post as reference: Create video with 5 images with fadeIn/out effect in ffmpeg.
Testing:
Creating a sample video file (with audio):
ffmpeg -y -r 25 -f lavfi -i testsrc=size=192x108:rate=30 -f lavfi -i sine=frequency=400 -f lavfi -i sine=frequency=1000 -filter_complex amerge -vcodec libx265 -crf 17 -pix_fmt yuv420p -acodec aac -ar 22050 -t 30 videoFile.mp4
Creating a sample PNG image file:
ffmpeg -y -f lavfi -i mandelbrot=rate=1:size=192x108 -t 1 waterMark.png
Executing the combined command:
ffmpeg -y -i videoFile.mp4 -i waterMark.png -c:a copy -c:v libx264 -filter_complex "[0:v]pad=$length:$length=216:x=-1:y=-1:color=#195766[t];[t][1:v]overlay=10:main_h-overlay_h-10[v]" -map "[v]" -map 0:a resultFile.mp4
Result (first frame of the output of the test):

ffmpeg add logo and photo and subtitles

Hello i need add logo and photo and subtitles to a video.
I have this code
ffmpeg -t 00:00:08 -i "video.mp4" -i photo.jpg -i logo.png -filter_complex "overlay=2700:1850,subtitles=sub.ass:force_style='WrapStyle=0" -an -vcodec libx264 -shortest -r 25 -crf 17 -aspect 16/9 output.mp4
i don't know how to add other filter to scale 50% and center the photo
this is the code to add scaled photo to a video
ffmpeg -t 8 -i "video" -i "photo.jpg" -filter_complex "[1][0]scale2ref=w=oh*mdar:h=ih/2[logo][video];[video][logo]overlay=(W-w)/2:(H-h)/2:format=auto,format=yuv420p" -vcodec libx264 -shortest -r 25 -crf 17 -aspect 16/9 "output.mp4"
i need to combine both. Thanks
Combined command:
ffmpeg -t 8 -i video.mp4 -i photo.jpg -i logo.png -filter_complex "[1][0]scale2ref=w=oh*mdar:h=ih/2[logo][video];[video][logo]overlay=(W-w)/2:(H-h)/2:format=auto[bg];[bg][2]overlay,subtitles=sub.ass:force_style='WrapStyle=0,format=yuv420p" -c:v libx264 -shortest -r 25 -crf 17 -aspect 16/9 output.mp4

ffmpeg wmv to mp4 and synchronous add a logo image

The script I use to add a logo:
ffmpeg -i input.mp4 -framerate 30000/1001 -loop 1 -i test.png \
-filter_complex "[1:v] fade=out:st=30:d=1:alpha=1 [ov]; \
[0:v][ov] overlay=10:10 [v]" -map "[v]" -map 0:a \
-c:v libx264 -c:a copy -shortest output.mp4
The command I use to convert video. (With this command, synchronize your webm and mp4 and get the picture.)
ffmpeg -i input.wmv -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis \
outputwebm.webm -c:v libx264 -crf 35 outputmp4.mp4 \
-vf "thumbnail,scale=640:360" -frames:v 1 outputpng.png
I want to add the logo image as synchronous.
The command I tried:
ffmpeg -i input.wmv -c:v libvpx -crf 10 -b:v 1M \
-c:a libvorbis outputwebm.webm -c:v libx264 \
-crf 35 -framerate 30000/1001 -loop 1 -i test.png \
-filter_complex "[1:v] fade=out:st=30:d=1:alpha=1 [ov]; \
[0:v][ov] overlay=10:10 [v]" -map "[v]" -map 0:a \
-c:v libx264 -c:a copy -shortest outputmp4.mp4 \
-vf "thumbnail,scale=640:360" -frames:v 1 outputpng.png
Result:
Group all inputs at the front of the command and remove the encoding for the temp MP4 file.
ffmpeg -i input.wmv -framerate 30000/1001 -loop 1 -i test.png -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis outputwebm.webm -filter_complex "[1:v] fade=out:st=30:d=1:alpha=1 [ov]; [0:v][ov] overlay=10:10 [v]" -map "[v]" -map 0:a -c:v libx264 -c:a copy -shortest outputmp4.mp4 -vf "thumbnail,scale=640:360" -frames:v 1 outputpng.png
If your PNG has greater resolution than the WMV then you'll need to map the video for the webm and png outputs.

Cutting audio and adding overlay in single command FFMPEG

How to add overlay and cut audio from a particular time in any type of video?
Here is what I am trying
ffmpeg -ss 5 -t 30 -i Happier.mp4 -i Watermark.png-filter_complex "[0:v][1:v] overlay=0:0:enable='between(t,5,30)'" -preset ultrafast -pix_fmt yuv420p -c:a copy output.mp4
Use
ffmpeg -i Happier.mp4 -i Watermark.png \
-filter_complex "[0:v][1:v] overlay=0:0:enable='between(t,5,30)'[v]; \
[0]volume=0:enable='between(t,5,30)'[a]" \
-map "[v]" -map "[a]" -preset ultrafast -pix_fmt yuv420p output.mp4

FFMpeg - Combine multiple filter_complex and overlay functions

I am having trouble combining these 3 passes in ffmpeg into a single process.
Is this even possible?
Pass 1
ffmpeg -y -i C:\Users\MJ\Downloads\20151211_pmoney_pmpod.mp3 -loop 1 -i C:\Users\MJ\Documents\pm1080.png -filter_complex "[0:a]showwaves=s=1920x1080:mode=line,colorkey=0x000000:0.01:0.1,format=yuva420p[v];[1:v][v]overlay=0:270[outv]" -map "[outv]" -pix_fmt yuv420p -map 0:a -c:v libx264 -c:a copy -shortest C:\Users\MJ\Documents\20151211_pmoney_pmpod4.mp4
Pass 2
ffmpeg -i "C:\Users\MJ\Documents\20151211_pmoney_pmpod4.mp4" -vf drawtext="fontsize=50:fontcolor=white:fontfile=/Windows/Fonts/impact.ttf:text=Planet Money Podcast on NPR - A/B Split Testing:x=(w-text_w)/2:y=200" -acodec copy "C:\Users\MJ\Documents\20151211_pmoney_pmpod-overlay-text.mp4"
Pass 3
ffmpeg -i "C:\Users\MJ\Documents\20151211_pmoney_pmpod-overlay-text.mp4" -i C:\Users\MJ\Downloads\6.png -filter_complex "overlay=10:10" C:\Users\MJ\Documents\20151211_pmoney_pmpod-overlay-text1.mp4"
Thanks!
Join filters with a comma and filterchains with a semicolon:
ffmpeg -i audio.mp3 -i image1.png -i image2.png -filter_complex \
"[0:a]showwaves=s=1920x1080:mode=line[fg]; \
[1:v][fg]overlay=0:270,drawtext=fontsize=50:fontcolor=white:fontfile=/Windows/Fonts/impact.ttf:text='Planet Money Podcast on NPR - A/B Split Testing':x=(w-text_w)/2:y=200[bg]; \
[bg][2:v]overlay=10:10,format=yuv420p[outv]" \
-map "[outv]" -map 0:a -c:v libx264 -c:a copy -movflags +faststart -shortest out.mp4

Resources