1.音频波形读取
import librosa aaa = librosa.load("233.mp3") # print(aaa) print(aaa[0])#波形数据 print(aaa[1])#码率 # print(len(aaa[0])/aaa[1]) s_play = len(aaa[0])//aaa[1]#时长 print(aaa[0]) bps = aaa[1] s_list = [] s_min = min(aaa[0]) s_max = max(aaa[0]) for idx in range(0,s_play):#平均音量 s_list.append(sum(aaa[0][idx*bps:(idx+1)*aaa[1]])/bps) def max_volum(llist,value): clip_save = [] for idx in llist: clip_save.append(idx>value) # if value>value: return clip_save ss_list = []#时间减半 for idx in range(0,int((s_max-s_min)*10)): ss_list = max_volum(s_list,idx/10) if sum(ss_list)>s_play/2: print(ss_list) break
2.视频剪辑合成
from moviepy import editor video_clip = editor.VideoFileClip("241.mp4") # 截取10到20秒 video_clip1 = video_clip.subclip(1,3) # 截取1分45秒到结尾的前两秒 video_clip2 = video_clip.subclip(1,3) video_clip3 = video_clip.subclip(3,8) video_clip4 = video_clip.subclip(3,8) cp=editor.concatenate_videoclips([video_clip1,video_clip2,video_clip3,video_clip4]) # cp.write_videofile() # cp=editor.CompositeVideoClip([video_clip1,video_clip2]) cp.write_videofile("252.mp4")
标签:aaa,idx,clip,python,list,video,print,与音,视频剪辑 From: https://www.cnblogs.com/hardfood/p/17074986.html