3

I'm splitting and merging a single video clip using this ffmpeg command:

-ss 0 -t 1 -i C:\source.mp4 
-ss 3 -t 1 -i C:\source.mp4 
-ss 6 -t 1 -i C:\source.mp4 
-ss 9 -t 1 -i C:\source.mp4 
-filter_complex "[0:v][1:v][2:v][3:v]concat=n=4[outv];
[0:a][1:a][2:a][3:a]concat=n=4:=v=0:a=1[outa]" -map [outv] -map [outa]
-vcodec h264 -acodec aac -pix_fmt yuv420p -strict -2 C:\output.mp4

But if source file doesn't have audio track, this command fails. if I remove ;[0:a][1:a][2:a][3:a]concat=n=4:=v=0:a=1[outa] part it fixes the problem but I need to analyse file before using the command.

is there any parameter that will automaticly remove this part or ignores audio track if source doesnt have any audio track at all.

4

Use the concat demuxer instead:

Create a text file of the following format

file 'C:\source.mp4'
inpoint 0
duration 1
file 'C:\source.mp4'
inpoint 3
duration 1
file 'C:\source.mp4'
inpoint 6
duration 1
file 'C:\source.mp4'
inpoint 9
duration 1

Then run

ffmpeg -f concat -i file.txt -map 0:v -map 0:a? -vcodec h264 -acodec aac -pix_fmt yuv420p -strict -2 -fflags +genpts C:\output.mp4
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.