可以通过以下方式解决将文本叠加到视频中:
Play the video with OMXPlayer.
Use Pillow to create a transparent image with the text.
Save the image.
Show the image with omxiv in a higher render level than the layer used by OMXPlayer.
更快的方法是将图像作为 numpy 数组直接写入帧缓冲区 /dev/fb0(层 -127)并让 OMXPlayer 使用层 -128,但随后看不到任何文本。
#!/usr/bin/env python3
import subprocess
import time
import numpy
from PIL import Image, ImageDraw
subprocess.Popen('omxplayer -r -o hdmi video.mp4 --layer -128', shell = True)
time.sleep(3)
h, w = 1080, 1920
img = Image.new('RGBA', size=(w, h), color=(0, 0, 0, 150))
draw = ImageDraw.Draw(img)
s = 'Some text ...'
draw.text((0, 0), s, fill=(255,255,255,255))
fb = numpy.memmap('/dev/fb0', dtype='uint8',mode='w+', shape=(h,w,4))
fb[:] = numpy.array(img)
输出vcgencmd dispmanx_list
显示图像被 OMXPlayer 覆盖或阻止:
display:2 format:YUV_UV transform:0 layer:-128 1280x720 src:0,0,1280,720 dst:0,0,1920,1080 cost:1216 lbm:20480 (ignore lower layers)
display:2 format:UNKNOWN transform:100000 layer:-127 0x0 src:0,0,1920,253 dst:0,780,1920,253 cost:0 lbm:0
如果我在 OMXPlayer 未运行时将图像写入帧缓冲区,则输出为:
display:2 format:XRGB8888 transform:0 layer:-127 1920x1080 src:0,0,1920,1080 dst:0,0,1920,1080 cost:1156 lbm:0
谁能告诉我我做错了什么?