乐闻世界logo
搜索文章和话题

How to Use ffmpeg to split video files by size

1个答案

1

When you need to split video files by size, ffmpeg is a very powerful tool. Below are the steps to use ffmpeg to split video files into segments of fixed size.

First, ensure that you have installed ffmpeg. You can download it from the ffmpeg official website and follow the installation instructions.

Next, open your terminal or command prompt using the command-line tool.

Step 1: Determine the Total Duration of the Video File

Before splitting the file, you need to know the total duration of the video. You can use the following command to retrieve detailed information about the video:

bash
ffmpeg -i input.mp4

This command does not process the video but displays video information, including duration.

Step 2: Calculate Split Points

If you want to split the video by a specific size, such as one file per 500MB, you need to calculate the approximate duration of each segment based on the video's bitrate.

For example, if your video bitrate is approximately 1000 kbps, it consumes approximately 125 KB per second. For a 500 MB video segment, you can estimate the duration of each segment as:

shell
500 MB * 1024 KB/MB / 125 KB/s = 4096 s

Step 3: Split Video Using ffmpeg by Time

After knowing the approximate duration of each video segment, you can start splitting the video. Assuming we split based on the calculation above, each segment is approximately 4096 seconds:

bash
ffmpeg -i input.mp4 -c copy -map 0 -segment_time 4096 -f segment output%03d.mp4

In this command:

  • -c copy indicates using the same video and audio encoding.
  • -map 0 indicates selecting all streams (video, audio, subtitles, etc.).
  • -segment_time 4096 indicates each video file is approximately 4096 seconds.
  • -f segment specifies the output format as multiple video segments.
  • output%03d.mp4 is the output file naming format, where %03d indicates the number starts from 000 and increments.

This allows you to split the video file according to the desired file size. Note that this method is based on time splitting, and the actual file size may have minor variations depending on the specific content and complexity of the video encoding.

Summary

By using ffmpeg's -segment_time option, you can relatively easily split the video according to the expected size. Additionally, using -c copy avoids re-encoding, which allows faster processing while preserving the original video quality. This method is suitable for approximately splitting video files when you don't need precise control over the output file size.

2024年6月29日 12:07 回复

你的答案