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