# -*- coding:utf-8 -*-
import os, sys, getopt
import numpy as np
import subprocess as sp
import cv2 # command line parser
'''
try:
opts, args = getopt.getopt(sys.argv[1:], "i:s:",["help"])
except getopt.GetoptError:
sys.exit() for op, value in opts:
if op == "-i":
input_file = value
elif op== "-s":
widthheight = value.split('*')
width = np.int(widthheight[0])
height = np.int(widthheight[1]) '''
input_file = 'rtsp://admin:hik12345@192.168.3.175/cam/realmonitor?channel=1&subtype=1'
width = 704
height = 576 # videoIO
FFMPEG_BIN = "E:/ffmpeg-20180227-fa0c9d6-win64-static/bin/ffmpeg.exe"
command_in = [ FFMPEG_BIN,
'-i', input_file,
'-f', 'rawvideo',
'-s', str(width) + '*' + str(height),
'-pix_fmt', 'bgr24',
'-']
pipe_in = sp.Popen(command_in, stdout=sp.PIPE) command_out = ['E:/ffmpeg-20180227-fa0c9d6-win64-static/bin/ffmpeg.exe',
'-y',
'-f', 'rawvideo',
'-vcodec', 'rawvideo',
'-pix_fmt', 'bgr24',
'-s', str(width) + '*' + str(height),
# '-r', str(fps),
'-i', '-',
'-c:v', 'libx264',
'-pix_fmt', 'yuv420p',
# '-preset', 'ultrafast',
# '-acodec', 'copy',
# '-vcodec', 'copy',
'-f', 'flv',
'rtmp://192.168.3.56:1935/MyRed5/test'] pipe_out = sp.Popen(command_out, stdin=sp.PIPE) # ,shell=False # 这是处理每一帧图像的函数
def process(img):
cv2.imshow('image', img) # read width*height*3 bytes (= 1 frame)
while True:
raw_image = pipe_in.stdout.read(width * height * 3)
image = np.fromstring(raw_image, dtype='uint8')
if(len(image) == 0):
break
image = image.reshape((height, width, 3)).copy()
process(image)
# sys.stdout.write(image.tostring())
# pipe_in.stdout.flush()
pipe_out.stdin.write(image.tostring()) # 存入管道
pipe_out.stdin.flush()
k = cv2.waitKey(25)
# q键退出
if (k & 0xff == ord('q')):
break

Python subprocess ffmpeg的更多相关文章

  1. 用Python和FFmpeg查找大码率的视频文件

    用Python和FFmpeg查找大码率的视频文件 本文使用Python2.7, 这个工作分两步 遍历目录下的视频文件 用ffprobe获取是视频文件的码率信息 用ffprobe 获取json格式的视频 ...

  2. 【python库模块】Python subprocess模块功能与常见用法实例详解

    前言 这篇文章主要介绍了Python subprocess模块功能与常见用法,结合实例形式详细分析了subprocess模块功能.常用函数相关使用技巧. 参考 1. Python subprocess ...

  3. python subprocess popen 静默模式(不弹出console控制台)

    python subprocess popen 静默模式(不弹出console控制台) import subprocess,sys IS_WIN32 = 'win32' in str(sys.plat ...

  4. python subprocess相关操作

    python subprocess常用操作 1.subprocess模块的常用函数 函数 描述 subprocess.run() Python 3.5中新增的函数.执行指定的命令,等待命令执行完成后返 ...

  5. Python: subprocess.Popen()不支持unicode问题解决

    起源: 所下载视频,有音视频分离者,需要合并起来,采用python之subprocess.Popen()调用ffmpeg实现.python版本为2.7.13,而音视频文件路径,有unicode字符者, ...

  6. Python subprocess.Popen communicate() 和wait()使用上的区别

    之所以会纠结到这个问题上是因为发现在调用Popen的wait方法之后程序一直没有返回.google发现wait是有可能产生死锁的.为了把这个问题彻底弄清楚,搜索一些资料过来看看: 原文链接:http: ...

  7. python subprocess阻塞

    import select import os import subprocess import time import fcntl args = ['python','./fetch_file2.p ...

  8. python subprocess 自动运行实验室程序

    import threading, os, subprocess, time exec_path = "/home/xhz/gems/ruby/amd...../bin/tester.exe ...

  9. Python subprocess模块学习总结

    从Python 2.4开始,Python引入subprocess模块来管理子进程,以取代一些旧模块的方法:如 os.system.os.spawn*.os.popen*.popen2.*.comman ...

随机推荐

  1. sqlite3 on python for newbies

    python 集成了 sqlite3 ,其接口很简单: import sqlite3 db_connection = sqlite3.connect(db_filename) db_cursor = ...

  2. scanf() 与 gets()--转载

    scanf( )函数和gets( )函数都可用于输入字符串,但在功能上有区别.若想从键盘上输入字符串"hi hello",则应该使用__gets__函数. gets可以接收空格:而 ...

  3. [IOI2008] Fish 鱼

    https://www.luogu.org/recordnew/lists?uid=56840 题解 首先可以发现我们对于每种颜色的鱼,长一点的能够覆盖的方案已定完全包含短一点的方案. 所以我们可以只 ...

  4. [思路题][LOJ2290][THUWC2017]随机二分图:状压DP+期望DP

    分析 考虑状压DP,令\(f[sta]\)表示已匹配状态是\(sta\)(\(0\)代表已匹配)时完美匹配的期望数量,显然\(f[0]=1\). 一条边出现了不代表它一定在完美匹配内,这也导致很难去直 ...

  5. Java Interger类,两对整数明明完全一样,为何一个输出true,一个输出false

    package text; public class MethodOverload { public static void main(String[] args) { Integer i1=100; ...

  6. linux-解决添加的网卡无法识别的问题

    添加网卡之后,网卡无法被正确的识别和使用排错方法 查看/etc/udev/rules.d/70-persistent-net.rules的内容,该文件中可以查看到新添加的网卡的MAC地址 修改/etc ...

  7. Handling Configuration Changes with Fragments

    This post addresses a common question that is frequently asked on StackOverflow: What is the best wa ...

  8. HDU 5073 Galaxy (数学)

    Galaxy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Su ...

  9. postgresql获取表最后更新时间(通过表磁盘存储文件时间)

    一.创建获取表更新时间的函数 --获取表记录更新时间(通过表磁盘存储文件时间) create or replace function table_file_access_info( IN schema ...

  10. linux shell的一些配置

    alias egrep='egrep --color=auto'alias fgrep='fgrep --color=auto'alias grep='grep --color=auto'alias ...