Fixing FFmpeg Error: Muxing Packet & Concatenating GoPro Videos
When working with multiple GoPro video files, preparing them for editing or final rendering, you may encounter issues with FFmpeg while concatenating or re-muxing them. This article aims to address potential problems and provide solutions when working with FFmpeg.
Background
FFmpeg is a powerful, open-source tool for working with multimedia files. It includes the ability to re-mux, concatenate and manipulate video/audio data streams in many different ways. This functionality is important when working with multiple video files from devices like GoPro cameras. A common use-case involves concatenating multiple video files, e.g., to create a longer clip, and re-muxing them into one MP4.
The Problem: FFmpeg Messes up Original Stream Order
Suppose you have a series of MP4 files from a GoPro camera: gopro1.MP4; gopro2.MP4, gopro3.MP4. You want to concatenate these files into a single MP4. A typical FFmpeg command to do this is:
ffmpeg -safe 0 -f concat -i <input\_list> -c copy output.mp4Where <input\_list> is a text file listing the input files in the order you want to concatenate them. However, for some reason, FFmpeg reorders the streams making the output file unplayable in certain media players or audio-video synchronization off.
GoPro Videos and FFmpeg Stream Types
GoPro H.264 MP4 files consist of three main streams:
- Video: The actual video content track.
- Audio: The audio track accompanying the video.
- Subtitles/Captions: Metadata usually containing details like the resolution or video orientation.
These subtitle/metadata streams can cause issues with FFmpeg when concatenating multiple GoPro video files because FFmpeg might attempt to reorder the streams, leading to synchronization issues and making the output unplayable.
The Solution: Remapping Streams and Excluding Unknown Types
To fix the FFmpeg muxing packet issue, you can use the following command:
ffmpeg -ssesof -1 -i input1.MP4 -map 0:v -map 0:3 -c copy -copy_unknown -map_metadata -1 -f mp4 intermediate1.mp4Here's what the different command parts do:
-ssesof -1: Skip the first frame of the input to avoid timestamps/MPEG Ts offset issues.-i input1.MP4: The input file name.-map 0:v -map 0:3: Map the video and metadata stream of input1.MP4 (Note: The exact stream number might differ, so check your specific files using the 'ffprobe' command).-c copy -copy_unknown: Copy codec parameters, including the unknown ones from the input.-map_metadata -1: Exclude metadata like the GPS data from the first input file during the muxing process.-f mp4: MP4 output format.intermediate1.mp4: The name of the output file.
Repeat the command for the rest of the GoPro files:
ffmpeg -ssesof -1 -i input2.MP4 -map 0:v -map 0:3
```arduino
-c copy -copy_unknown -map_metadata -1 -f mp4 intermediate2.mp4