FFMpeg - Freeze First Frame for X seconds - ffmpeg

I need to pause/freeze the first frame of the video for 2 seconds before proceeding to the scroll effect. Here's what I have:
ffmpeg -y -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -loop 1 -i "temp.jpg" -i "floating.png" -filter_complex "[1:v]fps=fps=30,crop=1280:720:0:'t*(ih-oh)/120',overlay,scale=1280x720,drawtext=fontfile='font.ttf':text='text here':x=20:y=675:fontsize=60:fontcolor=white:shadowcolor=black:shadowx=2:shadowy=2,drawtext=fontfile='font.ttf':text='more text':x=w-tw-20:y=670:fontsize=70:fontcolor=white:shadowcolor=black:shadowx=2:shadowy=2[out]" -t 10 -map "[out]" -map "0:a" -shortest -c:v h264_qsv -c:a aac -ac 2 -ar 44100 -vb 30M -r 30 "video.mp4"
Any ideas?

I figured it out using:
loop=60:1:0,setpts=N/FRAME_RATE/TB

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):

How to add multiple audio to a video at specific time for specific duration

I have a video.mp4 file of 20 seconds without audio stream, and I have 2 audio files audio1.mp3 and audio2.mp3. What I want is audio1 should start playe at 3 seconds for 5 seconds, and audio 2 should start play at 10 seconds for 6 seconds.
ffmpeg -y -i video1.mp4 -i audio1.mp3 -i audio2.mp3 -filter_complex "[1]adelay=3000|3000[aud1];[2]adelay=10000|10000[aud2];[aud1][aud2]amix=2,apad[a];
[0][a]amix=duration=first[a]" -map 0:v -map "[a]" -c:v copy -ac 2 output.mp4
what I'm trying to achieve is the final output will be a 20 seconds video where audio1 will start palying at 3 seconds to 8 seconds and audio2 will start from 10 seconds to 16 seconds.
mix with silence (aevalsrc=0):
ffmpeg -hide_banner \
-i video1.mp4 \
-i audio1.mp3 \
-i audio2.mp3 \
-filter_complex "
aevalsrc=0:d=20[bga];
[1:a]adelay=3000|3000,aresample=async=1:first_pts=0[1a];
[2:a]adelay=10000|10000,aresample=async=1:first_pts=0[2a];
[bga][1a][2a]amix=3[a]
" -map 0:v -map [a] -c:v copy -c:a aac -q:a 4 -y /tmp/output.mp4
Use atrim to limit the audio duration for the MP3s and the final output.
ffmpeg -y -i video1.mp4 -i audio1.mp3 -i audio2.mp3 -filter_complex "[1]atrim=0:5,adelay=3000|3000[aud1];[2]atrim=0:6,adelay=10000|10000[aud2];[aud1][aud2]amix=2,apad,atrim=0:20[a]" -map 0:v -map "[a]" -c:v copy -ac 2 output.mp4

Combining 2 FFMPEG Commands

I'm trying to combine 2 ffmpeg commands, one which creates the video, and another which adds a simple fade to the beginning of the created video. Here's what I have:
ffmpeg -y -stream_loop -1 -i "video.mp4" -stream_loop -1 -i "music.mp3" -i "audio.mp3" -filter_complex "[1:a]volume=0.1[a1];[2:a]adelay=5000|5000,apad=pad_dur=10[a2];[a1][a2]amerge=inputs=2,afade=in:st=0:d=5[audio]" -map "0:v" -map "[audio]" -c:v libx264 -c:a aac -ac 2 -ar 22050 -preset veryfast -shortest "output.mp4"
ffmpeg -y -i "output.mp4" -filter_complex "[0:v]fade=in:0:d=5" -c:a copy -preset veryfast -movflags faststart -fflags genpts "done.mp4"
The two commands work perfectly fine, however the second one takes about the same amount of time to process as the first, and I feel it should be relatively easy to do the fade-in during the first encode. For my skillset atleast, I was wrong. Please could someone with more experience lend a helping hand?
Thanks.
Add a simple filterchain for the video.
ffmpeg -y -stream_loop -1 -i "video.mp4" -stream_loop -1 -i "music.mp3" -i "audio.mp3" -filter_complex "[1:a]volume=0.1[a1];[2:a]adelay=5000|5000,apad=pad_dur=10[a2];[a1][a2]amerge=inputs=2,afade=in:st=0:d=5[audio]" -vf "fade=in:0:d=5" -map "0:v" -map "[audio]" -c:v libx264 -c:a aac -ac 2 -ar 22050 -preset veryfast -shortest -movflags faststart "done.mp4"

Merge video and audio while delaying audio by x seconds

This works for merging audio and video
ffmpeg -i video.mp4 -i audio.ogg -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map 0:v -map "[a]" -c:v copy -c:a libvorbis -ac 2 -shortest out.mp4 -y -nostdin
I can't figure out how to delay the audio so it starts x seconds into the video. I have tried -itsoffset but it doesn't work.
Use
ffmpeg -i video.mp4 -i audio.ogg -filter_complex "[1:a]adelay=1000|1000[a1];[0:a][a1]amerge=inputs=2[a]" -map 0:v -map "[a]" -c:v copy -c:a libvorbis -ac 2 -shortest out.mp4 -y -nostdin
The adelay adds 1000 ms of silence to both channels of the OGG.
This is more of a workaround, but you could concatenate 1 second of silence with your ogg first:
https://trac.ffmpeg.org/wiki/Concatenate

FFMPEG : Cut Video AND Include Ending Video/Image

I am using this command line to add a five second image on end of video:
ffmpeg -i "f:\output\input.mov" -loop 1 -t 5 -i "f:\output\taff.jpg" -f lavfi -t 5 -i anullsrc -filter_complex "[0:v] [0:a] [1:v] [2:a] concat=n=2:v=1:a=1 [v] [a]" -c:v libx264 -c:a aac -strict -2 -map "[v]" -map "[a]" f:\output\output.mp4
It works great, but sometimes I want to cut the video and then add the five seconds. So, make a 120 second video 110 seconds, then add the 5 second ending.
Possibly in one command line? I've tried to break it into two, by starting with cutting the video, but then I get an "Unable to parse option value "-1" pixel format" error if I try to re-encode the video I cut with ffmpeg using this:
ffmpeg -i f:\output\input.mov -vcodec copy -acodec copy -ss 00:00:00.000 -t 00:01:50.000 f:\output\output.mov
That output video will then give an error if I try to run the first command line against it.
All feedback appreciated on shortening a video, and then adding ending.
Cheers!
Ryan
Use
ffmpeg -t 110 -i "f:\output\input.mov"
-loop 1 -t 5 -i "f:\output\taff.jpg"
-f lavfi -t 5 -i anullsrc
-filter_complex "[0:v][0:a][1:v][2:a]concat=n=2:v=1:a=1[v][a]"
-c:v libx264 -c:a aac -strict -2 -map "[v]" -map "[a]" f:\output\output.mp4
With scale2ref, it should be
ffmpeg -t 110 -i "f:\output\input.mov"
-loop 1 -t 5 -i "f:\output\taff.jpg"
-f lavfi -t 5 -i anullsrc
-filter_complex "[1][0]scale2ref[2nd][ref];[ref][0:a][2nd][2:a]concat=n=2:v=1:a=1[v][a]"
-c:v libx264 -c:a aac -strict -2 -map "[v]" -map "[a]" f:\output\output.mp4
If the image has a different aspect ratio, use
ffmpeg -t 110 -i "f:\output\input.mov"
-loop 1 -t 5 -i "f:\output\taff.jpg"
-f lavfi -t 5 -i anullsrc
-filter_complex "[0]split[base][full];[base]trim=0:5,drawbox=t=fill[base];[1][base]scale2ref='if(lt(mdar,dar),oh*mdar/sar,iw)':'if(lt(mdar,dar),ih,ow*sar/mdar)'[2nd][base];[base][2nd]overlay='(W-w)/2':'(H-h)/2'[padded];[full][0:a][padded][2:a]concat=n=2:v=1:a=1[v][a]"
-c:v libx264 -c:a aac -strict -2 -map "[v]" -map "[a]" f:\output\output.mp4
This last command requires ffmpeg version >= 3.4

Resources