問(wèn)題描述
我創(chuàng)建了一個(gè)包含一組圖像和 mp3 的視頻.但我想為該視頻添加水印文本.我正在使用以下代碼添加文本.
I created a video with group of images and mp3. But i want to add a watermark text to that video .i am using the below code to add the text.
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');
這個(gè)問(wèn)題是視頻文件以零大小創(chuàng)建.任何人都可以幫助我.或者建議我任何其他命令來(lái)向視頻添加水印文本.提前謝謝你...
The issue with this is that the video file is creating with zero size. Can any one help me please. Or else Suggest me any other command to add watermark text to video. Thank you in advance...
推薦答案
我正在使用 php-ffmpeg [Below : Composer Json]:
I am using php-ffmpeg [Below : Composer Json]:
{
"require": {
"php-ffmpeg/php-ffmpeg": "^0.6.1"
}
}
并且使用這個(gè) php-ffmpeg 庫(kù),您可以使用以下代碼添加水印:
and Using this php-ffmpeg library you can add watermark's using the following codes:
<?php
function processVideo($videoSource,$reqExtension, $watermark = "")
{
$ffmpeg = FFMpegFFMpeg::create();
$video = $ffmpeg->open($videoSource);
$format = new FFMpegFormatVideoX264('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");
?>
[請(qǐng)根據(jù)需要更新位置.]
[Please, update the location according to your need.]
這篇關(guān)于在php中使用ffmpeg為視頻添加水印的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!