如何安装ffmpeg

时间:2016-03-09 09:53:57

标签: php linux apache video ffmpeg

我想制作一个“迷你”编辑器视频。我的目标是,剪切视频的某些部分,然后保存它,并创建一个撤消按钮。现在,我一直在寻找最佳解决方案(此操作必须在网站上完成),我发现我必须使用ffmpeg。我不知道ffmpeg是否已安装在我的服务器上,我使用这个php脚本来发现它:

<?php

/**
 * Test script for FFmpeg
 *
 * @author Andycoder <http://wdevblog.net.ru/>
 */

ini_set('display_errors',1);
error_reporting(E_ALL);

$is_windows = strpos( php_uname(), "Windows" ) !== false;
$ffmpeg_path = !empty( $_POST['ffmpeg_path'] ) && strpos( $_POST['ffmpeg_path'], 'ffmpeg' ) !== false ? trim( $_POST['ffmpeg_path'] ) : '';
if( !$ffmpeg_path && !$is_windows ){
    $ffmpeg_path = trim( shell_exec( 'which ffmpeg' ) );
}

function getCodecs( $ffmpeg_path = '' ) {

    $lines = array();
    $encoders = array();
    exec( "{$ffmpeg_path} -codecs", $lines);

    foreach ($lines as $line) {

        if (preg_match('/^\s+([A-Z .]+)\s+(\w{2,})\s+(.*)$/', $line, $m)) {
            $type = trim($m[1]);
            if (strpos($type, 'E') !== false) {
                $encoder = trim($m[2]);
                if (strpos($encoder, ',') !== false) {
                    foreach (split(',', $encoder) as $e) {
                        $encoders[] = $e;
                    }
                } else {
                    $encoders[] = $encoder;
                }
            }
        }
    }
    sort($encoders);

    return $encoders;
}

function getPHPPath(){

    $is_windows = strpos( strtolower(php_uname()), 'windows' ) !== false;

    if( $is_windows ){
        $output = dirname(ini_get('extension_dir')) . "/php.exe";
    }else{
        $output = trim(shell_exec("which php"));
    }

    return $output;
}

$info = array();

$info['php_version'] = array( 'name' => 'PHP version', 'value' => phpversion() );
$info['php_path'] = array( 'name' => 'PHP path', 'value' =>  getPHPPath() );
$info['web_server'] = array( 'name' => 'Web server', 'value' => $_SERVER['SERVER_SOFTWARE'] );
$info['ffmpeg_path'] = array( 'name' => 'FFMPEG path', 'value' =>  $ffmpeg_path );

$info['ffmpeg_version'] = array( 'name' => 'FFMPEG version', 'value' => '' );
if( $ffmpeg_path ){
    $ffmpeg_ver = shell_exec( "{$ffmpeg_path} -version" );
    preg_match( '/.+version.+/', $ffmpeg_ver, $matches );
    if( !empty( $matches ) ){
        $info['ffmpeg_version']['value'] = $matches[0];
    }
}
$info['yamdi_path'] = array( 'name' => 'Yamdi path', 'value' => !$is_windows ? trim(shell_exec('which yamdi')) : '' );
$info['mp4box_path'] = array( 'name' => 'MP4Box (GPAC) path', 'value' => !$is_windows ? trim(shell_exec('which MP4Box')) : '' );
$info['qtfaststart_path'] = array( 'name' => 'qt-faststart path', 'value' => !$is_windows ? trim(shell_exec('which qt-faststart')) : '' );
$info['flvtool2_path'] = array( 'name' => 'flvtool2 path', 'value' => !$is_windows ? trim(shell_exec('which flvtool2')) : '' );

$info['ffmpeg_codecs'] = array( 'name' => 'FFMPEG codecs', 'value' => array() );
if( $ffmpeg_path ) {
    $info['ffmpeg_codecs']['value'] = getCodecs( $ffmpeg_path );
}

if( empty( $info['ffmpeg_codecs']['value'] ) ){
    $info['ffmpeg_path']['value'] = '';
}

ksort($info);

?>
<!DOCTYPE html>
<html>
<head>
    <title>Test server</title>
</head>
<body>

<script type="text/javascript">
    function expandCollapse( id ){
        if( document.getElementById(id).style.display == 'none' ){
            document.getElementById(id).style.display = 'block';
        }else{
            document.getElementById(id).style.display = 'none';
        }
    }
</script>

<div>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
        <label>
            FFmpeg path:
            <input type="text" name="ffmpeg_path" value="<?php echo $info['ffmpeg_path']['value']; ?>">
        </label>
        <button type="submit">Submit</button>
    </form>
    <br>
</div>

<table cellpadding="5" cellspacing="0" border="1">
    <colgroup>
        <col width="30%" />
        <col width="70%" />
    </colgroup>
    <thead>
        <tr>
            <th>Property</th>
            <th>Value</th>
        </tr>
    </thead>
    <tbody>

        <?php foreach( $info as $key => $opt ): ?>

        <tr>
            <td><?php echo $opt['name']; ?>:</td>
            <td>

                <?php if( !empty( $opt['value'] ) ): ?>

                    <?php
                    if( !is_array( $opt['value'] ) ):
                        echo $opt['value'];
                    else: ?>

                        <a href="#" style="display: inline-block; margin: 5px 0;" onclick="expandCollapse('<?php echo $key; ?>');return false;">[Expand/Collapse]</a>
                        <div id="<?php echo $key; ?>" style="display: none;">

                        <?php foreach( $opt['value'] as $val ): ?>

                            <div><?php echo $val; ?></div>

                        <?php endforeach; ?>

                        </div>

                    <?php endif; ?>

                <?php else: ?>
                    <span style="color:red;">[Not found]</span>
                <?php endif; ?>

            </td>
        </tr>

        <?php endforeach; ?>

    </tbody>
</table>

</body>
</html>

让我回复:

enter image description here

所以,我没有在该服务器上安装ffmpeg。服务器应该是Linux,我这样说是因为我使用Internet中的众多网站之一来发现它。 enter image description here

我知道网站上说Web服务器是Engine-x,但是我的公司告诉他的是Apache(就像php脚本已经告诉我的那样)。现在,我发现这个链接http://www.mysql-apache-php.com/ffmpeg-install.htm(在Stackoverflow和许多其他部分中)说明如何在Linux中安装ffmpeg,但我应该在哪里执行这些命令?我应该用Putty吗?或者什么?

0 个答案:

没有答案