图像管从php到ffmpeg [英] Image pipe from php to ffmpeg

查看:410
本文介绍了图像管从php到ffmpeg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过PHP为图像序列提供FFMpeg,以便从中获取视频。我使用这个shell命令从文本文件中读取图像文件名:

I'm tring to feed FFMpeg whith an image sequence through PHP in order to get a video out of it. I'm using this shell command to read from a text file the image filenames:

cat $(cat " . $image-list-file . ") | ffmpeg -f image2pipe ...

我想输出到管道prom php,也许在修改后图像通过imagemagik或gd。

I would like to output to the pipe prom php, maybe after modifying the images through imagemagik or gd.

如何在PHP中执行此操作?

How can I do this in PHP?

编辑:

使用proc_open和buffer的组合做了这个工作。
这是一个使用GD生成图片的工作测试脚本。

Using a combination of proc_open and buffer did the job. Here's a working test script using some GD generated pictures.

<?php
set_time_limit(0);
$descriptors = array(
    0 => array("pipe", "r")
);

$command = "ffmpeg -f image2pipe -pix_fmt rgb24 -r 30 -c:v png -i - ".
                "-r 30 -vcodec libx264 -pix_fmt yuv420p ".
                "-y test.mp4";

$ffmpeg = proc_open($command, $descriptors, $pipes);

if (is_resource($ffmpeg)){
    for ($i = 0; $i < 180; $i++) {
        $im = @imagecreate(300, 300) or die("GD error");
        $background_color = imagecolorallocate($im, 0, 0, 0);
        $line_color = imagecolorallocate($im, 233, 14, 91);
        $x = rand(0, 300);
        imageline ($im, $x, 0, $x, 300, $line_color);
        ob_start();
        imagepng($im);
        fwrite($pipes[0], ob_get_clean());
        imagedestroy($im);
    }
    fclose($pipes[0]);
}


推荐答案

没有示例文件的示例。但是您应该使用 proc_open() proc_open()在shell中执行命令行,并允许对输入/输出管道进行直接读/写访问。所以你可以在管道完成之前读取输出。您可以在我所链接的手册中找到例子。

It's hard to give a working example without having the example files. But you should use proc_open() for that. proc_open() executes the command line in a shell and allows direct read/write access to input/output pipes. So you can read output before the pipe has finished. You'll find examples on the manual that I've linked.

这篇关于图像管从php到ffmpeg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆