I am trying to remove a segment (00:26:00 - 00:32:30) from a video file input.mp4
.
Since there is no way to do that directly using ffmpeg (as far as I know), I am instead cutting the segments which I want in the output and then concatenating them.
After searching a bit, I've found that there are 2 ways to do this:
- Using
trim
as mentioned in this answer - Using
seek
as mentioned in this answer.
Unfortunately, both these methods are failing for me.
I am going to explain the steps I performed in both the methods:
1. Using trim
:
EDIT: This method works now; skip to the second method instead.
Command used:
ffmpeg -i input.mp4 -filter_complex \"[0:v]trim=duration=00:26:00[a]; \[0:v]trim=start=00:32:30,setpts=PTS-STARTPTS[b]; \[a][b]concat[c]" -map [c] out.mp4
Command output: Link
The output file is less than 1 minutes long and is of just 6.8 MB, whereas the input file was 900 MB.
2. Using seek
Command used:
# Cut first wanted segmentffmpeg -ss 00:00:00 -i input.mp4 -t 00:26:00 -c copy -avoid_negative_ts 1 first.mp4# Cut second wanted segmentffmpeg -ss 00:32:30 -i input.mp4 -c copy -avoid_negative_ts 1 second.mp4# Combine all the wanted segmentsffmpeg -f concat -i input.txt -c copy output.mp4
where input.txt
contains:
file first.mp4file second.mp4
Command output: Link (The error is mentioned on line 90: input.txt: Invalid argument
)
The output file I get in this case is only about 500 MB (input file being 900 MB), and contains first video + first few minutes of the second video.
My system details:
Ubuntu 14.04
ffmpeg version: Link
EDIT:
Method 1 using trim
is now working, thanks to @Mulvya's comment regarding writing seconds as the unit of time instead of the HH:MM:SS notation as it is broken.
New command:
ffmpeg -i input.mp4 -filter_complex \"[0:v]trim=duration=1500[av]; \ [0:a]atrim=duration=1500[aa];\ [0:v]trim=start=1980,setpts=PTS-STARTPTS[bv]; \ [0:a]atrim=start=1980,asetpts=PTS-STARTPTS[ba];\ [av][bv]concat[outv]; [aa][ba]concat=v=0:a=1[outa]" \ -map [outv] -map [outa] out.mp4
But, I still want to know what's wrong with the second method.