duangsuse::Echo
717 subscribers
4.26K photos
130 videos
583 files
6.47K links
import this:
美而不丑、明而不暗、短而不凡、长而不乱,扁平不宽,读而后码,行之天下,勿托地上天国。
异常勿吞,难过勿过,叹一真理。效率是很重要,盲目最是低效。
简明是可靠的先验,不是可靠的祭品。
知其变,守其恒,为天下式;穷其变,知不穷,得地上势。知变守恒却穷变知新,我认真理,我不认真。

技术相干订阅~
另外有 throws 闲杂频道 @dsuset
转载频道 @dsusep
极小可能会有批评zf的消息 如有不适可退出
suse小站(面向运气编程): https://WOJS.org/#/
Download Telegram
关于绘制提速…… 一般最大的想法就是 OpenCV-Python only (no PIL) 或者干脆 C++ 重写好了
参数也就 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)
就是这样,制造一个蒙板然后像素相减
草,原来 Kdenlive 支持 crop 啊,只不过是在特效里…… 原来合成和特效还不一样! 我之前还以为 Kdenlive 的特效不能应用多个……
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
16px, (255, 255, 255) ±0 (1, 1)
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
mv lxh_mon.avi lxh_stop_mon.avi
../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 剪辑渲染,主要是混合了个声音。
This media is not supported in your browser
VIEW IN TELEGRAM
这个是 stop montage,就是每个 subtitle 排版不变化的(传递 --key-thres 0 每个色块都必须绘制导致的) 没加声音因为不是成品,是替补剪辑素材
由于绘制蒙太奇图时 #FFFFFF 颜色会和小黑自己的颜色冲突导致小黑无 text fill 所以手动剪辑换边框颜色,直接用 Kdenlive 剪的(第一张),第二张是实验照。
luoxioaheimon.kdenlive
51.2 KB
好了,做完了 #media #acg
Media is too big
VIEW IN TELEGRAM
#video #acg 《罗小黑战记》番外《晚安喵》中文彩色字符画版剪辑 [相关信息]
lxh.srt
1.1 KB
这个是 montage1_c.py 字幕 (--subtitle)
This media is not supported in your browser
VIEW IN TELEGRAM
这个是原版的白色背景替换版本
duangsuse::Echo
这个是 stop montage,就是每个 subtitle 排版不变化的(传递 --key-thres 0 每个色块都必须绘制导致的) 没加声音因为不是成品,是替补剪辑素材
大概说一下必须要啥接口啊…… (不止这个项目,是我最近用过的 API,emmm) #Python
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.BufferedImagejava.awt.Graphics 也是支持绘制文字的(但不能在调用里直接自定义字体)
def channelHistogram(img):
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))
#Python #code #CV 🤔
新版 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)
duangsuse::Echo
新版 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]…
对于非常模糊的视频,可以先检测关键帧导出,然后再利用 vcat_subtitle_imgs.py 进行合并化编辑去掉重复的关键帧,最后 --only-images 添加文字序列即可,这个过程依赖 bash 一类支持 glob 的 shell,如果是 windows 可以用 bash for windows 之类的。
b.png
1.2 MB
./vcat_subtitle_imgs.py unpack a.png
./vcat_subtitle_imgs.py b.png frames/subtitle_*.png
🌝 最后可以得出这么一个结果
西方的法制_字幕.txt
2.8 KB
🌚我居然把一个半透明质量这么差的字幕提取出来了…… 那些代码改得真不容易