Combine two ffmpeg commands (segment and still photo) - ffmpeg

is it possible to combine this command
ffmpeg -i video.mp4 -map 0:s:0? -c copy -movflags empty_moov+default_base_moof+frag_keyframe -f segment output%03d.mp4
with a command that can take a still from the first segment
ffmpeg -ss 00:00:00.00 -i output001.mp4 -vframes 1 -q:v 2 still.jpg"

Append the second command to the first:
ffmpeg -i video.mp4 -map 0:s:0? -c copy -movflags empty_moov+default_base_moof+frag_keyframe -f segment output%03d.mp4 -frames:v 1 -q:v 2 still.jpg

Related

ffmpeg - Sync Audio with image position (Audio Slideshow)

How can i start the audio Files at the same position as the pictures? (This is for a Image slideShow with changing Audio)
ffmpeg -loop 1 -t 19 -i 1.jpg -loop 1 -t 19 -i 2.jpg -i 1.mp3 -i 2.mp3
-filter_complex "
[0:a]adelay=19s:all=1[1a];
[1:a]adelay=24s:all=1[2a];
[0:v]scale=1280:720,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1[0p];
[1:v]scale=1280:720,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1[1p];
[0p][1p]xfade=transition=fade:duration=1:offset=19[1x];
-map [1x] -c:v libx264 -c:a copy -t 39 out.mp4
ok i found a solution to position audio files by seconds with Images.
just use this structure
and Paramter "adelay" for an audio offset
ffmpeg -loop 1 -t 10 -i "1.jpg" -loop 1 -t 10
-i "2.jpg" -t 5 -ss 0 -i "audio1.mp3"
-t 10 -ss 10 -i "audio2.mp3"
-filter_complex "[2]adelay=1000:all=1[a1];
[3]adelay=2000:all=1[a2];
[0:v]scale=1280:720,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1[0p];
[1:v]scale=1280:720,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1[1p];
[0p][1p]xfade=transition=fade:duration=1:offset=5.485[1x];
[a1][a2]amix=inputs=2[aout]" -map [1x] -map [aout] _out.mp4 -y 2>&1

ffmpeg, apply fade only to video input using filter_complex while concating

ffmpeg -i foo.mp4 -filter_complex "fade=d=0.5, reverse, fade=d=0.5, reverse" output.mp4
can be used to fade in and out foo.mp4 video. (we do not care about audio). According to https://video.stackexchange.com/questions/19867/how-to-fade-in-out-a-video-audio-clip-with-unknown-duration
It's good but only works in the simple situation of 1 input video, and 1 output. Now, how can I apply the fade in and out effect in the following more complex situation? I'm trying to concat a.jpg (a picture) with bar.mp4. I want only the bar.mp4 portion to fade in and out.
ffmpeg -loop 1 -t 2 -framerate 1 -i a.jpg -f lavfi -t 2 -i anullsrc -r 24 -i bar.mp4 -filter_complex "[0][1][2:v][2:a] concat=n=2:v=1:a=1 [vpre][a];[vpre]fps=24[v]" -map "[v]" -map "[a]" out.mp4 -y
Of course, I could first create a temporary temp.mp4 from bar.mp4 by running the first command, then input temp.mp4 in my second command. This involves an extra step and extra encoding. Could anyone help fix the commands or suggest something even better?
Use
ffmpeg -loop 1 -t 2 -framerate 24 -i a.jpg -f lavfi -t 2 -i anullsrc -r 24 -i bar.mp4 -filter_complex "[2:v]fade=d=0.5, reverse, fade=d=0.5, reverse[v2];[0][1][v2][2:a] concat=n=2:v=1:a=1 [v][a]" -map "[v]" -map "[a]" out.mp4 -y

ffmpeg concat video and image issue

I have a video it's 190 seconds long.
I want to show a part of the video with audio and a watermark (from 28th second to 154th second)
and then the video fades out, and then show an image for 5 seconds at the end of the video.
everything was working fine until i added concat and endpic.jpg
Here is the script it wrote but it's not working. It's really driving me crazy.
ffmpeg -y -ss 28 -i input.mp4 -loop 1 -i watermark.png -loop 1 -t 5 -i endpic.jpg -f lavfi -t 5 -i anullsrc -filter_complex "[1]fade=in:st=3:d=1:alpha=1,fade=out:st=20:d=1:alpha=1[w]; [0][w]overlay=main_w-overlay_w-10:main_h-overlay_h-10[sonh];[sonh]fade=out:st=154:d=1[sonhh];[sonhh:v][sonhh:a][2:v][3:a]concat=n=2:v=1:a=1[v][a]" -t 155 -map "[v]" -map "[a]" output.mp4
Use
ffmpeg -y -ss 28 -to 154 -i input.mp4 -loop 1 -t 22 -i watermark.png -loop 1 -t 5 -i endpic.jpg -f lavfi -t 5 -i anullsrc -filter_complex "[1]fade=in:st=3:d=1:alpha=1,fade=out:st=20:d=1:alpha=1[w]; [0][w]overlay=main_w-overlay_w-10:main_h-overlay_h-10,fade=out:st=154:d=1[sonhh];[sonhh][0:a][2:v][3:a]concat=n=2:v=1:a=1[v][a]" -t 155 -map "[v]" -map "[a]" output.mp4
If you don't limit the input duration, ffmpeg will feed till 190s of the input, and due to -t 155, the output will never get to the end of the input and the start of endpic.
Linklabels assigned within a filtergraph don't represent the original inputs so [sonhh:v][sonhh:a] isn't valid. The input audio remains [0:a].
Input -to was added a few months ago, so ensure you're using a recent build of ffmpeg.

FFmpeg - combine 2 commands

I have 2 commands as listed below.
Add intro image to a video
ffmpeg -y -loop 1 -framerate 10 -t 3 -i intro.png -i video.mp4 -filter_complex "[0:0] [1:0] concat=n=2:v=1:a=0" -c:v libx264 -crf 23 videoWithIntro.mp4
Add watermark to video
ffmpeg -y -i video.mp4 -i watermark_color.png -filter_complex "overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2" videoWithWatermark.mp4
I was wondering is it possible to combine these into the 1 command?
Use
ffmpeg -y -loop 1 -framerate 10 -t 3 -i intro.png -i video.mp4 -i watermark_color.png -filter_complex "[0][1]concat=n=2:v=1:a=0[v];[v][2]overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2" videoWithWatermark.mp4
I assume your videos don't have audio, else use
ffmpeg -y -loop 1 -framerate 10 -t 3 -i intro.png -i video.mp4 -i watermark_color.png -f lavfi -t 3 -i anullsrc -filter_complex "[0][1]concat=n=2:v=1:a=0[v];[v][2]overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2;[3][1]concat=n=2:v=0:a=1" videoWithWatermark.mp4
The final command to get this working correctly is as follows
ffmpeg -y -loop 1 -framerate 25 -t 3 -i 1920x1080_intro.png -i DSC_0002.MOV -i watermark_color.png -report -an -filter_complex "[1][2]overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2,setsar=1[v];[0]setsar=1[pre];[pre][v]concat=n=2:v=1:a=0" ../testing/videoWithIntroAndWatermark.mp4

FFmpeg filter_complex merging two commands

I'm having trouble merging these two commands, if anyone can help me merge the top ones transposing and watermarking to the second one I would really appreciate it. I've tried a few things such as:
ffmpeg -i .\test1.flv -i .\test2.flv -loop 1 -i .\watermark.png -filter_complex "[0]transpose=1[a];[1]transpose=1[b];[a][b]hstack[c];[c][2]overlay=W-w-5:H-h-5:shortest=1; [0:v]setpts=PTS-STARTPTS, pad=iw*2:ih[bg]; [1:v]setpts=PTS-STARTPTS[fg]; amerge,pan=stereo:c0<c0+c2:c1<c1+c3" -c:v libx264 -f mp4 -threads 24 -y matt.mp4
ffmpeg -i .\test1.flv -i .\test2.flv -loop 1 -i .\watermark.png -filter_complex "[0:v]setpts=PTS-STARTPTS, pad=iw*2:ih[bg]; [1:v]setpts=PTS-STARTPTS[fg]; amerge,pan=stereo:c0<c0+c2:c1<c1+c3;[0]transpose=1[a];[1]transpose=1[b];[a][b]hstack[c];[c][2]overlay=W-w-5:H-h-5:shortest=1" -c:v libx264 -f mp4 -threads 24 -y matt.mp4
Thanks everyone!
If I understand your intent right, this is what you want
ffmpeg -i .\test1.flv -i .\test2.flv -loop 1 -i .\watermark.png -filter_complex
"[0]setpts=PTS-STARTPTS,transpose=1[a];
[1]setpts=PTS-STARTPTS,transpose=1[b];
[a][b]hstack[c];
[c][2]overlay=W-w-5:H-h-5:shortest=1[v];
[0]asetpts=PTS-STARTPTS[x];[1]asetpts=PTS-STARTPTS[y];
[x][y]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[a]"
-map "[v]" -map "[a]" -c:v libx264 -f mp4 -threads 24 -y matt.mp4

Resources