Use the command ffmpeg -i input.MTS -c:v libx264 -preset fast -crf 23 output.mp4 to convert Canon MTS files efficiently. This command forces re-encoding into a widely compatible MP4 container using the H.264 codec, ensuring smooth playback across devices while maintaining high visual quality with minimal file size increase.
Understanding the MTS Format Challenge
Canon video cameras typically record in the AVCHD format, which stores footage inside an MPEG-2 Transport Stream container with a .MTS extension. While this format is excellent for archiving due to its efficient compression, it presents significant compatibility issues for web streaming, mobile editing, and social media uploads. Most modern software expects standard MP4 containers with AAC audio codecs, leading to errors or unplayable files when you attempt to use raw MTS inputs directly.
The core issue lies not in the video data itself, but in the container structure and the specific encoding parameters used by the camera. FFmpeg handles these streams well, but it requires explicit instructions on how to remux or transcode the data because the default behavior might not match your desired output standards. Without proper flags, you may encounter black screens, audio desynchronization, or files that are too large for practical sharing.
Basic Conversion Workflow
To resolve these compatibility issues, you need to perform a full transcoding operation rather than a simple copy. This process decodes the incoming MPEG-2 video stream and re-encodes it into a more universal format. The following command provides a robust baseline for most users who want a balance between speed and quality.
ffmpeg -i input.MTS -c:v libx264 -preset fast -crf 23 -c:a aac -b:a 192k output.mp4
This command specifies the input file as input.MTS. It sets the video codec to libx264, which is the industry standard for H.264 encoding. The -preset fast option balances processing time with compression efficiency, making it suitable for daily use without excessive CPU load. The -crf 23 parameter controls the Constant Rate Factor, where 23 is considered visually lossless for most content; lower values mean higher quality but larger files.
For the audio, we explicitly specify the AAC codec with a bitrate of 192kbps. This ensures that the audio remains synchronized and compatible with virtually all players. If you skip the audio specification, FFmpeg might choose a less compatible codec depending on its internal configuration, leading to potential playback issues on older devices.
Handling Interlaced Footage
Many Canon cameras record interlaced video to save bandwidth during capture. If you play the converted file on a modern computer or browser, you may notice horizontal lines or "comb" artifacts during fast motion. This happens because progressive displays struggle to render interlaced frames correctly. To fix this, you must deinterlace the video during the conversion process.
Add the -vf fieldorder=bt,deinterlace filter to your command line. The fieldorder=bt part tells FFmpeg that the top field is displayed first (bottom-top), which is the standard for AVCHD. The deinterlace filter then converts the interlaced fields into a progressive sequence. This results in a smoother viewing experience, especially for sports or action scenes recorded by your camera.
ffmpeg -i input.MTS -c:v libx264 -preset fast -crf 23 -vf fieldorder=bt,deinterlace -c:a aac output.mp4
Advanced Optimization Techniques
For users who need faster processing times or specific hardware acceleration, FFmpeg offers several advanced options. If you have an NVIDIA GPU, you can utilize the h264_nvenc encoder instead of libx264. This shifts the workload from the CPU to the GPU, significantly speeding up the conversion process for large batches of files.
However, GPU encoders sometimes produce slightly lower quality at equivalent bitrates compared to CPU-based software encoders. Therefore, it is advisable to test the output before committing to this method for critical projects. You can also adjust the -movflags +faststart flag to move metadata to the beginning of the file. This allows web browsers to start buffering the video immediately, improving the user experience for online distribution.
If you encounter issues related to corrupted headers or invalid signatures during the conversion, refer to our guide on fixing invalid PNG signature errors, which often share underlying causes with container corruption. Additionally, if your goal is to combine these clips with other media, ensure you understand how to concatenate image and video without reencoding the video portion to preserve maximum quality.
Checking File Integrity
Before converting, it is wise to check the integrity of the source MTS file. Corrupted files from broken card removals can cause FFmpeg to hang or produce garbled output. Run ffprobe input.MTS to analyze the stream. Look for any error messages regarding dropped packets or incorrect timestamps. If the probe fails, consider using recovery tools on the SD card before attempting further conversions.
Another common pitfall is dealing with variable frame rates. Some cameras report a constant frame rate even when the actual recording varies slightly. FFmpeg can handle this, but adding -r 30 (or your target frame rate) forces a consistent output, preventing stuttering in players that expect strict timing.
Common Troubleshooting Steps
If the output file plays but has no sound, verify that the audio stream was successfully mapped. Sometimes, FFmpeg defaults to copying the audio stream without re-encoding, which can fail if the destination container does not support the original codec. Explicitly setting -c:a aac resolves this by forcing a compatible re-encode.
If the video appears green or purple, it is likely a color space mismatch. AVCHD uses YUV 4:2:0, while some players expect RGB. Adding -pix_fmt yuv420p to the command line ensures the pixel format is compatible with almost all HTML5 video players and media centers. This small adjustment prevents color distortion in browsers like Chrome and Edge, where seekability issues might otherwise arise due to incompatible formats.
Frequently Asked Questions
Why does my converted video look blocky?
This usually indicates that the CRF value is set too high, resulting in aggressive compression. Lower the CRF value to 18-20 for high-quality results, or increase the bitrate manually using the -b:v flag. Ensure you are not using a very slow preset if you need maximum quality, as slower presets allocate bits more efficiently.
Can I convert MTS to MKV instead of MP4?
Yes, simply change the output filename extension to .mkv. MKV supports more codecs and metadata than MP4, making it ideal for archival purposes. However, keep in mind that some smart TVs and gaming consoles have limited support for MKV containers compared to the universal MP4 standard.
How do I speed up the conversion process?
You can reduce the encoding time by using a faster preset like ultrafast or by enabling hardware acceleration with -c:v h264_nvenc on NVIDIA GPUs. Note that faster presets sacrifice compression efficiency, meaning you will get larger files for the same visual quality. Always test the trade-off between speed and file size.
What should I do if FFmpeg crashes during conversion?
Crashes are often caused by corrupted source files or insufficient memory. First, run ffprobe on the input file to check for errors. If the file is intact, try increasing the thread count with -threads 0 to let FFmpeg auto-detect optimal CPU usage. Updating FFmpeg to the latest version also resolves many known bugs related to specific codec implementations.
Does converting MTS to MP4 lose quality?
If you use a high CRF value (like 23 or lower) and a good preset, the quality loss is negligible to the human eye. This is called "visually lossless" transcoding. However, any re-encoding is technically a generation loss. For final masters, consider keeping the original MTS files and only creating MP4 versions for distribution or editing.