Troubleshooting of FFmpeg: Difference between revisions
| (One intermediate revision by the same user not shown) | |||
| Line 6: | Line 6: | ||
== Troubleshooting of FFmpeg == | == Troubleshooting of FFmpeg == | ||
== File Overwrite Issue When Integrating FFmpeg with PHP == | === File Overwrite Issue When Integrating FFmpeg with PHP === | ||
'''Error condition''': | '''Error condition''': | ||
| Line 36: | Line 36: | ||
Or implement the file overwrite control directly in your PHP script logic. | Or implement the file overwrite control directly in your PHP script logic. | ||
== FFmpeg Fails to Decode Large JPEG Images == | === FFmpeg Fails to Decode Large JPEG Images === | ||
'''Error condition''': | '''Error condition''': | ||
| Line 98: | Line 98: | ||
== Further readings == | == Further readings == | ||
* [https://zulko.github.io/moviepy/ MoviePy documentation — MoviePy documentation] | * [https://zulko.github.io/moviepy/ MoviePy documentation — MoviePy documentation] | ||
* [[Speed_up_websites#Image_Compression | Image Compression]] | |||
== References == | == References == | ||
Latest revision as of 10:32, 4 April 2026
Troubleshooting of FFmpeg issues
Troubleshooting of FFmpeg[edit]
File Overwrite Issue When Integrating FFmpeg with PHP[edit]
Error condition: When integrating FFmpeg commands with PHP scripts, if the output file already exists, FFmpeg displays an overwrite confirmation prompt. However, this prompt is not visible in the PHP execution environment. This causes the PHP script to pause, waiting for user input, without any visible prompt.
Original command:
ffmpeg -i input.mp4 -vf scale=720:404 -c:v libx264 -crf 23 -preset fast -c:a aac -b:a 128k output.mp4
Prompt in terminal environment:
File 'output.mp4' already exists. Overwrite? [y/N]
Solution: Add parameters to the FFmpeg command to control file overwrite behavior:
First option: Auto-overwrite option:
ffmpeg -y -i input.mp4 -vf scale=720:404 -c:v libx264 -crf 23 -preset fast -c:a aac -b:a 128k output.mp4
Second option: Skip if file exists option:
ffmpeg -n -i input.mp4 -vf scale=720:404 -c:v libx264 -crf 23 -preset fast -c:a aac -b:a 128k output.mp4
Or implement the file overwrite control directly in your PHP script logic.
FFmpeg Fails to Decode Large JPEG Images[edit]
Error condition: When processing high-resolution JPEG images, FFmpeg reports the image size as invalid and aborts decoding entirely.
Original command:
ffmpeg -i "image.jpg" -vf scale=2000:-1 output.jpg
Error output:
[mjpeg @ 0x...] [IMGUTILS @ 0x...] Picture size 25600x14400 is invalid [image2 @ 0x...] Could not find codec parameters for stream 0: unspecified size Conversion failed!
Root cause: FFmpeg's internal function `av_image_check_size2()` (in `libavutil/imgutils.c`) validates image dimensions before decoding begins — before the pixel format (`pix_fmt`) is known. Without `pix_fmt`, FFmpeg assumes the worst-case bytes-per-pixel (bpp = 6), then checks:
stride * (height + 128) >= INT_MAX // INT_MAX = 2,147,483,647
For a 25600×14400 image with bpp = 6:
stride = 25600 × 6 = 153,600 result = 153,600 × (14400 + 128) = 2,231,500,800 → exceeds INT_MAX ✗
The actual pixel format of the image is `yuvj420p` (bpp = 1.5), which would pass the check:
stride = 25600 × 1.5 = 38,400 result = 38,400 × (14400 + 128) = 557,875,200 → within INT_MAX ✓
FFmpeg cannot read `pix_fmt` before running the size check, so the image is incorrectly rejected. Passing `-vcodec mjpeg` or `-pix_fmt` does not help — the check runs before any codec parameters take effect.
Solution:
Use ImageMagick instead of FFmpeg for large JPEG files:
magick "image.jpg" -resize 2000x2000\> "output.jpg"
The `\>` flag shrinks only — no enlargement if the image is already smaller than the target.
Or use Pillow to pre-scale before passing to FFmpeg:
python3 -c "
from PIL import Image
Image.MAX_IMAGE_PIXELS = None
img = Image.open('image.jpg')
img.thumbnail((4000, 4000))
img.save('temp.jpg', quality=90)
" && ffmpeg -i temp.jpg -vf scale=2000:-1 output.jpg
Note: `Image.MAX_IMAGE_PIXELS = None` disables Pillow's decompression bomb protection. Only use this for trusted image sources.[1][2]