不对啊…… 好像也有些东西是用 side effects 做 fs IO 来着……
两个依赖 frames 流的调用,我岂不是要求值两遍??!
两个依赖 frames 流的调用,我岂不是要求值两遍??!
duangsuse::Echo
现在内存的问题解决了,这个图形处理算法可是有大问题……
[DuangSUSE@duangsuse]~/Projects/extract-subtitles/extract-subtitles% ./extract_subtitles.py -crop '(313,951)(1343,45)' --crop-debug --draw-plot SomethingNew.mp4
[Video Path] SomethingNew.mp4大胜利(截取部分良好输出)(迫真)
[Subtitle Language] eng
[Crop] [[313, 951], [1343, 45]]
[Threshold] None
[Filter Window] hamming
[Filter Window Size] 30
[Process Chunk Size] 300
[Frame Directory] frames
Extracting key frames...
[Video Props] (2837, 29, 1920, 1080)
158 How can something be sonice?
178 Yet so shocking, yet so nice.
321 How can something beso new?
466 Ohh,,.one two, three, the time has gone.
585 ~ “How an something be so cruel? co
1236 ‘What a beautiful way to fix all wrong'things.
1297 emake are olt1Uia LTO WC VmcOm Dar IMMV ge alsa dal at em
1324 ‘What a beautiful way to fix all wrong'things.
1383 Evolve future generations of work teamsy
1562 But tell me why's that fear of yours,
1633 ‘Cause you know it is going to work... keep ittup ~
1757 Let's start from now, stay tuned, you're half way through!
1956 Making something even smarter. azn
2079 Stab in statements screaming louder.
2119 How can something be so nice?
2261 How can something be so new? B bat
2334 Yet so known but yet...
2650 IT'S SOMETHING NEW
https://github.com/duangsuse/extract-subtitles/commit/7178011dd705e1e8c82fb14555a6f1bab6f63476
这个是最后一个仅在 OCR 的时候做 crop 的版本了(设计上应该是这样,减小资源占用),我发上来看看。
之所以还有发的价值,是因为新版虽然更快更省资源,但 OCR 的时候开 GUI 的话会有“卡”的感觉(处理过程本身就串行的)
之前的版本有意思,很大一部分原因是它把 crop 和 OCR 做在一起,这样 OCR 的时候也会更新 cropped frame(等等……新版马上也支持)
这个是最后一个仅在 OCR 的时候做 crop 的版本了(设计上应该是这样,减小资源占用),我发上来看看。
之所以还有发的价值,是因为新版虽然更快更省资源,但 OCR 的时候开 GUI 的话会有“卡”的感觉(处理过程本身就串行的)
之前的版本有意思,很大一部分原因是它把 crop 和 OCR 做在一起,这样 OCR 的时候也会更新 cropped frame(等等……新版马上也支持)
GitHub
Extract BasicCvProcess, modify cvtColor · duangsuse/extract-subtitles@7178011
Extract Subtitles From Video 视频字幕提取 帧间差分法识别关键帧 OCR识别 - duangsuse/extract-subtitles
158 How can something be so nice?
178 Yet so shocking, yet so nice.
321 How can something be so new?
403 Yet so known but yet so new?
466 Ohh, one two, three, the time has gone.
494 Problematic things undone.
585 How an something be so cruel?
640 Yet so warm but yet so cruel?
992 Try to find from a different sight,
1053 Get to choose where to look back,
1120 Resolve what others can't do for now...
1324 What a beautiful way to fix all wrong things.
1383 Evolve future generations of work teams.
1562 But tell me why's that fear of yours,
1633 'Cause you know it is going to work... (keep it up)
1757 Let's start from now, stay tuned, you're half way through!
1834 Break it, crash it, take it farther
1956 Making something even smarter.
1993 Do it, start it, make it happen,
2079 Stab in statements screaming louder.
2119 How can something be so nice?
2207 Yet so shocking, yet so nice.
2261 How can something be so new?
2334 Yet so known but yet...
2424 IT'S SOMETHING NEW
2650 IT'S SOMETHING NEW
178 Yet so shocking, yet so nice.
321 How can something be so new?
403 Yet so known but yet so new?
466 Ohh, one two, three, the time has gone.
494 Problematic things undone.
585 How an something be so cruel?
640 Yet so warm but yet so cruel?
992 Try to find from a different sight,
1053 Get to choose where to look back,
1120 Resolve what others can't do for now...
1324 What a beautiful way to fix all wrong things.
1383 Evolve future generations of work teams.
1562 But tell me why's that fear of yours,
1633 'Cause you know it is going to work... (keep it up)
1757 Let's start from now, stay tuned, you're half way through!
1834 Break it, crash it, take it farther
1956 Making something even smarter.
1993 Do it, start it, make it happen,
2079 Stab in statements screaming louder.
2119 How can something be so nice?
2207 Yet so shocking, yet so nice.
2261 How can something be so new?
2334 Yet so known but yet...
2424 IT'S SOMETHING NEW
2650 IT'S SOMETHING NEW
duangsuse::Echo
现在内存的问题解决了,这个图形处理算法可是有大问题……
https://github.com/duangsuse/extract-subtitles/blob/master/extract_subtitles.py#L55-L68
总结下,内存问题是用 chunked processing 解决的。
我简化了程序,梳理了下数据流,把合适的部分从靠
定义两个辅助 generator:
这段原程序就是之前会导致内存不够用的:
接下来就是重构依赖它的依赖操作了,实际上只需要一个子程序来利用
然后,
但是,这种操作应该怎么运行(并且拿回,准确的说是「拼接」回结果)呢 🤔
刚才有说,直接贴代码:
这就是我解决
总结下,内存问题是用 chunked processing 解决的。
我简化了程序,梳理了下数据流,把合适的部分从靠
list 改成了用 generator(接着可以 hack 的地方就多了)定义两个辅助 generator:
def chunked(n, xs):
while True:
try: #< must return when inner gen finished
first = next(xs)
except StopIteration: return
chunk = islice(xs, n)
yield chain((first,) , chunk)
def collect2(selector2, xs):
bs, cs = [], []
for x in xs:
b, c = selector2(x)
bs.append(b); cs.append(c)
return (bs, cs) 这段原程序就是之前会导致内存不够用的:
def solveFrameDifferences(self, cap: VideoCapture, crop: Rect, fold) -> Frame: #!generator
于是我移除了没损失信息量的对象,给它重构成 yield Frame(index, curr_frame, count) 的形式接下来就是重构依赖它的依赖操作了,实际上只需要一个子程序来利用
collect2 来部分(按chunk)地执行计算,我这里直接加在原来依赖 list 版以上函数的操作里: def ocrWithLocalMaxima(self, frames, on_new_subtitle) -> array: 然后,
frame_list, frame_diffs = collect2(lambda it: (it, it.value), frames)接下来的操作和以往无二,但再也不会内存不足了(只要你不关掉GC,相当于手动把视频切成 N 块再逐个操作,哈哈)。 🥳
self.onFrameList(frame_list) 但是,这种操作应该怎么运行(并且拿回,准确的说是「拼接」回结果)呢 🤔
刚才有说,直接贴代码:
processChunk = lambda it: self.ocrWithLocalMaxima(it, on_new_subtitle)
diff_array_parts = map(processChunk, chunked(self.chunk_size, frames))
diff_array = reduce(lambda a, b: concatenate(array([a, b])), diff_array_parts) 这就是我解决
opencv-python 处理内存不足问题的全部细节。 🙂 #Python #Learn #DIP #CVGitHub
duangsuse/extract-subtitles
Extract Subtitles From Video 视频字幕提取 帧间差分法识别关键帧 OCR识别 - duangsuse/extract-subtitles
duangsuse::Echo
https://github.com/duangsuse/extract-subtitles/blob/master/extract_subtitles.py#L55-L68 总结下,内存问题是用 chunked processing 解决的。 我简化了程序,梳理了下数据流,把合适的部分从靠 list 改成了用 generator(接着可以 hack 的地方就多了) 定义两个辅助 generator: def chunked(n, xs): while True: try: #< must return…
我正在考虑添加一个能给『字幕分时段在不同位置出现的视频打轴』的脚本或者 Qt 应用 🤔
打完轴以后,就变成一个
还有一个能把
第一个应用有一个关键视图/交互需要实现:图像选区框
我已经想好了怎么同时支持绘制和事件监听(整个给做成 Widget,然后用 move 和 resize),只需要先学学 Qt 基础 🤔
打完轴以后,就变成一个
TreeSet ,然后我可以 findMaxLT 来取到最近的 crop 区域还有一个能把
extract_subtitles 输出自动检查合并到 ASS 这种 subtitles 格式的脚本,依然可以用到 zipWithNext 第一个应用有一个关键视图/交互需要实现:图像选区框
我已经想好了怎么同时支持绘制和事件监听(整个给做成 Widget,然后用 move 和 resize),只需要先学学 Qt 基础 🤔