summaryrefslogtreecommitdiffstats
path: root/encoder.py
blob: 31925c334f4672e7529afc249067cdbd61b96528 (plain)
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
#!/usr/bin/python

# freeseer - vga/presentation capture software
#
#  Copyright (C) 2010  Free and Open Source Software Learning Centre
#  http://fosslc.org
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.


# For support, questions, suggestions or any other inquiries, visit:
# the #fosslc channel on IRC (freenode.net)


import sys
from PyQt4 import QtGui, QtCore

CONFIG = dict()
CMD_FFMPEG = ("ffmpeg -i \"%(FILENAME)s.avi\" -async 3 -acodec libvorbis \"%(FILENAME)s.ogg\"")

class MainApp(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        
        self.ffmpeg = QtCore.QProcess()
        
        # layout
        layout = QtGui.QVBoxLayout()
        
        self.encode = QtGui.QPushButton("Encode")
        self.encode.setCheckable(True)
        layout.addWidget(self.encode)
        
        self.list = QtGui.QListWidget()
        layout.addWidget(self.list)
        
        self.setLayout(layout)
        
        # connectors
        self.connect(self.encode, QtCore.SIGNAL('toggled(bool)'), self.Encode)
        self.connect(self.ffmpeg, QtCore.SIGNAL('readyReadStandardOutput()'), self.ffmpegReadOutput)
        self.connect(self.ffmpeg, QtCore.SIGNAL('finished(int)'), self.EncodeFin)
        
        # Add values
        dir = QtCore.QDir()
        dir.setFilter(QtCore.QDir.Files)
        list = dir.entryList()
        while (not list.isEmpty()):
            self.list.addItem(list.takeFirst())        

    def ffmpegReadOutput(self):
        print QtCore.QString(self.ffmpeg.readAllStandardOutput())
            
    def Encode(self):
        if not (self.encode.isChecked()):
            self.stopEncoding()
            return

        self.startEncoding()
    
    def startEncoding(self):
        CONFIG['FILENAME'] = self.list.currentItem().text().remove(".avi")
        self.ffmpeg.start(CMD_FFMPEG % CONFIG)
        self.encode.setText('Stop')
        print 'Started encoding'
    
    def stopEncoding(self):
        self.ffmpeg.close()
        self.encode.setText('Encode')
        print 'Stopped encoding'        

    def EncodeFin(self):
        print 'Encoding completed'
        self.encode.setChecked(False)

#######################
# Program starts here #
#######################
app = QtGui.QApplication(sys.argv)

widget = MainApp()
widget.show()
widget.resize(480, 320)

sys.exit(app.exec_())