-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebcamg.py
130 lines (102 loc) · 4.14 KB
/
webcamg.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# -*- coding: utf-8 -*-
#!/usr/bin/env python
#Author: Ana Queila, Jeferson e Uesle
import sys, os
##### Importa a Biblioteca GTK+ #####
import pygtk
pygtk.require("2.0")
import gtk
import gtk.glade
### Importa a Biblioteca Gstreamer ###
import pygst
pygst.require('0.10')
import gst
class Grava():
def on_record_clicked(self, event):
if self.pipe.get_state()[1] == gst.STATE_NULL:
filepath = self.fcb.get_filename()
name = self.entry.get_text()+".avi"
if os.path.isdir(filepath):
self.sink.set_property("location", filepath +"/"+ name)
self.pipe.set_state(gst.STATE_PLAYING)
def on_stop_clicked(self, event):
if self.pipe.get_state()[1] == gst.STATE_PLAYING:
self.pipe.set_state(gst.STATE_NULL)
def on_finish_clicked(self, widget, data=None):
self.janela.hide_all()
arquivoglade = "webcamG.glade"
def __init__ (self):
#criando builder
builder = gtk.Builder()
#carregando arquivo do glade no builder
builder.add_from_file(self.__class__.arquivoglade)
#carregando janela
self.janela = builder.get_object("janela")
#Carregando o DrawingArea
self.movie_window = builder.get_object("movie_window")
self.fcb = builder.get_object("filechooserbutton1")
self.entry = builder.get_object("entry1")
#conectando os sinais
#builder.connect_signals(handle.__dict__)
builder.connect_signals(self)
#Exibe toda interface
self.janela.show_all()
self.pipe = gst.Pipeline("MyPlayer")
videosrc = gst.element_factory_make("v4l2src", "v4l")
videorate = gst.element_factory_make("videorate","videorate")
caps = gst.Caps("video/x-raw-yuv, framerate=(fraction)30/1 ")
capsfilter = gst.element_factory_make("capsfilter", "filter")
capsfilter.set_property("caps", caps)
tvid = gst.element_factory_make("tee","tvid")
colorspace = gst.element_factory_make("ffmpegcolorspace", "colorspace")
enc = gst.element_factory_make("jpegenc", "enc")
vidqueue = gst.element_factory_make("queue","vidqueue")
audqueue = gst.element_factory_make("queue","audqueue")
queue = gst.element_factory_make("queue","queue")
audiosrc = gst.element_factory_make("alsasrc","audiosrc")
convert = gst.element_factory_make("audioconvert","convert")
audiorate = gst.element_factory_make("audiorate")
acaps = gst.Caps("audio/x-raw-int ,width=16,depth=16,rate=44100,channels=2,signed=true")
acapsfilter = gst.element_factory_make("capsfilter","afilter")
acapsfilter.set_property("caps", acaps)
mux = gst.element_factory_make("avimux", "mux")
squeue = gst.element_factory_make("queue","squeue")
tsink = gst.element_factory_make("xvimagesink","tsink")
tsink.set_property("synchronous", False)
self.sink = gst.element_factory_make("filesink", "sink")
self.pipe.add(videosrc, videorate, capsfilter, tvid, acapsfilter, audiorate, tsink, colorspace, enc,vidqueue)
self.pipe.add(audiosrc, convert, audqueue)
self.pipe.add(squeue, mux, self.sink)
gst.element_link_many(videosrc, videorate, capsfilter, tvid, tsink)
gst.element_link_many( tvid, colorspace, enc, vidqueue, mux)
gst.element_link_many(audiosrc, convert, audiorate, acapsfilter, audqueue, mux)
gst.element_link_many(mux, self.sink)
bus = self.pipe.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
bus.connect("message", self.on_message)
bus.connect("sync-message::element", self.on_sync_message)
self.movie_window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(red=0, green=0, blue=0, pixel=65535))
gtk.gdk.threads_init()
gtk.main()
gtk.gdk.notify_startup_complete()
def on_message(self, bus, message):
t = message.type
print t
if t == gst.MESSAGE_EOS:
self.pipe.set_state(gst.STATE_NULL)
elif t == gst.MESSAGE_ERROR:
err, debug = message.parse_error()
print "Error: %s" % err, debug
self.pipe.set_state(gst.STATE_NULL)
def on_sync_message(self, bus, message):
if message.structure is None:
return
message_name = message.structure.get_name()
if message_name == "prepare-xwindow-id":
# Assign the viewport
imagesink = message.src
imagesink.set_property("force-aspect-ratio", True)
gtk.gdk.threads_enter()
imagesink.set_xwindow_id(self.movie_window.window.xid)
gtk.gdk.threads_leave()