Use FFmpeg’s -framerate input flag and the scale video filter to convert a sequence of JPG images into an MP4 file on Windows 10. This approach ensures the first frame is correctly scaled to your desired resolution while maintaining the specified frame rate for smooth playback.
Understanding FFmpeg Image Input Parameters
When converting static images into a video stream, FFmpeg requires specific instructions on how to interpret the image sequence. By default, many users assume that FFmpeg will automatically detect the frame rate or resolution from the first image, but this often leads to incorrect output or playback issues. To ensure the first frame is scaled to the clip resolution and frame rate, you must explicitly define these parameters before the input file specification. The critical component here is the-framerate option. Unlike the -r flag which can sometimes be ambiguous depending on whether it is applied to input or output, placing -framerate immediately before the -i (input) flag tells FFmpeg how many frames per second to expect from the incoming image sequence. If you do not specify this, FFmpeg may default to a very low frame rate (often 25 fps or even lower depending on the version), causing the video to appear choppy or run at an unexpected speed.
Another common pitfall involves the resolution. Images often have varying dimensions, or you may want to standardize all frames to a specific width and height. The s:v (video size) option allows you to set the resolution directly in the input stream. However, relying solely on s:v might not apply scaling filters if the aspect ratio changes, so combining it with explicit filtering provides more control.
Constructing the Correct Command
To fix the previous errors involving non-existent filters likevideo_scale, we must use the standard scale filter within the -vf (video filter) chain. The correct syntax involves chaining the framerate setting and the scaling filter together. Here is the robust command structure that works reliably on Windows 10:
ffmpeg -framerate 30 -i "image_%03d.jpg" -vf "scale=1920:1080" -c:v libx264 -pix_fmt yuv420p output.mp4
Let us break down why each part of this command is necessary. The -framerate 30 sets the input frame rate to 30 frames per second. This means FFmpeg will treat every image as lasting for 1/30th of a second. The -i "image_%03d.jpg" specifies the input pattern. The %03d is a printf-style format specifier that matches files like image_001.jpg, image_002.jpg, etc. Ensure your image files follow this naming convention, or adjust the pattern to match your actual filenames.
The -vf "scale=1920:1080" part applies the scaling filter. This filter takes the original image dimensions and scales them to 1920x1080 pixels. If you wish to maintain the aspect ratio and only specify one dimension, you can use scale=1920:-1, where -1 tells FFmpeg to calculate the height automatically based on the width. It is crucial to place this filter after the input definition but before the codec selection.
Finally, -c:v libx264 selects the H.264 video codec, which is widely supported by media players and web browsers. The -pix_fmt yuv420p flag ensures pixel compatibility with most players, preventing color distortion issues in some older software.
Handling Aspect Ratios and Scaling Issues
Sometimes, simply scaling to a fixed resolution results in stretched or distorted images if the source images do not match the target aspect ratio. In such cases, you might prefer to pad the image rather than stretch it. You can achieve this by using thescale filter in combination with the pad filter.
For example, if you want to scale the image to fit within 1920x1080 without stretching, and then center it on a black background, you can use:
-vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black"
This complex filter chain first scales the video down if necessary while preserving the aspect ratio. Then, the pad filter adds black bars to the top/bottom or left/right to fill the 1920x1080 canvas. The expressions (ow-iw)/2 and (oh-ih)/2 calculate the offset to center the content. This method is superior for photo slideshows where maintaining the integrity of the original image is important.
If you are dealing with a large number of images, consider checking your file naming consistency. Missing numbers in the sequence (e.g., jumping from _009.jpg to _011.jpg) can cause FFmpeg to skip frames or fail entirely. Using a tool to rename files sequentially before running the FFmpeg command saves debugging time. For more advanced manipulation like cropping or changing resolution dynamically, see FFmpeg Cropping, Changing Resolution, and FPS in One Process.
Optimizing Output Quality and Performance
The quality of the resulting MP4 clip depends heavily on the bitrate and preset settings used with the H.264 encoder. By default, FFmpeg uses a variable bitrate that may not be optimal for all use cases. You can control the quality by adding the-crf (Constant Rate Factor) option. A CRF value between 18 and 23 is generally considered visually lossless to high quality. Lower values mean higher quality and larger file sizes.
ffmpeg -framerate 30 -i "image_%03d.jpg" -vf "scale=1920:1080" -c:v libx264 -crf 20 -pix_fmt yuv420p output.mp4
Adding -preset fast or -preset medium can also help balance encoding speed and compression efficiency. fast is quicker but produces slightly larger files, while medium offers better compression at the cost of encoding time. For most slideshow applications, the difference in file size is negligible, so medium is a safe default.
It is also worth noting that if your images contain transparency (PNGs instead of JPGs), you need to handle alpha channels differently. Since JPG does not support transparency, this guide assumes opaque images. If you switch to PNG inputs, you may need to add -c:v libx264 -pix_fmt yuva420p to preserve alpha data, though most standard players ignore alpha in MP4 containers.
For those interested in other multimedia tasks on Windows 10, such as handling audio streams without transcoding, refer to How to Use ffmpeg (No Transcoding) for Audio on Windows 10.
Frequently Asked Questions
Why is my video playing too fast or too slow?
This is usually caused by an incorrect -framerate setting relative to your image sequence. If the framerate is set too high, the video plays faster; if too low, it plays slower. Ensure the -framerate value matches the intended duration of each image display.
Can I use individual image names instead of a numbered sequence?
Yes, but you must list each file individually in the command line separated by spaces, or use a text file with -f concat. The wildcard or pattern matching (%03d) is only valid for sequentially named files. Listing hundreds of files manually is impractical for large projects.
How do I prevent the image from being stretched during scaling?
Use the force_original_aspect_ratio=decrease option within the scale filter. This ensures the image fits within the target resolution without distorting its proportions. You may need to combine it with a pad filter to fill the remaining space.
What is the best codec for sharing MP4 clips online?
The libx264 codec with yuv420p pixel format is the industry standard for compatibility. It is supported by virtually all web browsers, mobile devices, and social media platforms. Avoid newer codecs like HEVC unless you specifically need smaller file sizes and know your audience supports them.
Does FFmpeg resize all frames or just the first one?
FFmpeg applies the same filters to every frame in the input sequence. If you define a scale filter, every image will be resized to the specified dimensions. There is no special behavior for the first frame unless you use complex conditional logic, which is rarely needed for simple conversions.