python对外部程序的调用


调用外部程序的两种方法:os.system和subprocess

python实现录屏功能

 

# coding=utf8
import time,os

# 输出视频文件
outputfile = 'd:/data/bandicam/tmp/'  + time.strftime('%Y%m%d_%H%M%S', time.localtime()) + '.mp4'

# 工具目录
ffmpegDir = r'd:\data\bandicam\tmp\ffmpeg.exe'

settings = [
    '-y -rtbufsize 100M -f gdigrab -framerate 10',   # 帧率等
    '-offset_x 1000 -offset_y 0 -video_size 640x480', # 录制指定屏幕区域
    '-draw_mouse 1 -i desktop -c:v libx264',         # 视频编码格式
    '-r 20 -preset medium -tune zerolatency -crf 35', # 视频压缩参数
    '-pix_fmt yuv420p -fs 100M  -movflags +faststart "%s"' % outputfile  # 大小限制 等
]

# 将参数组合起来
recordingCmdLine = ' '.join([ffmpegDir]+settings)

# 查看命令内容
print(recordingCmdLine)

# 执行命令录制视频
# os.system(recordingCmdLine)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM