Let’s say you wish to cut out some part of a video file. As an example we will use this file. The shortest minimal working code example for this task with FFmpeg can look as follows:
ffmpeg -i file_example_MP4_1920_18MG.mp4 -filter_complex "[0:v]trim=5.123:7.123,setpts=PTS-STARTPTS[v0]; [0:a]atrim=5.123:7.123,asetpts=PTS-STARTPTS[a0]; [0:v]trim=10.123:12.123,setpts=PTS-STARTPTS[v1]; [0:a]atrim=10.123:12.123,asetpts=PTS-STARTPTS[a1]; [v0][a0][v1][a1]concat=n=2:v=1:a=1[v][a]" -map "[v]" -c:v libx265 -crf 20 -preset veryslow -pix_fmt yuv420p10le -map "[a]" -c:a libopus result.mkv
Let’s say we use FFmpeg on Windows with CMD. Then we can break this huge command with ^, so we have
ffmpeg -i file_example_MP4_1920_18MG.mp4^
-filter_complex "[0:v]trim=5.123:7.123,setpts=PTS-STARTPTS[v0]; [0:a]atrim=5.123:7.123,asetpts=PTS-STARTPTS[a0]; [0:v]trim=10.123:12.123,setpts=PTS-STARTPTS[v1]; [0:a]atrim=10.123:12.123,asetpts=PTS-STARTPTS[a1]; [v0][a0][v1][a1]concat=n=2:v=1:a=1[v][a]"^
-map "[v]"^
-c:v libx265^
-crf 20^
-preset veryslow^
-pix_fmt yuv420p10le^
-map "[a]"^
-c:a libopus^
result.mkv
Please note the blank space before every line after ffmpeg -i testfile.mp4^. Please also note the ^ after every line (except for the last line).
The above code construction is more readable. But we have still have this monster part:
-filter_complex "[0:v]trim=5.123:7.123,setpts=PTS-STARTPTS[v0]; [0:a]atrim=5.123:7.123,asetpts=PTS-STARTPTS[a0]; [0:v]trim=10.123:12.123,setpts=PTS-STARTPTS[v1]; [0:a]atrim=10.123:12.123,asetpts=PTS-STARTPTS[a1]; [v0][a0][v1][a1]concat=n=2:v=1:a=1[v][a]"
I was not able to break this long part because of the "". It looks like the "" protects the the code sequence in between. Maybe I’am wrong?
Now comes the question: can one break the -filter_complex statement. If yes, how can one do it on Windows with CMD? One readable form could be a break after every ;, for example:
-filter_complex^
"[0:v]trim=5.123:7.123,setpts=PTS-STARTPTS[v0];^
[0:a]atrim=5.123:7.123,asetpts=PTS-STARTPTS[a0];^
[0:v]trim=10.123:12.123,setpts=PTS-STARTPTS[v1];^
[0:a]atrim=10.123:12.123,asetpts=PTS-STARTPTS[a1];^
[v0][a0][v1][a1]concat=n=2:v=1:a=1[v][a]"^
Please note the blank space before every line after -filter_complex^!