共計 1113 個字符,預計需要花費 3 分鐘才能閱讀完成。
要在 Python 中使用 ffmpeg 模塊,需要先安裝 ffmpeg-python 庫。可以使用以下命令安裝:
pip install ffmpeg-python
安裝完成后,可以使用以下代碼示例來使用 ffmpeg 模塊:
import ffmpeg
# 獲取視頻信息
probe = ffmpeg.probe('input.mp4')
video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
# 打印視頻信息
print(' 視頻信息:')
print(' 分辨率:', video_stream['width'], 'x', video_stream['height'])
print(' 編碼格式:', video_stream['codec_name'])
print(' 比特率:', video_stream['bit_rate'], 'bps')
# 轉換視頻格式
ffmpeg.input('input.mp4').output('output.avi').run()
# 剪切視頻
ffmpeg.input('input.mp4').output('output.mp4', ss='00:00:10', t='00:00:20').run()
# 提取音頻
ffmpeg.input('input.mp4').output('output.mp3', f='mp3').run()
# 合并視頻
input1 = ffmpeg.input('input1.mp4')
input2 = ffmpeg.input('input2.mp4')
ffmpeg.concat(input1, input2, v=1, a=1).output('output.mp4').run()
以上代碼示例中,演示了如何獲取視頻信息、轉換視頻格式、剪切視頻、提取音頻以及合并視頻等操作。根據需要,可以根據 ffmpeg 的命令行用法,在 python 中進行相應的操作。
丸趣 TV 網 – 提供最優質的資源集合!
正文完