我正在尝试进行实时流式传输,视频循环播放,桌面声音和覆盖图像(替换文件时会更新)以及文本(替换文件时也会更新),但我似乎遇到了问题。非常感谢任何帮助:
VID=lol.mp4
STREAM_KEY=rmeow
TEXT=current.txt
COLOR="0xFFFFFF"
BCOLOR="0x000000"
ffmpeg -re -f alsa -i hw:Loopback,1,0 -framerate 10 -f image2 -loop 1 -i image.jpg -filter_complex overlay -stream_loop -1 -i $VID \
-c:v libx264 -preset veryfast -b:v 1984k -maxrate 1984k -bufsize 3968k -vf "scale=1280:-1,format=yuv420p" -g 20 -c:a aac -b:a 128k -ar 44100 \
-vf drawtext="fontfile=/usr/share/fonts/truetype/slant.ttf:bordercolor=$BCOLOR: borderw=1: fontcolor=$COLOR:textfile=$TEXT:reload=1:y=10:x=5:fontsize=38" \
-f flv "rtmp://live.restream.io/live/$STREAM_KEY" \
2> log_stream.txt
输出:
Only '-vf drawtext=fontfile=/usr/share/fonts/truetype/slant.ttf:bordercolor=0x000000: borderw=1: fontcolor=0xFFFFFF:textfile=current_song.txt:reload=1:y=10:x=5:fontsize=38' read, ignoring remaining -vf options: Use ',' to separate filters
Filtergraph 'drawtext=fontfile=/usr/share/fonts/truetype/slant.ttf:bordercolor=0x000000: borderw=1: fontcolor=0xFFFFFF:textfile=current_song.txt:reload=1:y=10:x=5:fontsize=38' was specified through the -vf/-af/-filter option for output stream 0:0, which is fed from a complex filtergraph.
-vf/-af/-filter and -filter_complex cannot be used together for the same stream.
答案1
ffmpeg -re -stream_loop -1 -i $VID -f image2 -re -framerate 10 -stream_loop -1 -i image.jpg -f alsa -i hw:Loopback,1,0 -filter_complex "overlay,scale=1280:-2,drawtext="fontfile=/usr/share/fonts/truetype/slant.ttf:bordercolor=$BCOLOR: borderw=1: fontcolor=$COLOR:textfile=$TEXT:reload=1:y=10:x=5:fontsize=38,format=yuv420p" \ -c:v libx264 -preset veryfast -b:v 1984k -maxrate 1984k -bufsize 3968k -g 20 -c:a aac -b:a 128k -ar 44100 \ -f flv "rtmp://live.restream.io/live/$STREAM_KEY"
-re
应放在非实时输入(如文件)前面,但不能放在麦克风或摄像头输入前面。- 所有过滤都应在一个过滤器图中执行,如上所示。请参阅https://ffmpeg.org/ffmpeg-filters.html#Filtergraph-description
- 为了更好地处理图像更新,如果在 ffmpeg 重新加载图像的同时更新图像,则使用
stream_loop
而不是可能会失败。loop