目录
mp4转264
wav从60帧,降采样到30帧
mp4转264
import os
import subprocess
def extract_video(input_file, output_file):
command = [
'ffmpeg',
'-i', input_file,
'-vcodec', 'copy',
'-an',
'-bsf:v', 'h264_mp4toannexb',
'-f', 'h264',
output_file
]
try:
subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print("视频提取成功,保存为:", output_file)
except subprocess.CalledProcessError as e:
print("在处理视频时出现错误:", e.stderr.decode())
relative_path='aa.mp4'
absolute_path = os.path.abspath(relative_path)
# 使用示例
extract_video(absolute_path, 'output11.264')
wav从60帧,降采样到30帧
import subprocess
def change_sample_rate(input_file, output_file, new_sample_rate):
command = [
'ffmpeg',
'-i', input_file,
'-ar', str(new_sample_rate),
output_file
]
try:
subprocess.run(command, check=True)
print(f"音频采样率已转换,输出文件为:{output_file}")
except subprocess.CalledProcessError as e:
print("音频采样率转换失败:", e)
# 示例调用
change_sample_rate('output11.wav', 'output.wav', 24000)