forked from ririgoei/CS160-Team3
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvideometa
72 lines (51 loc) · 2.11 KB
/
videometa
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python
## NOTE: This is not functional because the database
## commands are needed to be changed? Currently this
## script only prints the info to the screen instead
## of executing database commands.
# videometa :
#
# This takes one argument, the video id number.
# It shows metadata about the input video.
# This script should be in Apache cgi-bin.
#
# Videos are expected to be in /cs160/videos/<#>.mp4
import sys
import subprocess
vidid = sys.argv[1]
videopath = "/cs160/videos/"
videofile = videopath + vidid + ".mp4"
print "video id is = " + vidid
print
usercmd = "echo `whoami`"
usname = subprocess.check_output(usercmd, shell=True)
print "username is = " + usname
getcmd = "ffprobe -v 0 -select_streams v:0 -show_entries stream=height,width,r_frame_rate,nb_frames " + videofile
a = subprocess.check_output(getcmd, shell=True)
getcmd = "ffprobe -v 0 -select_streams v:0 -show_entries stream=width " \
+ videofile + "|grep -v STREAM|cut -f 2 -d="
width = subprocess.check_output(getcmd, shell=True)
print "the width is = " + width
getcmd = "ffprobe -v 0 -select_streams v:0 -show_entries stream=height " \
+ videofile + "|grep -v STREAM|cut -f 2 -d="
height = subprocess.check_output(getcmd, shell=True)
print "the height is = " + height
getcmd = "ffprobe -v 0 -select_streams v:0 -show_entries stream=r_frame_rate " \
+ videofile + "|grep -v STREAM|cut -f 2 -d="
r_frame_rate = subprocess.check_output(getcmd, shell=True)
print "the r_frame_rate is = " + r_frame_rate
getcmd = "ffprobe -v 0 -select_streams v:0 -show_entries stream=nb_frames " \
+ videofile + "|grep -v STREAM|cut -f 2 -d="
nb_frames = subprocess.check_output(getcmd, shell=True)
print "the nb_frames is = " + nb_frames
try:
conn = MySQLdb.connect("localhost", "root", "3600", "cs160")
print "success"
except:
print "error"
cur = conn.cursor()
cur.execute("INSERT INTO cs160.video_metadata VALUES("+nb_frames + "," + width + "," +
height + "," + r_frame_rate + "," + vidid + "," + videofn + ");")
conn.commit()
cur.close()
conn.close()