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

How to Merge two videos without re- encoding

1个答案

1

When you need to merge two videos without re-encoding, you can use FFmpeg's concat protocol. This method is suitable for video files with identical formats, such as frame rate, resolution, and encoding format must all be identical.

Steps:

  1. Prepare the video files
    First, ensure that both video files have identical formats. You can use the ffprobe command to inspect video information.

  2. Create a file list
    List the paths of all videos to be merged in a text file, with each path on a separate line and prefixed with the file keyword. For example, create a file named filelist.txt with the following content:

    shell
    file 'video1.mp4' file 'video2.mp4'
  3. Use FFmpeg to merge
    Execute the following command to merge the videos:

    bash
    ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.mp4

    Here, -f concat specifies the use of the concat protocol, -safe 0 allows the use of absolute paths or non-standard characters, -i filelist.txt specifies the input file list, and -c copy instructs FFmpeg to copy the original stream data without re-encoding.

Example:

Suppose you have two video clips, clip1.mp4 and clip2.mp4, both with the same H.264 encoding and 720p resolution. You can follow these steps:

  1. Check the format
    ffprobe clip1.mp4 and ffprobe clip2.mp4

  2. Create the file list
    Edit filelist.txt and add:

    shell
    file 'clip1.mp4' file 'clip2.mp4'
  3. Execute the FFmpeg command
    Run the following command in the terminal:

    bash
    ffmpeg -f concat -safe 0 -i filelist.txt -c copy merged_video.mp4

This will produce merged_video.mp4 as the merged video without re-encoding, preserving the original video quality. The advantage of this method is that it is fast and does not degrade video quality. However, the drawback is that all video files must be identical in terms of encoding, container format, frame rate, etc. If there are mismatches, you may need to convert them to the same format first.

2024年6月29日 12:07 回复

你的答案