我使用命令提取帧
ffmpeg -i "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov" -f image2 -vf fps=fps=1 ipcam_%04d.png
我水平平铺提取的帧
ffmpeg -i ipcam_73_0001.jpg -i ipcam_73_0002.jpg -filter_complex hstack a.jpg
ffmpeg -i a.jpg -i ipcam_73_0003.jpg -filter_complex hstack a.jpg
ffmpeg -i a.jpg -i ipcam_73_0004.jpg -filter_complex hstack a.jpg
.. 很快
如何通过管道传输第一个ffmpeg
提取命令并堆叠输出?
答案1
也许可以写一个脚本来堆叠它?例如
<?php
declare(strict_types=1);
function wtf(string $uri, int $seconds = 5): string
{
$original_working_dir = getcwd();
$work_dir = $temp_file = tempnam(sys_get_temp_dir(), 'wtf');
unlink($work_dir);
mkdir($work_dir, 0700);
chdir($work_dir);
$cmd = implode(" ", array(
"ffmpeg",
"-i " . escapeshellarg($uri),
"-f image2",
//"-vf fps=fps=1",
"-vsync passthrough",
"-t " . ((int)$seconds),
"-an",
"wtf_%04d.png",
));
$out = shell_exec($cmd . " 2>&1");
$images = glob("*.png");
//var_dump($images);die();
natsort($images);
assert(count($images) >= 2);
$first = true;
for ($i = 0; $i < count($images); ++$i) {
$image = $images[$i];
$cmd = implode(" ", array(
"ffmpeg",
//"-y",
"-i " . escapeshellarg($image),
($i === 0 ? "-i " . escapeshellarg($images[$i + 1]) : "-i a1.jpg"),
"-filter_complex hstack",
"a2.jpg"
));
//var_dump($cmd);
$out = shell_exec($cmd. "2>&1");
@unlink("a1.jpg");
// > Output a.jpg same as Input #1 - exiting
// > FFmpeg cannot edit existing files in-place.
rename("a2.jpg", "a1.jpg");
if ($i === 0) {
++$i;
}
}
$ret = file_get_contents("a1.jpg");
var_dump($out, $images, $cmd, $original_working_dir, $work_dir);
chdir($original_working_dir);
$cmd_cleanup = "rm -rf " . escapeshellarg($work_dir);
passthru($cmd_cleanup);
return $ret;
}
$uri = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov";
$imageBinary = wtf($uri, 5 * 1);
file_put_contents("a.jpg", $imageBinary);
(但请注意,
$work_dir = $temp_file = tempnam(sys_get_temp_dir(), 'wtf');
unlink($work_dir);
mkdir($work_dir, 0700);
部分技术上存在竞争条件错误,bin2hex(random_bytes(10))
如果你担心的话,你可以用一些-scheme 来代替它)