[FFmpeg-trac] #10200(ffmpeg:new): Piping WEBP image will produce a broken image
FFmpeg
trac at avcodec.org
Fri Feb 17 07:38:44 EET 2023
#10200: Piping WEBP image will produce a broken image
---------------------------------------+----------------------------------
Reporter: lolcat | Owner: (none)
Type: defect | Status: new
Priority: normal | Component: ffmpeg
Version: 4.3.5 | Resolution:
Keywords: webp, sigpipe | Blocked By:
Blocking: | Reproduced by developer: 0
Analyzed by developer: 0 |
---------------------------------------+----------------------------------
Description changed by lolcat:
Old description:
> 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:
> {{{#!sh
> ffmpeg -i 'https://th.bing.com/th?id=OMB1.7pHOr_m7KOKS3w&pid=2.1' -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:
> {{{#!sh
> ffmpeg -i 'https://th.bing.com/th?id=OMB1.7pHOr_m7KOKS3w&pid=2.1' -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.
>
> Thank you!
New description:
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:
{{{#!sh
ffmpeg -i 'https://th.bing.com/th?id=OMB1.7pHOr_m7KOKS3w&pid=2.1' -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:
{{{#!sh
ffmpeg -i 'https://th.bing.com/th?id=OMB1.7pHOr_m7KOKS3w&pid=2.1' -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.
UPDATE:
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: https://th.bing.com/th?id=OMB1.7pHOr_m7KOKS3w 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)
{{{#!php
<?php
$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 -",
"rb"
);
if($handle === false){
// ffmpeg call failed
return;
}
$bytemod = false;
while(!feof($handle)){
if($bytemod === false){
echo substr_replace(fread($handle, 7), hex2bin("88b405"),
4, 3);
$bytemod = true;
continue;
}
echo fread($handle, 1);
}
fclose($handle);
}}}
--
--
Ticket URL: <https://trac.ffmpeg.org/ticket/10200#comment:1>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list