Commit cd14ab0e authored by xuanweiace's avatar xuanweiace

mod 起始时间 保留三位小数

add 防止检测时银报错而导致原文件丢失
parent f9d50d99
......@@ -265,7 +265,7 @@ def process_video(video_path: str, begin: float, end: float, book_path: str, she
# 判断当前是否有字幕需要被保存下来
if end_time < start_time:
# write_to_sheet(book_path, sheet_name, [round(start_time, 2), round(end, 2), lastSubTitle, ''])
add_to_list(mainWindow, "字幕", [round(start_time, 2), round(end, 2), lastSubTitle, ''])
add_to_list(mainWindow, "字幕", [round(start_time, 3), round(end, 3), lastSubTitle, ''])
break
# 每秒取4帧画面左右
if cnt % int(fps / 4) == 0:
......@@ -296,7 +296,7 @@ def process_video(video_path: str, begin: float, end: float, book_path: str, she
print(start_time, end_time, lastSubTitle)
# write_to_sheet(book_path, sheet_name, [round(start_time, 2), round(end_time, 2), lastSubTitle, ''])
add_to_list(mainWindow, "字幕", [round(start_time, 2), round(end_time, 2), lastSubTitle, ''])
add_to_list(mainWindow, "字幕", [round(start_time, 3), round(end_time, 3), lastSubTitle, ''])
elif lastSubTitle is not None and subTitle is not None:
# 两句话连在一起,但是两句话不一样
if string_similar(lastSubTitle, subTitle) < 0.7:
......@@ -310,7 +310,7 @@ def process_video(video_path: str, begin: float, end: float, book_path: str, she
add_to_list(mainWindow, "旁白", ['', '', '', '插入旁白,推荐字数为%d' % recommend_lens])
print(start_time, end_time, lastSubTitle)
# write_to_sheet(book_path, sheet_name, [round(start_time, 2), round(end_time, 2), lastSubTitle, ''])
add_to_list(mainWindow, "字幕", [round(start_time, 2), round(end_time, 2), lastSubTitle, ''])
add_to_list(mainWindow, "字幕", [round(start_time, 3), round(end_time, 3), lastSubTitle, ''])
start_time = end_time
else:
lastSubTitle = subTitle if len(subTitle) > len(lastSubTitle) else lastSubTitle
......@@ -355,8 +355,8 @@ def detect_with_ocr(video_path: str, book_path: str, start_time: float, end_time
print("start and end time:", start_time, end_time)
if state is None:
state = [None]
if os.path.exists(book_path):
os.remove(book_path)
# if os.path.exists(book_path):
# os.remove(book_path)
book_name_xlsx = book_path
sheet_name_xlsx = "旁白插入位置建议"
......@@ -372,9 +372,9 @@ def detect_with_ocr(video_path: str, book_path: str, start_time: float, end_time
context.detected = True
# 获取并构建输出信息
table_head = [["起始时间", "终止时间", "字幕", '建议', '解说脚本']]
# table_head = [["起始时间", "终止时间", "字幕", '建议', '解说脚本']]
# print("create sheet at time: ", datetime.datetime.now())
create_sheet(book_name_xlsx, sheet_name_xlsx, table_head)
# create_sheet(book_name_xlsx, sheet_name_xlsx, table_head)
# print("process the total video at time: ", datetime.datetime.now())
process_video(video_path, start_time, end_time, book_name_xlsx, sheet_name_xlsx, state, mainWindow)
......
......@@ -1179,7 +1179,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.prompt_dialog.show_with_msg("插入失败!未检测到视频或工程!")
return
print("self.player.position()", self.player.position())
cur_time = round(self.player.position()/1000, 2)
cur_time = round(self.player.position()/1000, 3)
idx = self.calculate_element_row(cur_time)
print("[insert_aside_from_now_slot] idx=", idx)
# 其实end_time目前是没啥用的,可以删掉了
......
......@@ -365,10 +365,12 @@ class ProjectContext:
def save_excel_to_to_path(all_element, new_excel_path, header, excel_sheet_name):
def save_excel_thread(all_element, new_excel_path, header, excel_sheet_name):
backup_path = None
if os.path.exists(new_excel_path):
os.remove(new_excel_path)
import time
backup_path = os.path.dirname(new_excel_path) + "/tmp_"+str(time.time())+".xlsx"
# os.remove(new_excel_path)
os.rename(new_excel_path, backup_path)
try:
create_sheet(new_excel_path, "旁白插入位置建议", [header])
# for element in all_element:
......@@ -379,9 +381,16 @@ def save_excel_to_to_path(all_element, new_excel_path, header, excel_sheet_name)
traceback.format_exception(*sys.exc_info()))
print("保存表格到路径[%s]失败"%(new_excel_path))
print(exception_info)
if os.path.exists(new_excel_path):
os.remove(new_excel_path)
if backup_path != None:
os.rename(backup_path,new_excel_path)
return exception_info
print("保存表格到路径[%s]成功"%(new_excel_path))
else:
print("backup_path::::", backup_path)
# if backup_path != None:
# os.remove(backup_path)
print("保存表格到路径[%s]成功"%(new_excel_path))
return None
t = RunThread(funcName=save_excel_thread,
......
......@@ -125,12 +125,12 @@ class Operation_Dialog(QDialog, Ui_Dialog):
# 校验起始时间、结束时间
start_time_f, end_time_f = 0.0, 0.0
try:
print("start_time_f:", self.timeEdit.time().toString("hh:mm:ss.qq"))
print("start_time_f:", self.timeEdit.time().toString("hh:mm:ss.zzz"))
start_time_f = float(
utils.trans_to_seconds(self.timeEdit.time().toString("hh:mm:ss:qq")))
utils.trans_to_seconds(self.timeEdit.time().toString("hh:mm:ss.zzz")))
if self.comboBox.currentText() == "字幕":
end_time_f = float(
utils.trans_to_seconds(self.timeEdit_2.time().toString("hh:mm:ss")))
utils.trans_to_seconds(self.timeEdit_2.time().toString("hh:mm.zzz")))
assert start_time_f < end_time_f
if row_number < rowCount:
# 要求结束时间在下一行的起始时间前面,对增加和修改都适用
......
......@@ -34,7 +34,7 @@ def trans_to_seconds(timePoint: str) -> float:
def transfer_second_to_time(sec: str) -> str:
"""
输入xxxx.xxx秒,输出xx:xx:xx.xx的格式(输出不一定有小数点)
输入xxxx.xxx秒,输出xx:xx:xx.xxx的格式
"""
duration = int(float(sec))
hour = int(duration/3600)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment