2

我用一组图像和 mp3 创建了一个视频。但我想在该视频中添加水印文本。我正在使用下面的代码添加文本。

exec('/usr/local/bin/ffmpeg -y -i output.mov -acodec libmp3lame -vcodec msmpeg4 \
-b:a 192k -b:v 1000k -ar 44100 \
-vf "drawtext=text=string1 string2 string3 string4 string5 string6 string7 :expansion=normal:fontfile=/usr/bin/DejaVuSerif-BoldItalic-webfont.ttf: y=0:x=h-(2*lh)-n: fontcolor=white: fontsize=40: box=1: boxcolor=0x00000000@1" \
-an IMG_0696.avi');

这个问题是视频文件正在以零大小创建。任何人都可以帮助我。或者建议我使用任何其他命令向视频添加水印文本。先感谢您...

4

4 回答 4

2
ffmpeg -i movie.mp4 -i logo.png -filter_complex overlay output.mp4
于 2014-03-26T10:19:15.857 回答
2

我正在使用 php-ffmpeg [下面:Composer Json]:

{
    "require": {
        "php-ffmpeg/php-ffmpeg": "^0.6.1"
    }
}

并使用这个 php-ffmpeg 库,您可以使用以下代码添加水印:

<?php

function processVideo($videoSource,$reqExtension, $watermark = "")
{
    $ffmpeg = FFMpeg\FFMpeg::create();

    $video = $ffmpeg->open($videoSource);

    $format = new FFMpeg\Format\Video\X264('libmp3lame', 'libx264');

    if (!empty($watermark))
    {
        $video  ->filters()
                ->watermark($watermark, array(
                    'position' => 'relative',
                    'top' => 25,
                    'right' => 50,
                ));
    }

    $format
    -> setKiloBitrate(1000)
    -> setAudioChannels(2)
    -> setAudioKiloBitrate(256);

    $randomFileName = rand().".$reqExtension";
    $saveLocation = getcwd(). '/video/'.$randomFileName;
    $video->save($format, $saveLocation);

    if (file_exists($saveLocation))
        return "http://localhost/test/video/$randomFileName";
    else
        return "http://localhost/test/thumb/404.png";

}

echo $videoLocation =  processVideo("sample.mp4","mp4","favicon.png");

?>

[请根据您的需要更新位置。]

于 2016-05-16T06:24:55.697 回答
1

命令:

    ffmpeg -i input.mp4 -i watermark.png -filter_complex 'overlay' output.mp4

在您的控制器中尝试此代码。

  public function setWaterMark(Request $request_body){
      try {
        $watermark = Input::file('watermark');
        $input = Input::file('input');

        ffmpeg = "C:\\ffmpeg\\bin\\ffmpeg";
        $cmd = $ffmpeg . " -i " . $input . " -i " . $watermark . " -filter_complex 'overlay' " . $output_file;
        exec($cmd, $output);

        return $output_file;
  }
于 2019-02-07T03:57:25.020 回答
-2
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open('video.mpg');
$video
    ->filters()
    ->resize(new FFMpeg\Coordinate\Dimension(320, 240))
    ->synchronize();
$video
    ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))
    ->save('frame.jpg');
$video
    ->save(new FFMpeg\Format\Video\X264(), 'export-x264.mp4')
    ->save(new FFMpeg\Format\Video\WMV(), 'export-wmv.wmv')
    ->save(new FFMpeg\Format\Video\WebM(), 'export-webm.webm');

在系统上安装 FFmpeg 的步骤。 http://drupalasia.com/article/how-add-watermark-video-using-php-and-ffmpeg

于 2017-07-13T15:51:39.790 回答