How to extract and join video files using ffmpeg

In this article we show how to extract one or different parts from a video file. We also show you how you can join two or more videos into one.
With these methods you can easily create small video summaries from one bigger video if you want, extracting relevant parts and joining them together into a summary or a trailer video.

We have already show how to extract images or frames from a video file into image files in a previous tutorial. Now with a similar method we will extract video parts from a bigger video file into smaller video files. Therefore we will be able to extract the most important part from a video, for example, we can extract a video with the most important 5 seconds from a video of 5 minutes.

Again, we will be using the program ffmpeg as it is an excellent program for these type of operations.

In this example we will extract 5 seconds from the second 20 to the second 25 of the video named example.mp4:

ffmpeg -i example.mp4 -f mp4 -ss 20 -t 5 -c:v libx264 -preset fast -c:a aac summary.mp4 -hide_banner

Here are the important parameters:

  • -ss 20 we are telling ffmpeg to seek to second 20 of the input video file to start processing. Change 20 for any time you want.
  • -t 5 we are indicating that the output file will have a time duration of 5 seconds.

The other parameters in this example (-f mp4, -c:v libx264, -preset fast, -c:a aac) are to encode and process the output video using libx264 to produce a mp4 file. You can read more about how to convert a video file into a mp4 file here. We can't just use the copy option (with -c:v copy) and we need to encode the new video in order to have it correctly.

Join various videos into one

Imagine that we have two short videos of 5 seconds of duration each one and we want to join them (the two videos are summary1.mp4 and summary2.mp4). We can do with the following command:

ffmpeg -i summary1.mp4 -i summary2.mp4 -filter_complex "[0:v:0] [0:a:0] [1:v:0] [1:a:0] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" -c:v libx264 -preset fast -c:a aac summary.mp4 -hide_banner

In this example we are using a complex filter that tells ffmpeg to concatenate the two files one after the other and process and encode the result into an output file called summary.mp4.

Again, we need to process the output file. With the method in this example we can concatenate videos that have different formats.

Conclusion and recomendations

With this method you can extract little parts from videos in order to have little summaries of them. It can be useful in video sites over the Internet to have little summaries of the videos. You can even have little video summaries instead of just one picture for your videos

当前网页内容, 由 大妈 ZoomQuiet 使用工具: ScrapBook :: Firefox Extension 人工从互联网中收集并分享;
若有不妥, 欢迎评注提醒:


订阅 substack 体验古早写作:

点击注册~> 获得 100$ 体验券: DigitalOcean Referral Badge

关注公众号, 持续获得相关各种嗯哼:


关于 ~ DebugUself with DAMA ;-)
公安备案号: 44049002000656 ...::