|
@@ -22,15 +22,19 @@ class FFmpeg():
|
|
|
"""
|
|
|
@classmethod
|
|
|
def get_video_duration(cls, video_url):
|
|
|
- ffprobe_cmd = [
|
|
|
- "ffprobe",
|
|
|
- "-i", video_url,
|
|
|
- "-show_entries", "format=duration",
|
|
|
- "-v", "quiet",
|
|
|
- "-of", "csv=p=0"
|
|
|
- ]
|
|
|
- output = subprocess.check_output(ffprobe_cmd).decode("utf-8").strip()
|
|
|
- return float(output)
|
|
|
+ try:
|
|
|
+ ffprobe_cmd = [
|
|
|
+ "ffprobe",
|
|
|
+ "-i", video_url,
|
|
|
+ "-show_entries", "format=duration",
|
|
|
+ "-v", "quiet",
|
|
|
+ "-of", "csv=p=0"
|
|
|
+ ]
|
|
|
+ output = subprocess.check_output(ffprobe_cmd).decode("utf-8").strip()
|
|
|
+ return float(output)
|
|
|
+ except Exception as e:
|
|
|
+ return 0
|
|
|
+
|
|
|
|
|
|
"""
|
|
|
获取视频文件的时长(秒)
|
|
@@ -123,6 +127,8 @@ class FFmpeg():
|
|
|
gg_duration_url = video_path_url + str(pw_random_id) + 'gg_duration.mp4'
|
|
|
# 获取视频时长
|
|
|
total_duration = cls.get_video_duration(new_video_path)
|
|
|
+ if total_duration == 0:
|
|
|
+ return new_video_path
|
|
|
duration = int(total_duration) - int(gg_duration_total)
|
|
|
if int(total_duration) < int(gg_duration_total):
|
|
|
return new_video_path
|
|
@@ -152,6 +158,8 @@ class FFmpeg():
|
|
|
jpg_url = video_path_url + str(pw_random_id) + 'png.jpg'
|
|
|
# 获取视频时长
|
|
|
total_duration = cls.get_video_duration(new_video_path)
|
|
|
+ if total_duration == 0:
|
|
|
+ return new_video_path
|
|
|
time_offset = total_duration - 1 # 提取倒数第一秒的帧
|
|
|
# 获取视频最后一秒,生成.jpg
|
|
|
subprocess.run(
|
|
@@ -192,6 +200,8 @@ class FFmpeg():
|
|
|
single_video_txt = video_path_url + str(pw_random_id) +'video_zm.txt'
|
|
|
single_video = video_path_url + str(pw_random_id) +'video_zm.mp4'
|
|
|
duration = cls.get_video_duration(new_video_path)
|
|
|
+ if duration == 0:
|
|
|
+ return new_video_path
|
|
|
start_time = cls.seconds_to_srt_time(0)
|
|
|
end_time = cls.seconds_to_srt_time(duration)
|
|
|
# zm = '致敬伟大的教员,为整个民族\n感谢老人家历史向一代伟人'
|
|
@@ -240,6 +250,8 @@ class FFmpeg():
|
|
|
pw_url_path = video_path_url + str(pw_random_id) + 'pw_video.mp4'
|
|
|
# 获取视频时长
|
|
|
pw_duration = cls.get_video_duration(pw_url)
|
|
|
+ if pw_duration == 0:
|
|
|
+ return pw_url_path
|
|
|
time.sleep(2)
|
|
|
# 添加字幕 wqy-zenhei Hiragino Sans GB
|
|
|
height = 1080
|
|
@@ -302,6 +314,8 @@ class FFmpeg():
|
|
|
single_video_srt = video_path_url + 'single_video.srt'
|
|
|
# 获取时长
|
|
|
duration = cls.get_video_duration(new_video_path)
|
|
|
+ if duration == 0:
|
|
|
+ return single_video_url
|
|
|
start_time = cls.seconds_to_srt_time(2)
|
|
|
end_time = cls.seconds_to_srt_time(duration)
|
|
|
single_video_txt = video_path_url + 'single_video.txt'
|