FFmpeg is a powerful and highly flexible open-source tool that can handle a wide variety of media formats, including M2TS files. This article will focus on how to alter codec tags in M2TS files using FFmpeg, specifically addressing the case where one audio track has an unusual Blu-ray PCM format.
Understanding M2TS Files and Codec Tags
M2TS files are container formats used for Blu-ray discs and some AVCHD camcorders. They can contain multiple video, audio, and subtitle streams. Codec tags, also known as metadata or header fields, are used to store information about the codec used for each stream.
Why Change Codec Tags?
Changing codec tags can help resolve compatibility issues when playing or editing M2TS files. For instance, in our test scenario, one of the audio tracks has an unusual Blu-ray PCM format, which might not be supported by certain media players or editing software. By altering the codec tag, we can ensure the file is recognized and played correctly.
FFmpeg: A Swiss Army Knife for Media Processing
FFmpeg provides a comprehensive set of tools for handling media files, including M2TS files. One of its capabilities is manipulating codec tags, which is what we will focus on in this article.
Prerequisites
Before using FFmpeg, ensure it is installed on your system. You can download it from the official website (https://ffmpeg.org/download.html). Additionally, you should have some familiarity with command-line interfaces.
Altering Codec Tags with FFmpeg
To alter codec tags in M2TS files using FFmpeg, follow these steps:
Open a terminal (or command prompt on Windows) and navigate to the directory containing the M2TS file (1.m2ts in our test scenario).
Run the following command to view the current codec tags:
ffprobe -loglevel error -show\_entries stream=codec\_name,codec\_tag\_string -of csv=p=0 1.m2ts-
The output will show the codec names and codec tags for all streams. Identify the audio stream with the unusual Blu-ray PCM format. You can find the stream\_index from this output.
-
Run the following command to alter the codec tag:
ffmpeg -i 1.m2ts -c copy -map 0 -metadata:s:a:<stream\_index> codec\_tag=<new\_codec\_tag> output.m2ts -
Replace <stream\_index> with the index of the audio stream with the unusual Blu-ray PCM format. Replace <new\_codec\_tag> with the desired codec tag. For instance, if the original codec tag is 0x01C4 (Blu-ray PCM) and you want to change it to 0x01C5 (DTS), use the following command:
ffmpeg -i 1.m2ts -c copy -map 0 -metadata:s:a:0 codec\_tag=0x01C5 output.m2ts
Explanation of the Command
-i 1.m2ts specifies the input M2TS file, and -c copy tells FFmpeg to copy the original streams without re-encoding them. The -map 0 parameter preserves the original input stream mapping. The -metadata:s:a:<stream\_index> parameter sets the metadata for the specific audio stream, and codec\_tag=<new\_codec\_tag> changes the codec tag for that stream. Finally, output.m2ts specifies the output file name.
FFmpeg is a versatile tool for altering codec tags in M2TS files. By understanding M2TS files and FFmpeg basics, you can easily manipulate codec tags to resolve compatibility issues or adapt files for specific applications.
References
-
FFmpeg Documentation: https://ffmpeg.org/documentation.html
-
M2TS Format: https://en.wikipedia.org/wiki/M2TS