Opened 16 months ago

Last modified 2 months ago

#10200 new defect

Piping WEBP image will produce a broken image

Reported by: lolcat Owned by:
Priority: normal Component: ffmpeg
Version: 4.3.5 Keywords: webp, sigpipe
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description (last modified by lolcat)

Hello. I've been trying to convert a video to an animated webp thumbnail image. This command doesn't work, because the output is piped. When I output to a file on disk, this problem does not occur. Here is my command:

ffmpeg -i '' -vf "fps=10,scale=148:83:flags=lanczos" -vcodec libwebp -lossless 0 -compression_level 6 -q:v 50 -loop 0 -preset picture -an -f webp - > test.webp

But if I use the following command:

ffmpeg -i '' -vf "fps=10,scale=148:83:flags=lanczos" -vcodec libwebp -lossless 0 -compression_level 6 -q:v 50 -loop 0 -preset picture -an -f webp out.webp

The image will load just fine in all modern browsers (notice at the end, I'm outputting to a file instead of a pipe). When using hexedit, I found out that the bytes 5 to 7 are all 0s, when it should be 88 B4 05. Patching these bytes in manually magically fixes the image.

I investigated the bug a little, and it seems that replacing the bytes I talked about only fixes the issue *sometimes*. When trying to convert this URL: it does not yield any errors in both ffmpeg and any image decoder that supports it. But if I try to convert the video I linked in the original question (first code snippet), I get a corruption in the middle of the file. I know this because I am piping the output of ffmpeg into the Firefox browser, and in the console, even though I can see that the image started animating, it cuts off and tells me that the file is either "truncated, or corrupt". I established that it was not truncated, and truly corrupted, since the filesize is not different from something outputted by the second command ...

I'm at a lost here. This sounds like a pipe encoder issue, and I don't have the expertise to fix this. If this helps anyone, I will post my (PHP) attempt at fixing the file(s)


$video = escapeshellarg($_GET["v"]);

header("Content-Type: image/webp");
//header("Content-Type: text/plain");
$handle = popen(
        "ffmpeg -i {$video} -vf \"fps=10,scale=148:83:flags=lanczos\" -vcodec libwebp -lossless 0 -compression_level 6 -q:v 50 -loop 0 -preset picture -an -f webp -",

if($handle === false){
        // ffmpeg call failed

$bytemod = false;

        if($bytemod === false){
                echo substr_replace(fread($handle, 7), hex2bin("88b405"), 4, 3);
                $bytemod = true;
        echo fread($handle, 1);


Change History (3)

comment:1 by lolcat, 16 months ago

Description: modified (diff)

comment:2 by lolcat, 16 months ago

Update #2:
I compiled FFMPEG to see if the issue had been fixed. It has not. It still generates broken images when piped.

comment:3 by mkver, 2 months ago

Hint: If you want an animated WebP image, you need to use the libwebp_anim encoder and not libwebp.

Note: See TracTickets for help on using tickets.