[FFmpeg-user] Copying sections of an mp4 by time stamp

Jim DeLaHunt list+ffmpeg-user at jdlh.com
Thu Aug 27 07:53:08 EEST 2020


On 2020-08-26 19:50, James Sundquist wrote:
> I'm looking to copy sections of example.mp4
>
> Ideally this would be by time stamp.  Perhaps the time stamps are noted in
> a text file.
>
> Example as minutes:second
> 0:20 - 0:40 as a an mp4 with title "Exercise 1"
> 0:40 - 0:59 as an mp4 with title "Exercise 2"
> 0:20 - 0:59 as an mp4 with title "Primary Exercises"
>
Hello, James. Fortunately, this is pretty easy to do. Have you read the 
FFmpeg documentation[1] yet?

Look up the main command line options `-ss` and `-to` [2]. If your input 
file is `example.mp4`, then the commands will be like:

ffmpeg -i example.mp4 -ss 0:20 -to 0:40 exercise_1.mp4
ffmpeg -i example.mp4 -ss 0:40 -to 0:59 exercise_2.mp4
ffmpeg -i example.mp4 -ss 0:20 -to 0:59 primary_exercises.mp4

Note that `-i example.mp4` says that `example.mp4` is the input video. 
The extension `.mp4` tells FFmpeg that the file is MP4 format. `-ss 
0:20` means, "discard the input video until 0 minutes, 20 seconds in, 
then start copying to the output video from there. `-to 0:40` means stop 
copying to the output video when the input video is 0 minutes, 40 
seconds in.  There is documentation on this time duration syntax[3].

I do not know of a convenient way to do all these cuts in one invocation 
of FFmpeg. There may be a way I don't know about. When I had to solve a 
similar problem, I invoked FFmpeg once for each cut.  I suggest you use 
a spreadsheet to generate this command invocation from your list of 
start time durations, end time durations, and output file names. Then 
paste the command invocations from the spreadsheet into the command 
line. The command line will run them one after the other.

When you say "time stamps", I assume you mean the elapsed time from the 
start of the input video to your desired moment in the video. The 
documentation calls them "time durations", and means something else by 
"time stamps".

[1] http://ffmpeg.org/documentation.html
[2] http://ffmpeg.org/ffmpeg-all.html#Main-options
[3] http://ffmpeg.org/ffmpeg-utils.html#time-duration-syntax

Does this work for you?
        —Jim DeLaHunt, software engineer, Vancouver, Canada




More information about the ffmpeg-user mailing list