关于绘制提速…… 一般最大的想法就是 OpenCV-Python only (no PIL) 或者干脆 C++ 重写好了
参数也就 font(size), scale, spacing / calc_draw_color(key_color, key_res)
之前想了一种按行而非字符绘制文本的思路,可是发现根本不可行——排除 horizontal 间距没法自定义不提,不同字符不同颜色没法做到!
缓存什么的,估计 pillow 或者 freetype 什么的也是有做的(当然,freetype 只是一个栅格化库而已啦)
参数也就 font(size), scale, spacing / calc_draw_color(key_color, key_res)
之前想了一种按行而非字符绘制文本的思路,可是发现根本不可行——排除 horizontal 间距没法自定义不提,不同字符不同颜色没法做到!
缓存什么的,估计 pillow 或者 freetype 什么的也是有做的(当然,freetype 只是一个栅格化库而已啦)
Forwarded from duangsuse Throws
This media is not supported in your browser
VIEW IN TELEGRAM
草死了,不会用 Kdenlive,不能 crop 刚才想起来可以用 mask 去 subtract,但没精力就先发了
ParserKt 的 Feed ( FeedError.onError, FeedTerminate.isEnd )
关系式的 six primitives (state, variable, introduce, eq, both, either)
关系式的 six primitives (state, variable, introduce, eq, both, either)
https://t.me/dsuset/7517 这是字幕提取的数据源
然后那个无水印原版的…… 忘记是 #bilibili 哪个 av号 的了
~/Projects/extract-subtitles% ../MontagePY/montage1_c.py -font /usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc lxhbb.mp4 -key-color ffffff --subtitle lxh.srt -font-size 16 -spacing :1,1 --subtitle-placeholder 呜 --key-thres 0
../MontagePY/montage1_c.py -font /usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc lxhbb.mp4 -key-color ffffff --subtitle lxh.srt -font-size 16 -spacing :1,1 --subtitle-placeholder 呜 --key-thres 1
后期使用 Kdenlive 剪辑渲染,主要是混合了个声音。
然后那个无水印原版的…… 忘记是 #bilibili 哪个 av号 的了
~/Projects/extract-subtitles% ../MontagePY/montage1_c.py -font /usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc lxhbb.mp4 -key-color ffffff --subtitle lxh.srt -font-size 16 -spacing :1,1 --subtitle-placeholder 呜 --key-thres 0
16px, (255, 255, 255) ±0 (1, 1)mv lxh_mon.avi lxh_stop_mon.avi
29.96969696969697fps*3592 720x540
84 time=5.935s 14.154fps
186 time=13.305s 13.979fps
204 time=14.564s 14.007fps
1514 time=112.642s 13.441fps
../MontagePY/montage1_c.py -font /usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc lxhbb.mp4 -key-color ffffff --subtitle lxh.srt -font-size 16 -spacing :1,1 --subtitle-placeholder 呜 --key-thres 1
16px, (255, 255, 255) ±1 (1, 1)
29.96969696969697fps*3592 720x540
166 time=11.506s 14.427fps
2563 time=180.191s 14.224fps
后期使用 Kdenlive 剪辑渲染,主要是混合了个声音。
Telegram
duangsuse Throws
https://www.bilibili.com/video/av57816577 😭 montage_1c 现在也是只支持 srt 字幕格式(虽然它也就是要一个抽象的 (start, end] content 而已)
我最好还是用 extract-subtitles 去配套它…… 所以只能找来这个有内嵌字幕的了
danmaku2ass 都没用
我最好还是用 extract-subtitles 去配套它…… 所以只能找来这个有内嵌字幕的了
danmaku2ass 都没用
This media is not supported in your browser
VIEW IN TELEGRAM
这个是 stop montage,就是每个 subtitle 排版不变化的(传递
--key-thres 0 每个色块都必须绘制导致的) 没加声音因为不是成品,是替补剪辑素材由于绘制蒙太奇图时
#FFFFFF 颜色会和小黑自己的颜色冲突导致小黑无 text fill 所以手动剪辑换边框颜色,直接用 Kdenlive 剪的(第一张),第二张是实验照。This media is not supported in your browser
VIEW IN TELEGRAM
这个是原版的白色背景替换版本
duangsuse::Echo
这个是 stop montage,就是每个 subtitle 排版不变化的(传递 --key-thres 0 每个色块都必须绘制导致的) 没加声音因为不是成品,是替补剪辑素材
大概说一下必须要啥接口啊…… (不止这个项目,是我最近用过的 API,emmm) #Python
Image 方面:
ImageDraw:
然后对 #CV 来说, fps, n_frames, width, height 是必须的
这些 API,OpenCV 不支持 unicode 字体,但可以写 C++ 扩展,用 freetype 画啊
from PIL import Image, ImageDraw, ImageFont Image 方面:
Image.open(path), Image.new(mode, size, fill)骚操作:
size, width, height
getpixel, putpixel
mode, Image.getmodebands
resize, crop, paste
palette
offset((x,y))
getchannel("R")
histogram()
getextrema() 可以算通道极值ImageDraw:
ImageFont.truetype(path)
ImageDraw.Draw(img) ImageDraw.text(pos, text, font, fill) 然后对 #CV 来说, fps, n_frames, width, height 是必须的
def cv2VideoInfo(cap):剩下
props = [cv2.CAP_PROP_FRAME_COUNT, cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT]
return (cap.get(cv2.CAP_PROP_FPS),) + tuple(int(cap.get(p)) for p in props)
VideoCapture.read, VideoWriter.write 就好了这些 API,OpenCV 不支持 unicode 字体,但可以写 C++ 扩展,用 freetype 画啊
java.awt.image.BufferedImage 和 java.awt.Graphics 也是支持绘制文字的(但不能在调用里直接自定义字体)Forwarded from duangsues.is_a? SaltedFish
def channelHistogram(img):#Python #code #CV 🤔
n_channels = Pillow.getmodebands(img.mode)
hist = img.histogram()
return tuple(hist[i:i+256] for i in range(0, n_channels*256, 256))
def imagePixels(img):
for y in range(0, img.height):
for x in range(0, img.width):
yield img.getpixel((x, y))
def count(xs): return sum(map(lambda _: 1, xs))
新版
vcat_subtitle_imgs.py 里我们支持了 #FF0000 红色标记划掉字幕的特性import os
def defaultOnAreaWrote(path, img, mark_range=range(10, 1000), show=lambda n, r: n > r.stop):
(r,_,_) = channelHistogram(img)[0:3]
if r[0xFF] > 0:
n_marks = count(filter(lambda it: it[0:3] == (0xFF,0,0), imagePixels(img)))
if n_marks not in mark_range: return
if show(n_marks, mark_range): img.show(title = f"Removed {path}")
print(f"Removing {path} (redmarks {n_marks})")
os.remove(path)