ffmpeg add logo and photo and subtitles - ffmpeg

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

Related

Ffmpeg speed processing time

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

FFMPEG Video loop from images files

I am trying to make a video from a bundle of image files and then apply a an overlay on top of it.Another requirement is to make the video loop 3x. It is simply not working.
The first three paths are pointing toward the same image bundle. (A folder containing images like the following DSC0001_0013.jpg,DSC0002_0013.jpg,etc)
Observed symptoms:
The script runs infinitely.I produces a video file of 0 KB.I have to abort script using CTRL+C
This is my script.
ffmpeg
-start_number 1 -framerate 3/1
-i "C:\Users\xxx\AppData\Local\xxx\xxx\xxx\xxx\xxx\xxx\xxx\963d9d9b8e1\DSC%04d_0013.jpg"
-i "C:\Users\xxx\AppData\Local\xxx\xxx\projects\xxx\xxx\xxx\xxx\963d9d9b8e1\DSC%04d_0013.jpg"
-i "C:\Users\xxx\AppData\Local\xxx\xxx\projects\xxx\xxx\xxx\xxx\963d9d9b8e1\DSC%04d_0013.jpg"
-i "C:\Users\xxx\AppData\Local\xxx\xxx\projects\1237\1138\overlay.png"
-i "C:\Users\xxx\AppData\Local\xxx\xxx\projects\1237\1138\overlay.png"
-i "C:\Users\xxx\AppData\Local\xxx\xxx\projects\1237\1138\overlay.png"
-filter_complex " [0:v]scale=600x900[scaled1]; [1:v]scale=600x900[scaled2]; [2:v]scale=600x900[scaled3]; [scaled1][3:v]overlay[tmp1]; [scaled2][4:v]overlay[tmp2]; [scaled3][5:v]overlay[tmp3]; [tmp1][tmp2][tmp3]concat=n=3[scaled] "
-map [scaled] -r 10 -vcodec libx264 -pix_fmt yuv420p -crf 23 "C:\Users\xxx\Documents\Projets\2020\xxx\video test ffmpeg\test.mp4"
Use the -stream_loop option:
ffmpeg -stream_loop 3 -framerate 3/1 -i DSC%04d_0013.jpg -i overlay.png -filter_complex "[0]scale=600:900[bg];[bg][1]overlay=format=auto,format=yuv420p[v]" -map "[v]" -r 10 -c:v libx264 -crf 23 output.mp4
#Ilogan, This is our solution.
-start_number 1 -framerate 3/1
-i DSC%04d_0013.jpg
-loop 1 -i overlay.png"
-filter_complex "
[0:v]scale=600x900[scaled];
[scaled][1:v]overlay,trim=duration=3,loop=loop=2:size=9[tmp]
" -map [tmp] -r 10 -vcodec libx264 -pix_fmt yuv420p -crf 23
test.mp4

FFMPEG: Combine "Create video from images" + scale to x + add audio + overlay logo

I´m working on a webcam-project. It is for generating timelapse videos of sunset/sundown.
I´m using a raspberrypi to generate them with gphoto2 + DSLR.
At the end of the day the images should get to an video, with audio and an overlay logo.
And it should be scaled to 1920 pixel.
I got a nice solution an it worked.
Producing the timelapse video an scale it:
ffmpeg -y -framerate 25 -start_number 0000001 -i /var/www/html/webcam/2020-01-05_bilder/%7d.jpg -vf scale=1920:-1 -pix_fmt yuv420p /var/www/html/webcam/2020-01-05-tag-output-1920.mp4
Taking the output of (1) and add an overlay-logo, add audio
ffmpeg -y -i '/var/www/html/webcam/2020-01-05-tag-output-1920.mp4'
-i '/var/www/html/webcam-scripts/graphics/logo.png'
-i '/var/www/html/webcam-scripts/sounds/chill_time_5.mp3'
-shortest -filter_complex '[1][0]scale2ref=h=ow/mdar:w=iw/6[#A logo][liebfrauen]; [#A logo]format=argb,colorchannelmixer=aa=0.95[#B logo transparent]; [liebfrauen][#B logo transparent] overlay=(main_w-w)-(main_w*0.05):(main_h-h)-(main_h*0.01)'
-c:v libx264 -crf 18 -preset slow -pix_fmt yuv420p -c:a aac -strict -2
'/var/www/html/webcam/2020-01-05-tag-1920.mp4
I tried to combine both actions, but I get an error:
ffmpeg -y -framerate 25 -start_number 0000001 -i '/var/www/html/webcam/2020-01-05_bilder/%7d.jpg' -vf scale=1920:-1 -pix_fmt yuv420p -i '/var/www/html/webcam-scripts/graphics/logo.png' -i '/var/www/html/webcam-scripts/sounds/chill_time_5.mp3' -shortest -filter_complex '[1][0]scale2ref=h=ow/mdar:w=iw/6[#A logo][liebfrauen]; [#A logo]format=argb,colorchannelmixer=aa=0.95[#B logo transparent]; [liebfrauen][#B logo transparent] overlay=(main_w-w)-(main_w*0.05):(main_h-h)-(main_h*0.01)' -c:v libx264 -crf 18 -preset slow -pix_fmt yuv420p -c:a aac -strict -2 '/var/www/html/webcam/2020-01-05-tag-1920.mp4'
Error: Filtergraph 'scale=720:-1' was specified through the -vf/-af/-filter option for output stream 0:0, which is fed from a complex filtergraph.
-vf/-af/-filter and -filter_complex cannot be used together for the same stream.
Isn`t it possible to combine these inputs and scale it? Or ... Where is my misunderstanding?
Don't mix -vf and -filter_complex. Do all filtering in one filtergraph.
ffmpeg -y -framerate 25 -i '/var/www/html/webcam/2020-01-05_bilder/%7d.jpg' -i '/var/www/html/webcam-scripts/graphics/logo.png' -i '/var/www/html/webcam-scripts/sounds/chill_time_5.mp3' -filter_complex '[0]scale=1920:-2[v0];[1][v0]scale2ref=h=ow/mdar:w=iw/6[#A logo][liebfrauen]; [#A logo]format=argb,colorchannelmixer=aa=0.95[#B logo transparent]; [liebfrauen][#B logo transparent] overlay=(main_w-w)-(main_w*0.05):(main_h-h)-(main_h*0.01),format=yuv420p' -c:v libx264 -crf 18 -preset slow -c:a aac -shortest '/var/www/html/webcam/2020-01-05-tag-1920.mp4'
No need for -strict -2. It does nothing for modern ffmpeg.
I replaced -pix_fmt yuv420p with format=yuv420p so it is more organized.
-start_number 0000001 is not needed because 1 is the default.

FFMPEG Add watermark to MP4

I have this command to add watermark to an mp4
ffmpeg -i junai-blvaz.mp4 -i evercam-logo-white.png -filter_complex "[1]scale=iw/2:-1[wm];[0][wm]overlay=x=main_w-overlay_w-10:y=main_h-overlay_h-10" -codec:a copy output.mp4
But I am creating the video using
ffmpeg -r 6 -i /tmp/%d.jpg -c:v h264_nvenc -r 6 -preset slow -bufsize 1000k -pix_fmt yuv420p -y junai-blvaz.mp4
Is there any way to merge this command of adding watermark
-i evercam-logo-white.png -filter_complex '[1]scale=iw/2:-1[wm];[0][wm]overlay=x=main_w-overlay_w-10:y=main_h-overlay_h-10'
to the very first command through which mp4 video has been created?
Combine the two commands:
ffmpeg -y -framerate 6 -i /tmp/%d.jpg -i evercam-logo-white.png -filter_complex "[1]scale=iw/2:-1[wm];[0][wm]overlay=x=main_w-overlay_w-10:y=main_h-overlay_h-10,format=yuv420p" -c:v h264_nvenc -preset slow -bufsize 1000k junai-blvaz.mp4

Combine Two Commands (Get Video from Images)

I have 300 images and i wants to generate video from these images.
i am new to FFMPEG so now i am using two commands to generate video from images.
Command to generate video from images which also add Logo on video
ffmpeg -framerate 24 -i img_%d.jpg -i logo.png -filter_complex \
"[0:v][1:v] overlay=25:25:enable='between(t,0,20)'" \
-vcodec libx264 -crf 25 -pix_fmt yuv420p test_video.mp4
After using above command i am getting the video to add audio to this video i am using below command
ffmpeg -i test_video.mp4 -i inputfile.mp3 -c:v libx264 -c:a libvorbis -shortest final_video.mp4
which generates video and i am getting below message
MPEG-4 AAC decoder is required to play the file
Help to combine this both command. if possible can we add sound without any decoder required
Log for command 1 https://drive.google.com/file/d/1zS7gvrPy69VK_MkyE4127FpX2kEziJHq/view?usp=sharing
and Log command 2 https://drive.google.com/file/d/1rHqVGzj7f003aWP6eISiyUjsES8_EWuw/view?usp=sharing
Try next command:
ffmpeg -framerate 24 -i img_%d.jpg -i logo.png -i inputfile.mp3 -filter_complex \
"[0:v][1:v] overlay=25:25:enable='between(t,0,20)'" \
-vcodec libx264 -crf 25 -map 2:a -c:a copy -pix_fmt yuv420p -shortest test_video.mp4
-map 2:a is needed to skip image in case if there is cover image in track.
With -c:a copy track will not be re-encoded, so you will have mp3 inside of your video file.

Resources