I have a video file of 30 minutes, but I want to extract a video from 00:09:23 to 00:25:33.
I can define the startposition with -ss
, but I couldn't find one for the end position. Any help please?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityMake sure you download a recent version of ffmpeg
, and don't use the one that comes with your distribution (e.g. Ubuntu). Packaged versions from various distributions are often outdated and do not behave as expected.
Or compile it yourself. Under macOS, you can use Homebrew and brew install ffmpeg
.
Use this to cut video from [start]
for [duration]
:
ffmpeg -ss [start] -i in.mp4 -t [duration] -map 0 -c copy out.mp4
Use this to cut video from [start]
to [end]
:
ffmpeg -copyts -ss [start] -i in.mp4 -to [end] -map 0 -c copy out.mp4
The options mean the following:
-ss
specifies the start time, e.g. 00:01:23.000
or 83
(in seconds)-t
specifies the duration of the clip. The format of the time is the same.-t
, you can also use -to
, which specifies the end time.You have to understand that normally, -ss
resets the timestamps of the input video after the cut point to 0, so by default it does not matter if you use -t
or -to
. If you want -ss
to not reset the timestamp to 0, the -copyts
option can be used. This makes -to
behave more intuitively.
For example:
ffmpeg -ss 5 -i in.mp4 -t 30 -map 0 -c copy out.mp4
This seeks forward in the input by 5 seconds and generates a 30 second long output file. In other words, you get the input video's part from 5–35 seconds.
Or:
ffmpeg -ss 5 -i in.mp4 -to 30 -map 0 -c copy out.mp4
This achieves the same thing as above, since the timestamps get reset to 0 after seeking 5 seconds in the input. The output will still be 30 seconds long.
If we instead use -copyts
, and we want the part from 5–35 seconds, we should use:
ffmpeg -copyts -ss 5 -i in.mp4 -to 35 -map 0 -c copy out.mp4
Finally, we've used the -c copy
option. -c copy
copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.
For more info on seeking, see https://trac.ffmpeg.org/wiki/Seeking
Sometimes, using -c copy
leads to output files that some players cannot process (they'll show a black frame or have audio-video sync errors).
If you leave out the -c copy
option, ffmpeg
will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the x264 Encoding Guide and the AAC Encoding Guide, respectively.
For example:
ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -crf 23 -c:a aac -b:a 192k out.mp4
You can change the CRF and audio bitrate parameters to vary the output quality. Lower CRF means better quality, and vice-versa. Sane values are between 18 and 28.
-to
does not always "start from" -ss
even without -copyts
, @Maggyero I use to move the -to
option to configure the input instead of the output so it is just another solution. ffmpeg -ss [start] -to [stop] -i in.mp4 -c copy out.mp4
Like this my stop time is correct despite the start time. I wonder if it is also the reason why @lustig moved -ss
to the output while they did not know why. The answer does not even mention -copyts
! It should, as it is the simplest solution here ! I prefer reordering the arguments, but i guess it is not simpler.
Aug 23, 2020 at 8:54
I think you can use the following command now.
ffmpeg -i inputFile -vcodec copy -acodec copy -ss 00:09:23 -to 00:25:33 outputFile
Have a look also ffmpeg Doc, or this wiki page.
ffmpeg -i inputFile -c copy -ss 00:09:23 -to 00:25:33 outputFile
simpler version
ffmpeg -ss 00:01:00 -i video.mp4 -to 00:02:00 -c copy -copyts cut.mp4
version (with -copyts
), otherwise it cut incorrectly (with black screen in the beginning). Thanks for the 2nd link though.
Jan 12, 2018 at 15:51
This is odd that no-one suggested the trim
filter.
Drop everything except the second minute of input:
ffmpeg -i INPUT -vf trim=60:120
Keep only the first second:
ffmpeg -i INPUT -vf trim=duration=1
Drop everything except from second 13 to second 58:
ffmpeg -i INPUT -vf trim=13:58 OUTPUT
trim
and atrim
. I usually use these when filtering, but users should note that filtering requires re-encoding.
You can use these two methods which work for Windows and Linux.
There are two ways how to split video files by ffmpeg. The first one is good in itself, more than that - it is faster, but sometimes creates output files with certain flaws. So for those cases there is the second way of splitting video files: it is considerably slower, the output files are bigger, but it seems they are always of the same quality level as input files used.
Way 1:
ffmpeg -ss <start> -i in1.avi -t <duration> -c copy out1.avi
Way 2:
ffmpeg -ss <start> -i in1.avi -t <duration> out1.avi
<start>
– the beginning of the part of a video ffmpeg is to cut out. Format:00:00:00.0000
, meaning hours:minutes:seconds:milliseconds.
<duration>
– the duration of the part of a video ffmpeg is to cut out. Same format as above.Examples:
ffmpeg -ss 01:19:00 -i in1.avi -t 00:05:00 -c copy out1.avi ffmpeg -ss 01:19:00 -i in1.avi -t 00:05:00 out1.avi
ffmpeg cuts out a part of the video file starting from 1 hour 19 minutes 0 seconds. The duration of the video sequence cut out is 5 minutes 0 seconds.
-sameq
does not mean "same quality" and has been removed from ffmpeg. Use -codec copy
instead. Also, don't forget about the -to
option.
I use the following syntax to cut video with ffmpef:
ffmpeg -sameq -ss [start_seconds] -t [duration_seconds] -i [input_file] [outputfile]
-t is used to set the duration in seconds - you can't specify the end time but this should work for you.
-sameq
does not mean "same quality" at all.
You can use this
ffmpeg -sameq -ss clip_start -t duration -i original.ogg clip.ogg
Here you have to give duration of video. ie. 00:25:33-00:09:23