Skip to content

Commit

Permalink
修复PROP_MSEC不靠谱的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
YaoFANGUK committed Apr 12, 2022
1 parent 6d34de5 commit a253228
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,4 @@ $RECYCLE.BIN/
/dylib/
/settings.ini
/test.py
/test2.py
11 changes: 9 additions & 2 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@ def extract_frame_by_fps(self):

duration_ms = (self.frame_count / self.fps) * 1000
while self.video_cap.isOpened():
total_ms = self.video_cap.get(cv2.CAP_PROP_POS_MSEC)
ret, frame = self.video_cap.read()
# 如果读取视频帧失败(视频读到最后一帧)
if not ret:
break
# 读取视频帧成功
else:
total_ms = self.video_cap.get(cv2.CAP_PROP_POS_MSEC)
if total_ms <= 0:
total_ms = self._frameno_to_milliseconds(self.video_cap.get(cv2.CAP_PROP_POS_FRAMES))
frame_no += 1
self.subtitle_ocr_queue.put((total_ms, duration_ms, frame_no, None, None, self.subtitle_area))
# 跳过剩下的帧
Expand Down Expand Up @@ -225,11 +227,13 @@ def extract_frame_by_det(self):
compare_ocr_result_cache = {}
tbar = tqdm(total=int(self.frame_count), unit='f', position=0, file=sys.__stdout__)
while self.video_cap.isOpened():
total_ms = self.video_cap.get(cv2.CAP_PROP_POS_MSEC)
ret, frame = self.video_cap.read()
# 如果读取视频帧失败(视频读到最后一帧)
if not ret:
break
total_ms = self.video_cap.get(cv2.CAP_PROP_POS_MSEC)
if total_ms <= 0:
total_ms = self._frameno_to_milliseconds(self.video_cap.get(cv2.CAP_PROP_POS_FRAMES))
# 读取视频帧成功
frame_no += 1
dt_boxes, elapse = self.sub_detector.detect_subtitle(frame)
Expand Down Expand Up @@ -654,6 +658,9 @@ def _frame_to_timecode(self, frame_no):
int(frame_no / self.fps % 60),
int(frame_no % self.fps))

def _frameno_to_milliseconds(self, frame_no):
return float(int(frame_no / self.fps * 1000))

def _remove_duplicate_subtitle(self):
"""
读取原始的raw txt,去除重复行,返回去除了重复后的字幕列表
Expand Down

0 comments on commit a253228

Please sign in to comment.