python-ffmpeg
Python FFMPEG
2023-09-14 09:06:34 时间
# -*- coding: utf-8 -*-
# @Time : 2022/12/27 4:37 下午
# @Author : chenxiangan
# @File : mp4tomp3.py
# @Software: PyCharm
import click
import ffmpeg
@click.command()
@click.option('-v', '--video_name', required=True, type=str, help='please input video full path')
@click.option('-f', '--format', default='aac', type=str, help='audio format ,support aac or mp3,default is acc')
def main(video_name, format):
buff = ffmpeg_render(video_name, format)
if not format.startswith('.'):
format = f".{format}"
with open(video_name.replace(".mp4", format), "wb") as fs:
fs.write(buff)
def ffmpeg_render(media_file: str, audio_format) -> bytes:
'提取视频伴音并转码为aac格式'
if audio_format == "aac":
audio_format = 'adts'
out, err = (ffmpeg
.input(media_file, v='warning')
.output('pipe:', ac=1, format=audio_format)
.run(capture_stdout=True)
)
return out
if __name__ == '__main__':
main()
视频转音频,方便后期转字幕
相关文章
- python要不要装pycharm-Python和pyCharm安装
- python 生成数组_Python创建数组「建议收藏」
- python语言一般用于什么_PYthon
- Python机器学习教程—回归模型的评估与封装
- Python修改文件后缀_python重命名文件名
- python语言关键字是_Python 关键字
- 正则表达式Python_python正则表达式匹配字符串
- python分段线性插值_Python实现分段线性插值
- Python 自动化业务服务监控
- Python 实现Web容器指纹识别
- python-Python与PostgreSQL数据库-PostgreSQL数据库的基本知识(一)
- Python发邮件代码详解编程语言
- python入门(十):XML和JSON解析详解编程语言
- Linux系统快速运行Python脚本(linux运行python脚本)
- Linux系统如何运行Python脚本(linux执行python脚本)
- Python输出函数print()总结(python print())详解编程语言
- Python简易操作MySQL数据库指南(python操作mysql数据库)
- 安装Python MySQL驱动之快速指南(python安装mysql驱动)
- 语言Linux下开发:从C语言到Python(linux下用什么编程)
- Python实现快速连接Redis数据库(python连接redis)
- python编程-将Python程序转化为可执行程序[整理]