Skip to content

Commit 27a32c3

Browse files
authored
Merge pull request #154 from yimm0815/smartupload
add ffmpeg transcode
2 parents bcb60c2 + 0f6c975 commit 27a32c3

File tree

4 files changed

+45
-33
lines changed

4 files changed

+45
-33
lines changed

Diff for: deployment/docker-swarm/smart-upload.m4

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
2-
define(`SERVICE_INTERVAL_SMART_UPLOAD',`60')dnl
1+
define(`SERVICE_INTERVAL_SMART_UPLOAD',`120')dnl
32

43
defn(`OFFICE_NAME')_smart_upload:
54
image: smtc_smart_upload:latest
65
environment:
7-
QUERY: "time>=now-eval(defn(`SERVICE_INTERVAL_SMART_UPLOAD')*1000000) where objects.detection.bounding_box.x_max-objects.detection.bounding_box.x_min>0.01"
6+
QUERY: "time>=now-eval(defn(`SERVICE_INTERVAL_SMART_UPLOAD')*1000) where objects.detection.bounding_box.x_max-objects.detection.bounding_box.x_min>0.01"
87
INDEXES: "recordings,analytics"
98
OFFICE: "defn(`OFFICE_LOCATION')"
109
DBHOST: "http://ifelse(eval(defn(`NOFFICES')>1),1,defn(`OFFICE_NAME')_db,db):9200"
@@ -28,4 +27,9 @@ ifelse(defn(`PLATFORM'),`VCAC-A',`dnl
2827
placement:
2928
constraints:
3029
- defn(`OFFICE_ZONE')
30+
resources:
31+
limits:
32+
cpus: '0.20'
33+
reservations:
34+
cpus: '0.10'
3135

Diff for: deployment/kubernetes/smart-upload.yaml.m4

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
include(office.m4)
2-
define(`SERVICE_INTERVAL_SMART_UPLOAD',60)dnl
2+
define(`SERVICE_INTERVAL_SMART_UPLOAD',120)dnl
33

44
apiVersion: apps/v1
55
kind: Deployment
@@ -21,6 +21,11 @@ spec:
2121
- name: defn(`OFFICE_NAME')-smart-upload
2222
image: smtc_smart_upload:latest
2323
imagePullPolicy: IfNotPresent
24+
resources:
25+
requests:
26+
cpu: "100m"
27+
limits:
28+
cpu: "200m"
2429
env:
2530
- name: QUERY
2631
value: "time>=eval(defn(`SERVICE_INTERVAL_SMART_UPLOAD')*1000) where objects.detection.bounding_box.x_max-objects.detection.bounding_box.x_min>0.01"

Diff for: maintenance/smart-upload/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
FROM centos:7.6.1810
2+
FROM openvisualcloud/xeon-centos76-media-ffmpeg:latest
33

4-
RUN yum -y install epel-release && yum -y install python36-requests python36-ply && rm -rf /var/cache/yum/* curl
4+
RUN yum -y install epel-release && yum -y install python36-requests python36-ply python36-psutil && rm -rf /var/cache/yum/* curl
55

66
COPY --from=smtc_common /*.py /home/
77
COPY *.py /home/

Diff for: maintenance/smart-upload/smart-upload.py

+30-27
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from db_ingest import DBIngest
44
from db_query import DBQuery
5+
from probe import probe, run
56
from signal import signal, SIGTERM
67
import requests
78
import os
@@ -18,10 +19,24 @@
1819
smhost=os.environ["SMHOST"]
1920
cloudhost=os.environ["CLOUDHOST"]
2021

22+
dbs=None
23+
rs=None
24+
2125
def quit_service(signum, sigframe):
2226
if dbs and rs: dbs.delete(rs["_id"])
2327
exit(143)
2428

29+
def upload(cloudhost, filename, office, sensor, timestamp):
30+
with open(filename,"rb") as fd:
31+
r=requests.post(cloudhost,data={
32+
"time":timestamp,
33+
"office":str(office[0])+","+str(office[1]),
34+
"sensor":sensor,
35+
},files={
36+
"file": fd,
37+
},verify=False)
38+
os.remove(filename)
39+
2540
signal(SIGTERM, quit_service)
2641
dbs=DBIngest(index="services",office=office,host=dbhost)
2742
while True:
@@ -39,40 +54,28 @@ def quit_service(signum, sigframe):
3954
dbq=DBQuery(index=indexes,office=office,host=dbhost)
4055

4156
while True:
42-
print("Sleeping...")
43-
time.sleep(service_interval)
4457

4558
print("Searching...",flush=True)
4659
print("query = ", query)
4760

4861
try:
4962
for q in dbq.search(query):
50-
filename=smhost+'/'+q["_source"]["path"]
51-
print("filename: ", filename)
63+
url=smhost+'/'+q["_source"]["path"]
64+
print("url: ", url)
65+
66+
mp4file="/tmp/"+str(os.path.basename(url))
5267

53-
r=requests.head(filename, timeout=10)
54-
if r.status_code!=200:
55-
print("pipeline status: "+str(r.status_code), flush=True)
56-
print(r.text, flush=True)
57-
break
68+
print("Transcoding...")
69+
os.remove(mp4file)
70+
list(run(["/usr/bin/ffmpeg","-f","mp4","-i",url,"-c:v","libsvt_hevc","-c:a","aac",mp4file]))
5871

59-
#add updates to request
60-
print("get url: ", r.url)
61-
print("send to cloud storage: ", cloudhost)
62-
print("office: ", str(office[0])+","+str(office[1]))
63-
#print("sensor: ", sensor)
64-
#print("year: ", year)
65-
#print("month: ", month)
66-
#print("day: ", day)
67-
#print("time: ", str((os.path.basename(filename).split('.')[0]))
68-
# r=requests.post(cloudhost,data={
69-
# "office":str(office[0])+","+str(office[1]),
70-
# "sensor":***,
71-
# "year":***,
72-
# "month":***,
73-
# "day":***,
74-
# "time":str((os.path.basename(filename).split('.')[0])),
75-
# })
72+
print("Uploading: ", cloudhost)
73+
sensor=q["_source"]["sensor"]
74+
timestamp=q["_source"]["time"]
75+
upload(cloudhost, mp4file, office, sensor, timestamp)
7676

7777
except Exception as e:
78-
print("Exception: "+str(e), flush=True)
78+
print("Exception: "+str(e), flush=True)
79+
80+
print("Sleeping...")
81+
time.sleep(service_interval)

0 commit comments

Comments
 (0)