php - 我想使用 ffmpeg 将图像用作 drawtext 视频的背景

标签 php ffmpeg

目前,我能够使用 ffmpeg 创建视频,使用 drawtext 过滤器在黑色背景上绘制文本现在保留对我来说似乎很难的一件事,我认为这会很容易,直到我发现我做错了。我想使用图像作为 drawtext 过滤器的背景。即我想使用图像作为视频的背景,而不是使用背景颜色或视频背景。请有人带我完成这是我的代码`

echo shell_exec('ffmpeg -f lavfi -i color=color=black -vf drawtext="textfile=text.txt:expansion=normal:fontfile=FreeSerif.otf: y=h-line_h-20:x=-100*t: fontcolor=white: fontsize=50" -t '.$words_count.' textover09.mp4 -report'); `



ffmpeg started on 2018-01-07 at 22:53:03
Report written to "ffmpeg-20180107-225303.log"
Command line:
ffmpeg -loop 1 -i elena.jpg -vf "drawtext=textfile=text.txt:expansion=normal:fontfile=FreeSerif.otf: y=h-line_h-20:x=-100*t: fontcolor=white: fontsize=50" -t 46.2 textover09.mp4 -report
ffmpeg version git-2017-12-28-be4dfbf Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-18)
  configuration: --prefix=/usr/local/ffmpeg --extra-cflags=-I/usr/local/ffmpeg/include --extra-ldflags=-L/usr/local/ffmpeg/lib --bindir=/usr/local/bin --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libx264 --enable-libtheora --enable-filter=drawtext --enable-libfreetype
  libavutil      56.  7.100 / 56.  7.100
  libavcodec     58.  9.100 / 58.  9.100
  libavformat    58.  3.100 / 58.  3.100
  libavdevice    58.  0.100 / 58.  0.100
  libavfilter     7.  8.100 /  7.  8.100
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
Splitting the commandline.
Reading option '-loop' ... matched as AVOption 'loop' with argument '1'.
Reading option '-i' ... matched as input url with argument 'elena.jpg'.
Reading option '-vf' ... matched as option 'vf' (set video filters) with argument 'drawtext=textfile=text.txt:expansion=normal:fontfile=FreeSerif.otf: y=h-line_h-20:x=-100*t: fontcolor=white: fontsize=50'.
Reading option '-t' ... matched as option 't' (record or transcode "duration" seconds of audio/video) with argument '46.2'.
Reading option 'textover09.mp4' ... matched as output url.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url elena.jpg.
Successfully parsed a group of options.
Opening an input file: elena.jpg.
[NULL @ 0x2c1fe80] Opening 'elena.jpg' for reading
[file @ 0x2c207c0] Setting default whitelist 'file,crypto'
[image2 @ 0x2c1fe80] Format image2 probed with size=2048 and score=50
[image2 @ 0x2c1fe80] Before avformat_find_stream_info() pos: 0 bytes read:32768 seeks:0 nb_streams:1
[image2 @ 0x2c1fe80] Opening 'elena.jpg' for reading
[AVIOContext @ 0x2c21f80] Statistics: 3871771 bytes read, 0 seeks
[mjpeg @ 0x2c21940] marker=d8 avail_size_in_buf=3871769
[mjpeg @ 0x2c21940] marker parser used 0 bytes (0 bits)
[mjpeg @ 0x2c21940] marker=e0 avail_size_in_buf=3871767
[mjpeg @ 0x2c21940] marker parser used 16 bytes (128 bits)
[mjpeg @ 0x2c21940] marker=e2 avail_size_in_buf=3871749
[mjpeg @ 0x2c21940] marker parser used 3160 bytes (25280 bits)
[mjpeg @ 0x2c21940] marker=db avail_size_in_buf=3868587
[mjpeg @ 0x2c21940] index=0
[mjpeg @ 0x2c21940] qscale[0]: 2
[mjpeg @ 0x2c21940] index=1
[mjpeg @ 0x2c21940] qscale[1]: 2
[mjpeg @ 0x2c21940] marker parser used 132 bytes (1056 bits)
[mjpeg @ 0x2c21940] marker=c0 avail_size_in_buf=3868453
[mjpeg @ 0x2c21940] Changing bps from 0 to 8
[mjpeg @ 0x2c21940] sof0: picture: 5616x3744
[mjpeg @ 0x2c21940] component 0 2:2 id: 0 quant:0
[mjpeg @ 0x2c21940] component 1 1:1 id: 1 quant:1
[mjpeg @ 0x2c21940] component 2 1:1 id: 2 quant:1
[mjpeg @ 0x2c21940] pix fmt id 22111100
[mjpeg @ 0x2c21940] marker parser used 17 bytes (136 bits)
[mjpeg @ 0x2c21940] marker=c4 avail_size_in_buf=3868434
[mjpeg @ 0x2c21940] marker parser used 0 bytes (0 bits)
[mjpeg @ 0x2c21940] escaping removed 6222 bytes
[mjpeg @ 0x2c21940] marker=da avail_size_in_buf=3868014
[mjpeg @ 0x2c21940] marker parser used 3861792 bytes (30894336 bits)
[mjpeg @ 0x2c21940] marker=d9 avail_size_in_buf=0
[mjpeg @ 0x2c22540] marker parser used 132 bytes (1056 bits)
[mjpeg @ 0x2c22540] marker=c0 avail_size_in_buf=3868453
[mjpeg @ 0x2c22540] sof0: picture: 5616x3744
[mjpeg @ 0x2c22540] component 0 2:2 id: 0 quant:0
[mjpeg @ 0x2c22540] component 1 1:1 id: 1 quant:1
[libx264 @ 0x2c24c40] i16 v,h,dc,p: 40% 53%  4%  3%
[libx264 @ 0x2c24c40] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 11% 10% 27%  7%  9%  8%  8%  9% 11%
[libx264 @ 0x2c24c40] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 12% 11%  6%  9% 11%  7%  9%  6%
[libx264 @ 0x2c24c40] i8c dc,h,v,p: 53% 17% 21%  8%
[libx264 @ 0x2c24c40] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x2c24c40] ref P L0: 56.3%  9.9% 21.1% 12.8%
[libx264 @ 0x2c24c40] ref B L0: 74.5% 22.4%  3.1%
[libx264 @ 0x2c24c40] ref B L1: 98.3%  1.7%
[libx264 @ 0x2c24c40] kb/s:4673.55
[AVIOContext @ 0x2c28ac0] Statistics: 32768 bytes read, 0 seeks

最佳答案

利用

ffmpeg -loop 1 -i image -vf scale=-2:1080,drawtext="textfile=text.txt:expansion=normal:fontfile=FreeSerif.otf: y=h-line_h-20:x=-100*t: fontcolor=white: fontsize=50" -pix_fmt yuv420p -t '.$words_count.' -movflags +faststart textover09.mp4

关于php - 我想使用 ffmpeg 将图像用作 drawtext 视频的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48139025/

相关文章:

video - ffmpeg 将多个文件从 avi dv 视频 (dvsd) 转换为 avi h.264 + mp3(mp4)

ffmpeg 流式传输(mpegts 与 rtmp)错误

FFMPEG 剪切视频并添加水印

php - 将cookie 设置为空值不起作用

PHP CodeIgniter-combobox 值未在数据库中更新

php - 防止一键式 Laravel 多次提交

php - 在单个语句中创建和调用匿名函数

ffmpeg - ffmpeg 错误 "Prediction is not allowed in AAC-LC"是什么意思?

video - FFMPEG,播放器在编码后播放生涩的视频

php - 如何将 Behat 与 PHPStorm/其他 IDE 集成