To change a video’s resolution and convert an AIFF audio file using FFmpeg, use the
-vf scale filter to adjust dimensions and map the audio stream with
-c:a. This approach ensures precise control over pixel dimensions while maintaining high-quality audio conversion without re-encoding unnecessary data.
Understanding Resolution vs Frame Size
A common misconception among users is that the
-s flag controls "resolution" in the artistic sense. In reality,
-s sets the frame size (widthxheight) for encoding but does not perform the actual scaling calculation if you want to maintain aspect ratios or target specific dimensions relative to source content. For true resolution manipulation, the
scale video filter is the correct tool. It allows you to specify exact output widths and heights, or use factors like
iw/2 (input width divided by 2). Using
-s alone often results in distorted images if the aspect ratio is not manually calculated beforehand, whereas
scale handles the geometry intelligently.
Handling AIFF Audio Streams
AIFF (Audio Interchange File Format) is a high-quality, uncompressed audio format similar to WAV. When combining it with video, FFmpeg treats it as just another input stream. If your goal is to keep the audio lossless, you should avoid re-encoding it unless necessary. However, many video containers do not support AIFF natively. Common formats like MP4 or MKV prefer AAC or MP3. Therefore, the process usually involves either mapping the existing AIFF stream directly (if the container supports it) or converting it on the fly to a more compatible codec like AAC while preserving quality.
Step-by-Step Video Resolution Change
To resize a video, you must apply a video filter. The syntax for the scale filter is
-vf scale=width:height. You can use variables to make this dynamic. For example, to halve the width and automatically calculate the height to preserve the aspect ratio, you would use
-vf scale=iw/2:-1. Here,
-1 tells FFmpeg to compute the height based on the input width and aspect ratio. If you want a fixed resolution, such as 1920x1080, you would use
-vf scale=1920:1080. Note that if the source aspect ratio differs from the target, black bars may appear unless you also use the
pad filter to add padding.
Integrating AIFF Audio
When merging video and AIFF audio, you need two input files. Let's assume
video.mp4 is your source video and
audio.aiff is your source audio. The basic command structure starts with specifying inputs:
ffmpeg -i video.mp4 -i audio.aiff -map 0:v:0 -map 1:a:0
The
-map flags explicitly tell FFmpeg which streams to include.
-map 0:v:0 selects the first video stream from the first input, and
-map 1:a:0 selects the first audio stream from the second input. This prevents FFmpeg from auto-selecting streams, which can sometimes lead to unexpected behavior if multiple tracks exist.
Optimizing Output and Codec Selection
If you are packaging this into an MP4 container, you likely need to convert the AIFF audio to AAC. You can do this by adding
-c:a aac -b:a 192k to your command. This re-encodes the audio at 192 kbps, which is a good balance between quality and file size. If you wish to keep the audio exactly as is (lossless), you might consider using a Matroska (MKV) container instead, which supports FLAC or even raw PCM, though compatibility with players may vary. Always check the output log to ensure no warnings about unsupported codecs appear. For more complex audio setups, such as adding random music to multiple videos, refer to our guide on
How to Add Random Music (Defined Folder) for Multiple Video with FFMPEG.
Common Pitfalls and Troubleshooting
One frequent error occurs when the output file extension does not match the expected codec. If you save a file as
.mp4 but try to force a codec that MP4 doesn't support, FFmpeg will fail. Another issue is audio synchronization drift. If the audio and video have different frame rates or sample rates, slight desyncs can occur. Ensuring both inputs are processed with consistent timebases helps mitigate this. Additionally, always verify the resulting file plays correctly in your target player. Some older media players struggle with newer H.265/HEVC video codecs combined with certain audio formats.
Advanced Scaling Options
For higher quality scaling, especially when upscaling, you can specify the algorithm used by the scale filter. Adding
scaleflags=lanczos after the resolution values uses the Lanczos interpolation algorithm, which produces sharper results than the default bilinear filter. The command would look like
-vf scale=1920:1080:scaleflags=lanczos. This is particularly useful when converting low-resolution footage to high-definition outputs. Conversely, when downsampling, the default filters are usually sufficient, but you can still enforce specific algorithms for consistency across batches of videos.
Final Command Structure
Combining all elements, a robust command to scale a video to 720p and convert AIFF audio to AAC looks like this:
ffmpeg -i input_video.mp4 -i input_audio.aiff -vf scale=1280:720 -c:v libx264 -preset fast -c:a aac -b:a 192k -shortest output_final.mp4
This command scales the video to 1280x720, encodes video with H.264, converts audio to AAC at 192kbps, and stops encoding once the shorter stream ends (
-shortest). This ensures no silent trailing audio or frozen video frames at the end. For troubleshooting sound issues specifically, see our article on
FFmpeg Warning and No Sound on the Encoding Video.
Frequently Asked Questions
Why did my video look stretched after using the -s flag?
The
-s flag forces a specific frame size without considering the original aspect ratio, leading to distortion. Always use the
scale filter with automatic height calculation (
-1) or explicit aspect-ratio-preserving dimensions to prevent stretching.
Can I keep the AIFF audio completely lossless in an MP4 file?
No, standard MP4 containers generally do not support uncompressed AIFF or PCM audio streams directly in a way that preserves the exact file structure. You must convert the audio to a supported codec like AAC or ALAC, or switch to an MKV container which supports more diverse audio formats.
What is the best video codec for general compatibility?
H.264 (libx264) remains the most widely supported video codec across web browsers, mobile devices, and desktop players. While newer codecs like H.265 offer better compression, they lack universal hardware support on older devices.
How do I fix audio desync in my final video?
Desync often happens when frame rates differ between input and output. Ensure you set the correct timebase or use the
-itsoffset flag to delay one stream slightly. Checking the input metadata with
ffprobe can help identify mismatched timestamps.
Is it faster to scale video before or after encoding?
Scaling is part of the encoding pipeline, so it happens during processing. However, pre-scaling source files can reduce CPU load during final assembly if you are batching multiple videos. For single conversions, letting FFmpeg handle it in one pass is efficient and accurate.