~novacut/novacut/12.07

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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/usr/bin/python3

# novacut: the collaborative video editor
# Copyright (C) 2011 Novacut Inc
#
# This file is part of `novacut`.
#
# `novacut` is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# `novacut` 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 Affero General Public License for
# more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with `novacut`.  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#   Jason Gerard DeRose <jderose@novacut.com>

import time

from userwebkit import BaseApp
from microfiber import Conflict, NotFound
import dbus
from dmedia.util import init_views

import novacut
from novacut import schema
from novacut import views


session = dbus.SessionBus()


def default_settings():
#    node = {
#        'muxer': {'name': 'oggmux'},
#        'ext': 'ogv',
#        'video': {
#            'encoder': {
#                'name': 'theoraenc',
#                'props': {
#                    'speed-level': 2,
#                },
#            },
#            'filter': {
#                'mime': 'video/x-raw-yuv',
#                'caps': {
#                    'width': 960,
#                    'height': 540,
#                },
#            },
#        },
#        'audio': {
#            'encoder': {
#                'name': 'vorbisenc',
#            },
#        },
#    }
    node = {
        'muxer': {'name': 'avimux'},
        'ext': 'avi',
        'video': {
            'encoder': {
                'name': 'x264enc',
                'props': {
                    'pass': 5,  # Quality-based encoding
                    'quantizer': 15,  # Lower means higher-quality, default=21
                    'psy-tune': 5,  # Tune for SSIM
                },
            },
            'filter': {
                'mime': 'video/x-raw-yuv',
                'caps': {
                    'width': 1280,
                    'height': 720,
                },
            },
        },
#        'audio': {
#            'encoder': {
#                'name': 'identity',
#            },
#            'filter': {
#                'mime': 'audio/x-raw-int',
#            },
#        },
        'audio': {
            'encoder': {
                'name': 'ffenc_aac',
                'props': {
                    'bitrate': 256000,
                },
            },
        },
    }
    return schema.create_settings(node)


class App(BaseApp):
    name = 'novacut'
    dbname = schema.DB_NAME
    version = novacut.__version__
    title = 'Novacut Video Editor'
    splash = 'splash.html'
    page = 'projects.html'

    proxy_bus = 'org.freedesktop.Dmedia'

    maximize = True

    # For using gtk-recordmydesktop with the select window option:
    # This results in a video that's 1280x720
#    maximize = False
#    width = 1264
#    height = 672

    signals = {
        'create_project': ['title'],
        'project_created': ['project_id'],
        'load_project': ['project_id'],
        'copy_docs': ['src_db_name', 'dst_db_name', 'doc_ids'],
        'thumbnail': ['file_id', 'frames'],
        'thumbnail_finished': ['file_id'],

        'hash_edit': ['project_id', 'node_id'],
        'edit_hashed': ['project_id', 'node_id', 'intrinsic_id'],

        'hash_job': ['intrinsic_id', 'settings_id'],
        'job_hashed': ['intrinsic_id', 'settings_id', 'job_id'],

        'render_job': ['job_id'],
        'job_rendered': ['job_id', 'file_id', 'link'],
 	'delete_project': ['project_id'],
 	'sos_project': ['project_id'],
    }

    __Renderer = None

    @property
    def Renderer(self):
        if self.__Renderer is None:
            self.__Renderer = session.get_object('com.novacut.Renderer', '/')
            self.__Renderer.connect_to_signal('ThumbnailFinished', self.on_ThumbnailFinished)
            self.__Renderer.connect_to_signal('EditHashed', self.on_EditHashed)
            self.__Renderer.connect_to_signal('JobHashed', self.on_JobHashed)
            self.__Renderer.connect_to_signal('JobRendered', self.on_JobRendered)
        return self.__Renderer

    def on_ThumbnailFinished(self, file_id):
        self.hub.send('thumbnail_finished', file_id)

    def on_EditHashed(self, project_id, node_id, intrinsic_id):
        self.hub.send('edit_hashed', project_id, node_id, intrinsic_id)

    def on_JobHashed(self, intrinsic_id, settings_id, job_id):
        self.hub.send('job_hashed', intrinsic_id, settings_id, job_id)

    def on_JobRendered(self, job_id, file_id, link):
        self.hub.send('job_rendered', job_id, file_id, link)

    def connect_hub_signals(self, hub):
        hub.connect('create_project', self.on_create_project)
        hub.connect('load_project', self.on_load_project)
        hub.connect('copy_docs', self.on_copy_docs)
        hub.connect('thumbnail', self.on_thumbnail)
        hub.connect('hash_edit', self.on_hash_edit)
        hub.connect('hash_job', self.on_hash_job)
        hub.connect('render_job', self.on_render_job)
        hub.connect('delete_project', self.on_delete_project)
        hub.connect('sos_project', self.on_sos_project)

    def post_env_init(self):
        init_views(self.db, views.novacut_main)

    def dmedia_resolver(self, uri):
        return self.proxy.ResolveURI(uri)

    def on_create_project(self, hub, title):
        print('create_project', title)
        doc = schema.create_project(title)
        self.db.post(doc)
        project = self.server.database(doc['db_name'])
        project.put(None)  # Create DB
        project.post(doc)
        init_views(project, views.novacut_projects)
        self.load_page('bucket.html#' + doc['_id'])
        #self.hub.send('project_created', doc['_id'])

    def on_delete_project(self, hub, project_id):
        print('delete_project', project_id)
        doc = self.db.get(project_id)		
       	doc['isdeleted'] = True
        self.db.post(doc)

    def on_sos_project(self,hub,project_id):
        print('sos_project', project_id)
        doc = self.db.get(project_id)
        print(doc)
       	doc['isdeleted'] = False
        self.db.post(doc)
	

    def on_load_project(self, hub, project_id):
        print('load_project', project_id)
        doc = self.db.get(project_id)
        doc['atime'] = time.time()
        self.db.save(doc)
        db = self.server.database(schema.project_db_name(project_id))
        init_views(db, views.novacut_projects)
        self.load_page('bucket.html#' + project_id)

    def on_copy_docs(self, hub, src_db, dst_db, doc_ids):
        assert isinstance(doc_ids, list)
        docs = []
        for _id in doc_ids:
            doc = self.server.get(src_db, _id, attachments=True)
            del doc['_rev']
            docs.append(doc)
        self.server.post({'docs': docs}, dst_db, '_bulk_docs')

    def on_thumbnail(self, hub, file_id, frames):
        self.Renderer.Thumbnail(file_id, frames)

    def on_hash_edit(self, hub, project_id, root_id):
        print('hash_edit', project_id, root_id)
        self.Renderer.HashEdit(project_id, root_id)

    def on_hash_job(self, hub, intrinsic_id, settings_id):
        print('hash_job', intrinsic_id, settings_id)
        if settings_id is None:
            settings = default_settings()
            settings_id = settings['_id']
            try:
                self.db.save(settings)
            except Conflict:
                pass
        self.Renderer.HashJob(intrinsic_id, settings_id)

    def on_render_job(self, hub, job_id):
        print('render_job', job_id)
        job = self.db.get(job_id)
        if job.get('renders'):
            file_id = list(job['renders'])[0]
            print('using existing render', file_id)
            self.hub.send('job_rendered', job_id, file_id, '')
            return
        self.Renderer.RenderJob(job_id)

app = App()
app.run()