Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
accessibility_movie_2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵心治
accessibility_movie_2
Commits
cd14ab0e
Commit
cd14ab0e
authored
Nov 16, 2022
by
xuanweiace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mod 起始时间 保留三位小数
add 防止检测时银报错而导致原文件丢失
parent
f9d50d99
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
16 deletions
+25
-16
detect_with_ocr.py
detect_with_ocr.py
+7
-7
main_window.py
main_window.py
+1
-1
management.py
management.py
+13
-4
operation_dialog.py
operation_dialog.py
+3
-3
utils.py
utils.py
+1
-1
No files found.
detect_with_ocr.py
View file @
cd14ab0e
...
@@ -265,7 +265,7 @@ def process_video(video_path: str, begin: float, end: float, book_path: str, she
...
@@ -265,7 +265,7 @@ def process_video(video_path: str, begin: float, end: float, book_path: str, she
# 判断当前是否有字幕需要被保存下来
# 判断当前是否有字幕需要被保存下来
if
end_time
<
start_time
:
if
end_time
<
start_time
:
# write_to_sheet(book_path, sheet_name, [round(start_time, 2), round(end, 2), lastSubTitle, ''])
# 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
break
# 每秒取4帧画面左右
# 每秒取4帧画面左右
if
cnt
%
int
(
fps
/
4
)
==
0
:
if
cnt
%
int
(
fps
/
4
)
==
0
:
...
@@ -296,7 +296,7 @@ def process_video(video_path: str, begin: float, end: float, book_path: str, she
...
@@ -296,7 +296,7 @@ def process_video(video_path: str, begin: float, end: float, book_path: str, she
print
(
start_time
,
end_time
,
lastSubTitle
)
print
(
start_time
,
end_time
,
lastSubTitle
)
# write_to_sheet(book_path, sheet_name, [round(start_time, 2), round(end_time, 2), 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
:
elif
lastSubTitle
is
not
None
and
subTitle
is
not
None
:
# 两句话连在一起,但是两句话不一样
# 两句话连在一起,但是两句话不一样
if
string_similar
(
lastSubTitle
,
subTitle
)
<
0.7
:
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
...
@@ -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
])
add_to_list
(
mainWindow
,
"旁白"
,
[
''
,
''
,
''
,
'插入旁白,推荐字数为
%
d'
%
recommend_lens
])
print
(
start_time
,
end_time
,
lastSubTitle
)
print
(
start_time
,
end_time
,
lastSubTitle
)
# write_to_sheet(book_path, sheet_name, [round(start_time, 2), round(end_time, 2), 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
start_time
=
end_time
else
:
else
:
lastSubTitle
=
subTitle
if
len
(
subTitle
)
>
len
(
lastSubTitle
)
else
lastSubTitle
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
...
@@ -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
)
print
(
"start and end time:"
,
start_time
,
end_time
)
if
state
is
None
:
if
state
is
None
:
state
=
[
None
]
state
=
[
None
]
if
os
.
path
.
exists
(
book_path
):
#
if os.path.exists(book_path):
os
.
remove
(
book_path
)
#
os.remove(book_path)
book_name_xlsx
=
book_path
book_name_xlsx
=
book_path
sheet_name_xlsx
=
"旁白插入位置建议"
sheet_name_xlsx
=
"旁白插入位置建议"
...
@@ -372,9 +372,9 @@ def detect_with_ocr(video_path: str, book_path: str, start_time: float, end_time
...
@@ -372,9 +372,9 @@ def detect_with_ocr(video_path: str, book_path: str, start_time: float, end_time
context
.
detected
=
True
context
.
detected
=
True
# 获取并构建输出信息
# 获取并构建输出信息
table_head
=
[[
"起始时间"
,
"终止时间"
,
"字幕"
,
'建议'
,
'解说脚本'
]]
#
table_head = [["起始时间", "终止时间", "字幕", '建议', '解说脚本']]
# print("create sheet at time: ", datetime.datetime.now())
# 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())
# 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
)
process_video
(
video_path
,
start_time
,
end_time
,
book_name_xlsx
,
sheet_name_xlsx
,
state
,
mainWindow
)
...
...
main_window.py
View file @
cd14ab0e
...
@@ -1179,7 +1179,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
...
@@ -1179,7 +1179,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self
.
prompt_dialog
.
show_with_msg
(
"插入失败!未检测到视频或工程!"
)
self
.
prompt_dialog
.
show_with_msg
(
"插入失败!未检测到视频或工程!"
)
return
return
print
(
"self.player.position()"
,
self
.
player
.
position
())
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
)
idx
=
self
.
calculate_element_row
(
cur_time
)
print
(
"[insert_aside_from_now_slot] idx="
,
idx
)
print
(
"[insert_aside_from_now_slot] idx="
,
idx
)
# 其实end_time目前是没啥用的,可以删掉了
# 其实end_time目前是没啥用的,可以删掉了
...
...
management.py
View file @
cd14ab0e
...
@@ -365,10 +365,12 @@ class ProjectContext:
...
@@ -365,10 +365,12 @@ class ProjectContext:
def
save_excel_to_to_path
(
all_element
,
new_excel_path
,
header
,
excel_sheet_name
):
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
):
def
save_excel_thread
(
all_element
,
new_excel_path
,
header
,
excel_sheet_name
):
backup_path
=
None
if
os
.
path
.
exists
(
new_excel_path
):
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
:
try
:
create_sheet
(
new_excel_path
,
"旁白插入位置建议"
,
[
header
])
create_sheet
(
new_excel_path
,
"旁白插入位置建议"
,
[
header
])
# for element in all_element:
# for element in all_element:
...
@@ -379,8 +381,15 @@ def save_excel_to_to_path(all_element, new_excel_path, header, excel_sheet_name)
...
@@ -379,8 +381,15 @@ def save_excel_to_to_path(all_element, new_excel_path, header, excel_sheet_name)
traceback
.
format_exception
(
*
sys
.
exc_info
()))
traceback
.
format_exception
(
*
sys
.
exc_info
()))
print
(
"保存表格到路径[
%
s]失败"
%
(
new_excel_path
))
print
(
"保存表格到路径[
%
s]失败"
%
(
new_excel_path
))
print
(
exception_info
)
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
return
exception_info
else
:
print
(
"backup_path::::"
,
backup_path
)
# if backup_path != None:
# os.remove(backup_path)
print
(
"保存表格到路径[
%
s]成功"
%
(
new_excel_path
))
print
(
"保存表格到路径[
%
s]成功"
%
(
new_excel_path
))
return
None
return
None
...
...
operation_dialog.py
View file @
cd14ab0e
...
@@ -125,12 +125,12 @@ class Operation_Dialog(QDialog, Ui_Dialog):
...
@@ -125,12 +125,12 @@ class Operation_Dialog(QDialog, Ui_Dialog):
# 校验起始时间、结束时间
# 校验起始时间、结束时间
start_time_f
,
end_time_f
=
0.0
,
0.0
start_time_f
,
end_time_f
=
0.0
,
0.0
try
:
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
(
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
()
==
"字幕"
:
if
self
.
comboBox
.
currentText
()
==
"字幕"
:
end_time_f
=
float
(
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
assert
start_time_f
<
end_time_f
if
row_number
<
rowCount
:
if
row_number
<
rowCount
:
# 要求结束时间在下一行的起始时间前面,对增加和修改都适用
# 要求结束时间在下一行的起始时间前面,对增加和修改都适用
...
...
utils.py
View file @
cd14ab0e
...
@@ -34,7 +34,7 @@ def trans_to_seconds(timePoint: str) -> float:
...
@@ -34,7 +34,7 @@ def trans_to_seconds(timePoint: str) -> float:
def
transfer_second_to_time
(
sec
:
str
)
->
str
:
def
transfer_second_to_time
(
sec
:
str
)
->
str
:
"""
"""
输入xxxx.xxx秒,输出xx:xx:xx.xx
的格式(输出不一定有小数点)
输入xxxx.xxx秒,输出xx:xx:xx.xx
x的格式
"""
"""
duration
=
int
(
float
(
sec
))
duration
=
int
(
float
(
sec
))
hour
=
int
(
duration
/
3600
)
hour
=
int
(
duration
/
3600
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment