Skip to content

Instantly share code, notes, and snippets.

@mokurin000
Last active March 12, 2023 01:14
Show Gist options
  • Select an option

  • Save mokurin000/83da3baca839d768cb1813c4ab28ae01 to your computer and use it in GitHub Desktop.

Select an option

Save mokurin000/83da3baca839d768cb1813c4ab28ae01 to your computer and use it in GitHub Desktop.
使用ffmpeg + PaddleOCR 自动生成月月妈视频第n个兰那多对应的时间戳

首先下载可爱月月的兰那多全收集视频

$ ls
820355733-1-208.mp4

然后导出帧:

width=171
height=144
x=1580
y=133
export_frame_rate=1
ffmpeg -t 3850 -i 820355733-1-208.mp4 -filter:v "crop=$width:$height:$x:$y" -r $export_frame_rate frames/%04d.webp 

其中 3850是75(最后一个兰那多开始)的最后时间

为了减少ocr负载,这里我使用的导出帧率是1(1s一张)

为了方便处理结果,从python调用PaddleOCR

cd frames
python ../ocr.py | grep -v ppocr > ocr.log
from paddleocr import PaddleOCR, draw_ocr
import os
ocr = PaddleOCR(lang='ch')
png_files = (f for f in os.listdir('.') if f.endswith('.png'))
last_result = -1
count = 0
ITEM_PER_LINE=4
for png in png_files:
time_sec = int(png.rstrip(".png")) # 如果你用了 -r 0.5 这里需要*2
result = ocr.ocr(png, det=False)
try:
result = int(result[0][0][0])
time_min = time_sec // 60
time_sec = time_sec % 60
if result == last_result+1:
count += 1
last_result += 1
print("%02d" % time_min, ":", "%02d" % time_sec, " ", "%02d" % 1+result, sep='', end='')
if count == ITEM_PER_LINE:
count = 0
print()
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment