-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.py
55 lines (47 loc) · 1.26 KB
/
publish.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import logging as logger
import ffmpy
import mongoengine as mg,os
import requests
import json
import datetime
from models import Device
from urlparse import urlparse, ParseResult
import threading
import CommonDefine
import errno
import shlex
import subprocess
from ffmpy import FFExecutableNotFoundError
import time
class myffmpeg(ffmpy.FFmpeg):
def sync_run(self, input_data=None, stdout=None, stderr=None):
try:
self.process = subprocess.Popen(
self._cmd,
stdin=subprocess.PIPE,
stdout=stdout,
stderr=stderr
)
except OSError as e:
if e.errno == errno.ENOENT:
raise FFExecutableNotFoundError("Executable '{0}' not found".format(self.executable))
else:
raise
def killself(self):
self.process.kill()
if __name__ == "__main__":
try:
url = "rtsp://xxxxxx"
pushUrl = "rtmp://xxxxxx"
ff = myffmpeg(
inputs={url: None},
outputs={pushUrl :'-hide_banner -loglevel panic -threads 2 -f flv -r 15 -s 1280x720 -an'}
)
ff.sync_run()
time.sleep(600)
ff.killself()
except Exception as e:
print e