python利用ffmpeg进行录制屏幕的方法

yipeiwu_com6年前Python基础

前几天下载了几个视频,但是有两集是一个视频的,偶尔找到了ffmpeg处理视频的方法,它的功能非常强大。因此,分享一下,一起学习。

import subprocess,sys,os
import re
class CutSplicingVdeio(object):
  def __init__(self):
    pass
  #dercription CutSplicingVdeio this class function
  def instructions(self):
    dercription="vdeio and image transform,vdeio other opreation"
    return dercription
  def transcribeScreen(self,filePath):
    filePath=filePath.decode('utf-8')
    cmd=ffmpegPath + " -f gdigrab -framerate 60 -offset_x 0 -offset_y 0 -video_size 1366x768 -i desktop " + filePath
    cmd=cmd.encode(sys.getfilesystemencoding())
    if "?" in cmd:
      cmd=cmd.replace("?","")
    print cmd
    subprocess.call(cmd , shell=True)

vp=CutSplicingVdeio()       vp.transcribeScreen(r"C:\Users\Administrator\Desktop\transcribe.avi")
#according to give a video filepath (transcribe Screen)

首先,写了一个api,里面的的一个录制屏幕的功能,其他的暂时没写,以后再分享。

vp.transcribeScreen传递路径后执行transcribeScreen,为让中文显示正常转换一下编码格式,

之后执行cmd命令即可。

win7系统执行后报错,不知原因,排产原因是在路径里多出一个?,去除之后,完美运行。

也可以直接cmd运行 D:\LenovoC\ffmpeg\bin\ffmpeg.exe -f gdigrab -framerate 60 -offset_x 0 -offset_y 0 -video_size 1366x768 -i desktop C:\Users\Administrator\Desktop\transcribe.avi。

好了今天就到这里。

以上这篇python利用ffmpeg进行录制屏幕的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python线程的几种创建方式详解

Python3 线程中常用的两个模块为: _thread threading(推荐使用) 使用Thread类创建 import threading from time...

PyTorch 解决Dataset和Dataloader遇到的问题

今天在使用PyTorch中Dataset遇到了一个问题。先看代码 class psDataset(Dataset): def __init__(self, x, y, trans...

Python里字典的基本用法(包括嵌套字典)

Python里字典的基本用法(包括嵌套字典)

Python字典的基本用法 创建字典: myDict1 = { '薛之谦':'我叫薛之谦', '吴青峰':'我叫吴青峰', '李宇春':'我叫李宇春', '花花':'...

Python利用正则表达式实现计算器算法思路解析

  (1)不使用eval()等系统自带的计算方法   (2)实现四则混合运算、括号优先级解析 思路:   1、字符串预处理,将所有空格去除   2、判断是否存在括号运算,若存在进行第3步...

Python中的sort()方法使用基础教程

一、基本形式 sorted(iterable[, cmp[, key[, reverse]]]) iterable.sort(cmp[, key[, reverse]]) &nbs...