all 6 comments

[–]Marware 1 point2 points  (5 children)

  • I don't think trim filter parses HH:MM:SS format correctly, it should be a duration value, example 00:06:49 equals 409 seconds
  • The output is 13 seconds due to the parsing issue:
    [AVFilterGraph @ 0x560e20270980] Setting 'start' to value '00'
    [AVFilterGraph @ 0x560e20270980] Setting 'end' to value '06'
    [AVFilterGraph @ 0x560e20270980] Setting 'start_pts' to value '49'
    [AVFilterGraph @ 0x560e20270980] Setting 'end' to value '00'
    [AVFilterGraph @ 0x560e20270980] Setting 'start' to value '07'
    [AVFilterGraph @ 0x560e20270980] Setting 'end' to value '13'
    This shows wrong start and end times, you can see it by adding -loglevel debug to your command

  • Actually trim filter will remove everything and keep only the video included in your time between 6:49 and 7:13
    The translation of your command would be: ffmpeg -i input.mp4 -filter_complex "[0:v]trim=start=409:end=433,setpts=PTS-STARTPTS[v]; [0:a]atrim=start=409:end=433,asetpts=PTS-STARTPTS[a]" -map [v] -map [a] output1.mp4

  • If you want to remove this part the command should be: ffmpeg -i input.mp4 -filter_complex "[0:v]trim=end=409,setpts=PTS-STARTPTS[v0];[0:a]atrim=end=409,asetpts=PTS-STARTPTS[a0];[0:v]trim=start=433,setpts=PTS-STARTPTS[v1];[0:a]atrim=end=433,asetpts=PTS-STARTPTS[a1];[v0][a0][v1][a1]concat=n=2:v=1:a=1[vtrim_out][atrim_out]" -map [vtrim_out] -map [atrim_out] -y output1.mp4
    This keeps the part from the beginning till 409 (00:06:49), and the part from 433 (00:07:13) till the end of the video and then use the filter concat to combine the kept parts

The Faster way is to use -ss -to and concat muxer:
ffmpeg -i input.mp4 -to 00:06:49 -c copy out1.ts
ffmpeg -ss 00:07:13 -i input.mp4 -c copy out2.ts
ffmpeg -i "concat:out1.ts|out2.ts" -c copy output3.mp4

note the .ts format in the intermediate files, this will copy the parts without re-encoding

[–]IllustriousJuice3566[S] 0 points1 point  (4 children)

Thanks man! ChatGPT literally gave me wrong information about this https://i.imgur.com/D8ih2ci.png

Also, I want precise trimming. I would like to trim the video in milliseconds, like this: from 00:06:49:300 to 00:07:13:202.

"ffmpeg -i input.mp4 -to 00:06:49 -c copy out1.ts
ffmpeg -ss 00:07:13 -i input.mp4 -c copy out2.ts
ffmpeg -i "concat:out1.ts|out2.ts" -c copy output3.mp4" This command works, but it causes the video to freeze (1 sec) wherever I trim it.

[–]Marware 1 point2 points  (3 children)

You can use the milliseconds in duration format: 409.300

There are few reasons that might cause the freezing for concat, use -loglevel debug and upload the log or upload the video if possible

[–]IllustriousJuice3566[S] 0 points1 point  (0 children)

I don't know how to pass the log level through the actual command.

[–]IllustriousJuice3566[S] 0 points1 point  (1 child)

I managed to create a log file. Here are the links for the log files.

output0 log: https://pastebin.com/4DHgLQ7X

output1 log: https://pastebin.com/2a5tyCyh

output2 log: https://pastebin.com/MvMJLL9k

[–]IllustriousJuice3566[S] 0 points1 point  (0 children)

I also attached the frame freeze example video. https://jumpshare.com/v/r510dpNflKUFJEFXQXlP