To copy the video stream, convert all audio tracks to AC3, and retain only English subtitles using FFmpeg, you must use specific mapping flags. The command ffmpeg -i input.mp4 -c:v copy -c:a ac3 -map 0:v:0 -map 0:a? -map -0:s? -map -0:s? -map 0:s:m:language:eng achieves this efficiently. This approach ensures video quality is preserved while strictly filtering subtitle streams.
The Command Structure Explained
The core of this operation relies on precise stream selection. Many users attempt simple conversion commands that inadvertently strip non-English subtitles or fail to transcode audio correctly. The correct syntax requires explicit mapping instructions for each stream type. First, we define the input file with-i input.mp4. Next, we specify the codec for the video stream. Using -c:v copy tells FFmpeg to copy the video stream without re-encoding it. This preserves the original quality and drastically reduces processing time. It is crucial not to change the video codec unless necessary, as re-encoding can introduce artifacts and loss of fidelity.
For the audio streams, we use -c:a ac3. This flag instructs FFmpeg to encode all selected audio streams into the AC3 format (Dolby Digital). AC3 is widely supported by hardware players, set-top boxes, and streaming devices, making it a robust choice for compatibility. Note that if your source audio is already AC3, FFmpeg may still re-encode it depending on the bitstream settings, but the output will be standardized.
Mapping Video and Audio Streams
Stream mapping is where most errors occur. We need to explicitly tell FFmpeg which streams to include in the output container. Use-map 0:v:0 to select the first video stream from the input. This ensures that even if multiple video streams exist, only the primary one is carried over. If you have multiple video tracks and want to keep them all, you might adjust this, but for standard transcoding, selecting the main track is sufficient.
For audio, the flag -map 0:a? selects all audio streams present in the input file. The question mark indicates "optional," meaning if no audio streams are found, the command will not fail. This is safer than -map 0:a, which would throw an error if the input lacks audio. By combining this with -c:a ac3, every selected audio stream is converted to AC3.
Filtering Subtitles Correctly
Retaining only English subtitles requires a two-step mapping process. First, we must remove all subtitle streams, and then we selectively add back only the English ones. Start by stripping all subtitles with-map -0:s?. This negative map removes any stream labeled as a subtitle from the default selection. If you have multiple subtitle tracks in different languages, they are all discarded at this stage.
Next, we add the English subtitles back using -map 0:s:m:language:eng. This complex map selector looks for subtitle streams that have the metadata language tag set to "eng". This is more reliable than guessing stream indices because language tags are often embedded in the file header. If your subtitles do not have proper language metadata, this method will fail to find them. In such cases, you may need to identify the specific stream index using ffprobe and map it directly, e.g., -map 0:s:1.
It is important to note that some containers, like MP4, have limitations regarding AC3 audio. While modern MP4 containers support AC3, older players might struggle. For maximum compatibility, consider using a MKV container instead. To do this, simply change the output filename extension to .mkv. MKV supports virtually all codecs and metadata structures without restriction.
Handling Metadata and Compatibility
When copying video and converting audio, metadata handling becomes critical. FFmpeg copies metadata by default, but sometimes you want to clean it up or ensure consistency. You can use-movflags +faststart if you are outputting to MP4 to optimize web playback. However, if you switch to MKV, this flag is unnecessary.
Another common issue is the presence of forced subtitles. Sometimes, a single subtitle track contains both normal dialogue and forced translations (e.g., for foreign songs). If you want to keep forced subtitles, you should not use -map -0:s? followed by -map 0:s:m:language:eng blindly. Instead, you might need to filter based on the "forced" attribute. However, for most general use cases, keeping all English-language subtitles is the desired outcome.
If you encounter warnings about unsupported bitstreams, check your FFmpeg version. Older versions may not support AC3 encoding natively. Ensure you are using a recent build that includes libavcodec support for AC3. You can verify this by running ffmpeg -encoders | grep ac3. If it appears in the list, your installation is capable.
For related tasks, such as adding background music or censoring audio, see our guides on Adding Random Music for Multiple Videos with FFmpeg and Creating a Modern Bleep Censor for Audio and Video. These resources expand on audio manipulation techniques that complement this workflow.
Troubleshooting Common Errors
Users often face issues when the language tag is missing. If the command produces an output with no subtitles, it is likely because the source file does not label the English subtitles as "eng". Useffprobe -v quiet -print_format json -show_streams input.mp4 to inspect the stream details. Look for the tags section within the subtitle stream data. If the language is listed as "en" instead of "eng", you may need to remap using the stream index or update the metadata before processing.
Another error involves the output container rejecting the AC3 stream. As mentioned, MP4 has strict standards. If you receive an error like "Invalid argument" or "Codec not supported", switch to MKV. The command remains identical except for the output filename. MKV is a matroska container that acts as a universal wrapper for almost any combination of codecs.
Finally, always test with a short clip before processing full-length movies. Transcoding audio can be CPU-intensive, and verifying the output quickly saves hours of wasted time. Check the duration, audio bitrate, and subtitle presence in a media player like VLC or MPC-HC.
Frequently Asked Questions
Can I keep the original audio format instead of converting to AC3?
Yes, replace-c:a ac3 with -c:a copy to preserve the original audio codec. However, this means the audio will not be converted to Dolby Digital, which might affect compatibility with certain legacy devices that require AC3.
What if my subtitles are not tagged as "eng"?
If the language metadata is incorrect or missing, you cannot rely on the language filter. You must identify the stream index usingffprobe and map it manually, for example, -map 0:s:2. Alternatively, you can rename the subtitle files externally and burn them into the video using subtitles filters.
Why did my output file become very large?
AC3 audio typically uses bitrates between 192kbps and 640kbps. If you have multiple audio tracks, each is converted separately, increasing the total size. Additionally, if you accidentally re-encoded the video instead of copying it, the file size will increase significantly. Always verify-c:v copy is active.