问题描述
将文本叠加到视频可以通过这种方式解决:
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,150))
draw = ImageDraw.Draw(img)
s = 'Some text ...'
draw.text((0,0),s,fill=(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,1280,720 dst:0,1920,1080 cost:1216 lbm:20480 (ignore lower layers)
display:2 format:UNKNowN transform:100000 layer:-127 0x0 src:0,253 dst:0,780,253 cost:0 lbm:0
如果我在 OMXPlayer 未运行时将图像写入帧缓冲区,则输出为:
display:2 format:XRGB8888 transform:0 layer:-127 1920x1080 src:0,1080 dst:0,1080 cost:1156 lbm:0
谁能告诉我我做错了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)