rogerxavier commited on
Commit
ad571ab
1 Parent(s): d2d2a7f

Update 3mergeDialogToVideo.py

Browse files
Files changed (1) hide show
  1. 3mergeDialogToVideo.py +43 -2
3mergeDialogToVideo.py CHANGED
@@ -273,6 +273,41 @@ if __name__ == '__main__':
273
 
274
  image_files = filtered_image_files
275
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  for idx, image_file in enumerate(image_files):
277
  print("现在处理的图片是"+image_file)
278
  #后面是视音频生成部分-这里图片需要用到完整的去水印的而不是对话框用于识别的
@@ -295,15 +330,21 @@ if __name__ == '__main__':
295
  font=font_path) ##文本clip后加入视频
296
 
297
  txt_clip = txt_clip.set_pos(('center', 'bottom')).set_duration(duration)
 
 
 
 
 
 
298
  # 创建音频剪辑
299
  audio_clip = AudioFileClip(filename)
300
  clip = clip.set_audio(audio_clip) # 将音频与视频片段关联
301
  clip = CompositeVideoClip([clip, txt_clip])
302
  video_clips.append(clip)
 
303
  else:
304
  pass ##音频特殊字符或者其他原因无法生成跳过
305
- else:
306
- pass ##图片不规范直接跳过
307
  video = concatenate_videoclips(video_clips)
308
  # 保存视频
309
  video.write_videofile('mp4_out/output_video.mp4', fps=fps,temp_audiofile="mp3_out/temp.mp3")
 
273
 
274
  image_files = filtered_image_files
275
 
276
+
277
+
278
+ # for idx, image_file in enumerate(image_files):
279
+ # print("现在处理的图片是"+image_file)
280
+ # #后面是视音频生成部分-这里图片需要用到完整的去水印的而不是对话框用于识别的
281
+ # img = cv2.imread(image_file)
282
+ # img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) ##只支持英文路径
283
+
284
+ # ##获取当前图片对应的对话框识别文字(还需gpt处理后作为字幕文案)
285
+ # cur_copywrite = get_image_copywrite(image_file,dialog_img_path) # image_file就是6.jpg了
286
+ # #cur_copywrite = gpt_polish(cur_copywrite)#不用gpt,只用新版漫画块得到的100%识别原文即可
287
+
288
+ # if cur_copywrite is not None:
289
+
290
+ # ##获取当前图片对应的临时音频文件名称和文案时长
291
+ # filename, duration = get_audio_data(cur_copywrite)
292
+ # if filename is not None:
293
+ # print("存放临时mp3文件的路径是",filename)
294
+ # clip = ImageClip(img).set_duration(duration).resize((width, height)) # 初始clip
295
+
296
+ # txt_clip = TextClip(cur_copywrite, fontsize=40, color='white', bg_color='black',
297
+ # font=font_path) ##文本clip后加入视频
298
+
299
+ # txt_clip = txt_clip.set_pos(('center', 'bottom')).set_duration(duration)
300
+ # # 创建音频剪辑
301
+ # audio_clip = AudioFileClip(filename)
302
+ # clip = clip.set_audio(audio_clip) # 将音频与视频片段关联
303
+ # clip = CompositeVideoClip([clip, txt_clip])
304
+ # video_clips.append(clip)
305
+ # else:
306
+ # pass ##音频特殊字符或者其他原因无法生成跳过
307
+
308
+
309
+ #分割字幕
310
+ prev_clip_end = 0
311
  for idx, image_file in enumerate(image_files):
312
  print("现在处理的图片是"+image_file)
313
  #后面是视音频生成部分-这里图片需要用到完整的去水印的而不是对话框用于识别的
 
330
  font=font_path) ##文本clip后加入视频
331
 
332
  txt_clip = txt_clip.set_pos(('center', 'bottom')).set_duration(duration)
333
+ if prev_clip_end > 0:
334
+ silence_duration = duration - prev_clip_end
335
+ silence_clip = TextClip('', fontsize=40, color='white', bg_color='black', font=font_path)
336
+ silence_clip = silence_clip.set_pos(('center', 'bottom')).set_duration(silence_duration)
337
+ video_clips.append(silence_clip)
338
+
339
  # 创建音频剪辑
340
  audio_clip = AudioFileClip(filename)
341
  clip = clip.set_audio(audio_clip) # 将音频与视频片段关联
342
  clip = CompositeVideoClip([clip, txt_clip])
343
  video_clips.append(clip)
344
+ prev_clip_end = duration
345
  else:
346
  pass ##音频特殊字符或者其他原因无法生成跳过
347
+
 
348
  video = concatenate_videoclips(video_clips)
349
  # 保存视频
350
  video.write_videofile('mp4_out/output_video.mp4', fps=fps,temp_audiofile="mp3_out/temp.mp3")