python 鑷繁鍐欎竴涓棰戝帇缂╀唬鐮
浠ヤ笅鏄娇鐢≒ython缂栧啓鐨勫熀鏈棰戝帇缂╀唬鐮佺ず渚嬶細


import moviepy.editor as mp
 
def compress_video(input_file, output_file):
    video = mp.VideoFileClip(input_file)
    
    # 璁剧疆杈撳嚭鏂囦欢鏍煎紡銆佸垎杈ㄧ巼绛夊弬鏁帮紙鍙牴鎹渶姹傝繘琛岃皟鏁达級
    compressed_video = video.resize((640, 360)) \
                            .set_fps(25) \
                            .write_videofile(output_file, codec='libx264', audio_codec="aac")
    
    return compressed_video
 
# 鎸囧畾鍘熷瑙嗛璺緞鍜岀洰鏍囧帇缂╁悗瑙嗛淇濆瓨璺緞
input_path = "original_video.mp4"
output_path = "compressed_video.mp4"
 
# 璋冪敤鍑芥暟杩涜瑙嗛鍘嬬缉
result = compress_video(input_path, output_path)
print("瑙嗛鍘嬬缉瀹屾垚锛")


杩欐浠g爜浣跨敤浜唌oviepy搴撴潵澶勭悊瑙嗛銆傞鍏堥氳繃VideoFileClip()鍔犺浇瑕佸帇缂╃殑瑙嗛鏂囦欢锛岀劧鍚庝娇鐢.resize()璁剧疆鏂扮殑鍒嗚鲸鐜囷紝.set_fps()璁剧疆鏂扮殑甯ч熺巼锛屾渶鍚庝娇鐢.write_videofile()灏嗗帇缂╁悗鐨勮棰戜繚瀛樺埌鎸囧畾璺緞涓傚湪姝ょず渚嬩腑锛屾垜浠夋嫨浜嗗父鐢ㄧ殑H.264缂栫爜鍣ㄤ綔涓鸿棰戠紪鐮佸櫒锛孉AC缂栫爜鍣ㄤ綔涓洪煶棰戠紪鐮佸櫒銆傛潵婧愶細OD浜戝叏缃戣惀閿www.odweb.cn

浠ヤ笂灏辨槸鐢≒ython鑷繁鍐欎竴娈佃秴楦$畝鍗曠殑瑙嗛鍘嬬缉鍔熻兘浠g爜鐨勮缁嗗唴瀹癸紝鏇村淇℃伅璇峰叧娉∣D浜戝叾瀹冪浉鍏虫枃绔狅紒



鏈枃URL锛http://www.odweb.cn/news_show.html?id=268