{"record":{"id":"2f2cafd44fbc1e31","repo":"AlistGo/alist","slug":"ffmpeg-go-failed-to-resize-image-s-to-buffer-w","errorCode":null,"errorMessage":"ffmpeg-go failed to resize image %s to buffer: %w","messagePattern":"ffmpeg-go failed to resize image (.+?) to buffer: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/local/util.go","lineNumber":108,"sourceCode":"\t\t\"f\":       outputFormat, // Format for piping (e.g., image2pipe, png_pipe)\n\t}\n\tif vcodec != \"\" {\n\t\toutputArgs[\"vcodec\"] = vcodec\n\t}\n\tif outputFormat == \"mjpeg\" {\n\t\toutputArgs[\"q:v\"] = \"3\"\n\t}\n\n\terr = ffmpeg.Input(inputFile).\n\t\tOutput(\"pipe:\", outputArgs). // Output to pipe (stdout)\n\t\tGlobalArgs(\"-loglevel\", \"error\").\n\t\tSilent(true).                     // Suppress ffmpeg's own console output\n\t\tWithOutput(outBuffer, os.Stderr). // Capture stdout to outBuffer, stderr to os.Stderr\n\t\t// ErrorToStdOut(). // Alternative: send ffmpeg's stderr to Go's stdout\n\t\tRun()\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"ffmpeg-go failed to resize image %s to buffer: %w\", inputFile, err)\n\t}\n\tif outBuffer == nil || outBuffer.Len() == 0 {\n\t\treturn nil, fmt.Errorf(\"ffmpeg-go produced empty buffer for %s\", inputFile)\n\t}\n\n\treturn outBuffer, nil\n}\n\nfunc generateThumbnailWithImagingOptimized(imagePath string, targetWidth int, quality int) (*bytes.Buffer, error) {\n\n\tfile, err := os.Open(imagePath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open image: %w\", err)\n\t}\n\tdefer file.Close()\n\n\timg, err := imaging.Decode(file, imaging.AutoOrientation(true))\n\tif err != nil {","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/local/util.go#L90-L126","documentation":"The ffmpeg-go library (github.com/u2takey/ffmpeg-go) failed to run the ffmpeg child process that resizes an image and pipes it to stdout. The %s is the input file, %w carries the exec error: process not found (exec: 'ffmpeg': executable file not found in $PATH), non-zero ffmpeg exit code (corrupt/unsupported input, bad filter arguments), or context cancellation. ffmpeg's own stderr is forwarded to os.Stderr via WithOutput, so the real reason is visible on the server console, not in the error string.","triggerScenarios":"getThumb with useFFmpeg=true on a host without the ffmpeg binary installed; ffmpeg built without the requested codec (e.g. mjpeg/png encoder missing in a minimal build); an input image ffmpeg cannot demux (WebP in old builds, HEIC, truncated download); invalid scale filter arguments when width <= 0.","commonSituations":"Docker images deployed without ffmpeg (alpine-based images especially), ffmpeg present at build time but not in the runtime container PATH, or enabling the 'use ffmpeg for thumbnails' option as a workaround for WebP only to hit a build without libwebp.","solutions":["Confirm ffmpeg is installed and visible to the process: run 'ffmpeg -version' in the same environment (inside the container if containerized)","Look at the process stderr (forwarded to os.Stderr) for ffmpeg's actual diagnostic line","Test the exact operation manually: ffmpeg -i <input> -vf scale=<width>:-1 -f image2pipe -loglevel error -","If ffmpeg is fine but the input is unsupported, disable useFFmpeg and fall back to the pure-Go imaging path, or install a full ffmpeg build (libwebp/libheif)"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// fail fast at startup if ffmpeg is required\nif d.useFFmpeg {\n    if _, err := exec.LookPath(\"ffmpeg\"); err != nil {\n        return fmt.Errorf(\"useFFmpeg enabled but ffmpeg not found in PATH: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err != nil { // ffmpeg path failed\n    log.Printf(\"ffmpeg resize failed for %s: %v, falling back to imaging\", inputFile, err)\n    return generateThumbnailWithImagingOptimized(inputFile, width, 85)\n}","preventionTips":["Install ffmpeg in the runtime container image and verify with exec.LookPath at driver Init","Capture os.Stderr output from WithOutput into a logger so failures are diagnosable","Keep the pure-Go imaging path as an automatic fallback"],"tags":["ffmpeg","thumbnail","external-process","environment","local-driver"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}