0

I'm trying to split & combine multiple portions of the same video file.

Since there are multiple portions that I want to combine, I want to use filtercomplex to do this.

Also, since some of the portions are quite small in duration, I want to use precise timestamps (setpts=PTS-STARTPTS)

The "script.txt" file contains the code below.

[0:v]trim=0.823625:5.88717,setpts=PTS-STARTPTS[v0];
[0:a]atrim=0.823625:5.88717,asetpts=PTS-STARTPTS[a0];
[0:v]trim=6.87858:10.2093,setpts=PTS-STARTPTS[v1];
[0:a]atrim=6.87858:10.2093,asetpts=PTS-STARTPTS[a1];
[0:v]trim=10.5683:11.5989,setpts=PTS-STARTPTS[v2];
[0:a]atrim=10.5683:11.5989,asetpts=PTS-STARTPTS[a2];
[0:v]trim=11.9066:13.2301,setpts=PTS-STARTPTS[v3];
[0:a]atrim=11.9066:13.2301,asetpts=PTS-STARTPTS[a3];
[0:v]trim=14.2123:14.903,setpts=PTS-STARTPTS[v4];
[0:a]atrim=14.2123:14.903,asetpts=PTS-STARTPTS[a4];
[0:v]trim=15.2467:16.5819,setpts=PTS-STARTPTS[v5];
[0:a]atrim=15.2467:16.5819,asetpts=PTS-STARTPTS[a5];
[0:v]trim=17.1012:20.1223,setpts=PTS-STARTPTS[v6];
[0:a]atrim=17.1012:20.1223,asetpts=PTS-STARTPTS[a6];
[0:v]trim=20.9504:22.5714,setpts=PTS-STARTPTS[v7];
[0:a]atrim=20.9504:22.5714,asetpts=PTS-STARTPTS[a7];
[0:v]trim=23.4482:24.8745,setpts=PTS-STARTPTS[v8];
[0:a]atrim=23.4482:24.8745,asetpts=PTS-STARTPTS[a8];
[0:v]trim=25.5697:26.8718,setpts=PTS-STARTPTS[v9];
[0:a]atrim=25.5697:26.8718,asetpts=PTS-STARTPTS[a9];
[0:v]trim=27.5758:27.9942,setpts=PTS-STARTPTS[v10];
[0:a]atrim=27.5758:27.9942,asetpts=PTS-STARTPTS[a10];
[0:v]trim=28.5431:30,setpts=PTS-STARTPTS[v11];
[0:a]atrim=28.5431:30,asetpts=PTS-STARTPTS[a11];
[v0][a0][v1][a1][v2][a2][v3][a3][v4][a4][v5][a5][v6][a6][v7][a7][v8][a8][v9][a9][v10][a10][v11][a11]
concat=n=12:v=1:a=1[outv][outa]

The command that I am using to run ffmpeg with this script file is as below

ffmpeg -i "input.mp4" -c:v libx265 -filter_complex_script "script.txt" -map [outv] -map [outa] "output.mp4"

But after running this command, the output video file is only ~5 seconds long (the very first portion of the input video).

As we can see from the first line of the "script.txt", the start timestamp is ~0.8 and the end timestamp is ~5.8 giving a duration of ~5s for the first piece of the output video.

So, ffmpeg is not joining any other parts of the input video after the first part. I am unable to understand why so.

I am facing this problem since the past couple of months after I updated ffmpeg. The same syntax of script file and command line used to work fine before that. Did any changes in the update alter the syntax that ffmpeg expects for this task?

Any help is much appreciated.

3
  • Hey, I tried to edit your answer on a tablet to improve code formatting. I don't know why but it messed up the whole line. I can't see history and now I am not sure what your output was. Was it "output.txt? Probably not.
    – Celdor
    Feb 11 at 12:58
  • Everything seems to work on my end. Just copied the command line assuming output is output.mp4 and have a 22 sec. long video. The question is how did you install FFMpeg. Are you using any non-standard version? This could be important because I used to have a similar issue. There are two version for Windows gyan.dev and BtbN. My script for splitting a video only worked using the second version BtbN. BTW your script works on BtbN.
    – Celdor
    Feb 11 at 13:07
  • The output was output.mp4. This is the result of running ffmpeg -version on my current installed ffmpeg. ffmpeg version N-113032-g76cd71bf0c-20231219 Copyright (c) 2000-2023 the FFmpeg developers built with gcc 13.2.0 (crosstool-NG 1.25.0.232_c175b21) I tried the above script file & command line with this version of ffmpeg & got the output video that's only ~5s long. Then I tried the same script & command line on the ffmpeg build from the BtbN link you suggested & got ~22s long output video. So now the problem has been identified & I can solve it now. Thanks
    – icyGuy
    Feb 11 at 19:30

1 Answer 1

0

Thanks to Celdor for identifying the problem.

The build of ffmpeg I had installed on my system was the culprit. Here's the output of running ffmpeg -version in the command line

ffmpeg version N-113032-g76cd71bf0c-20231219 Copyright (c) 2000-2023 the FFmpeg developers built with gcc 13.2.0 (crosstool-NG 1.25.0.232_c175b21)

The problem was solved after I installed the build of ffmpeg from BtbN

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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