Skip to content

Commit 3bf4dc8

Browse files
committed
Add asset_width, asset_height and asset_framerate columns to the asset table of the database
The new columns are used to set asset specific size and playback options overriding the bookmark item's values per asset.
1 parent 3a721bd commit 3bf4dc8

File tree

15 files changed

+228
-160
lines changed

15 files changed

+228
-160
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<img src="https://img.shields.io/badge/Python-3.8%2B-lightgrey">
88
<img src="https://img.shields.io/badge/Python-PySide2-lightgrey">
99
<img src="https://img.shields.io/badge/Platform-Windows-lightgrey">
10-
<img src="https://img.shields.io/badge/Version-v0.8.3-green">
10+
<img src="https://img.shields.io/badge/Version-v0.8.4-green">
1111
</p>
1212

1313
<p align="center">

bookmarks/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
.. |label3| image:: https://img.shields.io/badge/Platform-Windows-lightgrey
7777
:height: 18
7878
79-
.. |label4| image:: https://img.shields.io/badge/Version-v0.8.3-green
79+
.. |label4| image:: https://img.shields.io/badge/Version-v0.8.4-green
8080
:height: 18
8181
8282
.. |image1| image:: ./images/active_bookmark.png
@@ -100,7 +100,7 @@
100100
__email__ = '[email protected]'
101101

102102
#: Project version
103-
__version__ = '0.8.3'
103+
__version__ = '0.8.4'
104104

105105
#: Project version
106106
__version_info__ = __version__.split('.')

bookmarks/database.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@
142142
'sql': 'INT',
143143
'type': int
144144
},
145+
'asset_framerate': {
146+
'sql': 'REAL',
147+
'type': float
148+
},
149+
'asset_width': {
150+
'sql': 'INT',
151+
'type': int
152+
},
153+
'asset_height': {
154+
'sql': 'INT',
155+
'type': int
156+
},
145157
'url1': {
146158
'sql': 'TEXT',
147159
'type': str

bookmarks/editor/asset_properties.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ class AssetPropertyEditor(base.BasePropertyEditor):
173173
}
174174
},
175175
2: {
176-
'name': 'Cut',
177-
'icon': 'todo',
176+
'name': 'Settings',
177+
'icon': 'bookmark',
178178
'color': common.color(common.color_dark_background),
179179
'groups': {
180180
0: {
@@ -221,6 +221,33 @@ class AssetPropertyEditor(base.BasePropertyEditor):
221221
'description': 'The frame this asset ends at, e.g. \'1575\'.',
222222
},
223223
},
224+
2: {
225+
0: {
226+
'name': 'Asset frame-rate',
227+
'key': 'asset_framerate',
228+
'validator': base.float_validator,
229+
'widget': ui.LineEdit,
230+
'placeholder': 'Frame-rate, e.g. \'23.976\'',
231+
'description': 'The frame-rate of the asset, e.g. '
232+
'\'25.0\'',
233+
},
234+
1: {
235+
'name': 'Asset width',
236+
'key': 'asset_width',
237+
'validator': base.int_validator,
238+
'widget': ui.LineEdit,
239+
'placeholder': 'Width in pixels',
240+
'description': 'The asset\'s output width in pixels, e.g. \'1920\''
241+
},
242+
2: {
243+
'name': 'Asset height',
244+
'key': 'asset_height',
245+
'validator': base.int_validator,
246+
'widget': ui.LineEdit,
247+
'placeholder': 'Height in pixels',
248+
'description': 'The asset\'s output height in pixels, e.g. \'1080\''
249+
},
250+
},
224251
},
225252
},
226253
3: {
@@ -359,6 +386,29 @@ def init_data(self):
359386
self._set_completer()
360387
self._disable_shotgun()
361388

389+
def init_db_data(self):
390+
super().init_db_data()
391+
392+
# Asset frame-rate, width and height overrides
393+
db = database.get(self.server, self.job, self.root)
394+
for k in ('asset_framerate', 'asset_width', 'asset_height'):
395+
# Skip items that don't have editors
396+
if not hasattr(self, f'{k}_editor'):
397+
raise RuntimeError(f'No editor for {k}!')
398+
399+
v = db.value(self.db_source(), k, database.AssetTable)
400+
# If the value is not set, we'll use the bookmark item's value instead as a
401+
# placeholder for the text editor
402+
if not v:
403+
source = f'{self.server}/{self.job}/{self.root}'
404+
_v = db.value(source, k.replace('asset_', ''), database.BookmarkTable)
405+
if _v is None:
406+
continue
407+
getattr(self, f'{k}_editor').setPlaceholderText(f'{_v}')
408+
409+
410+
411+
362412
def _disable_shotgun(self):
363413
sg_properties = shotgun.SGProperties(
364414
self.server,

bookmarks/editor/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ def _add_row(self, v, grp, _grp):
330330
if k is not None:
331331
setattr(self, f'{_k}_editor', editor)
332332
else:
333-
print(_name)
334333
setattr(self, f'{_name}_editor', editor)
335334

336335
if hasattr(editor, 'setAlignment'):

bookmarks/editor/bookmark_properties.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,13 @@ class BookmarkPropertyEditor(base.BasePropertyEditor):
9191
},
9292
2: {
9393
0: {
94-
'name': 'Framerate',
94+
'name': 'Frame-rate',
9595
'key': 'framerate',
9696
'validator': base.float_validator,
9797
'widget': ui.LineEdit,
98-
'placeholder': 'Framerate, e.g. \'23.976\'',
99-
'description': 'The framerate of the bookmark, eg, '
100-
'\'25.0\'.\n\nUsed by Bookmarks to control the '
101-
'format of scenes inside hosts, e.g. Maya.'
98+
'placeholder': 'Frame-rate, e.g. \'23.976\'',
99+
'description': 'The frame-rate of the bookmark, e.g. '
100+
'\'25.0\'.'
102101
},
103102
1: {
104103
'name': 'Width',

bookmarks/external/ffmpeg.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,22 +248,25 @@ def _output_path_from_seq(seq, ext):
248248
return f'{seq.group(1).rstrip(".").rstrip("_").rstrip()}.{ext}'
249249

250250

251-
def _get_framerate(server, job, root, fallback_framerate=24.0):
251+
def _get_framerate(fallback_framerate=24.0):
252252
"""Get the currently set frame-rate from the bookmark item database.
253253
254254
Returns:
255-
float: The current framerate.
255+
float: The current frame-rate set in the active context.
256256
257257
"""
258-
db = database.get(server, job, root)
259-
v = db.value(
260-
db.source(),
261-
'framerate',
262-
database.BookmarkTable
263-
)
258+
if not all(common.active('root', args=True)):
259+
return fallback_framerate
260+
261+
db = database.get(*common.active('root', args=True))
264262

265-
if not v: # use the fallback value when not set
263+
bookmark_framerate = db.value(common.active('root', path=True),'framerate', database.BookmarkTable)
264+
asset_framerate = db.value(common.active('asset', path=True),'asset_framerate', database.AssetTable)
265+
266+
v = asset_framerate or bookmark_framerate or fallback_framerate
267+
if not isinstance(v, (int, float)) or v < 1.0:
266268
return fallback_framerate
269+
267270
return v
268271

269272

@@ -399,7 +402,7 @@ def convert(
399402
input_path = _input_path_from_seq(seq)
400403
cmd = preset.format(
401404
BIN=ffmpeg_bin,
402-
FRAMERATE=_get_framerate(server, job, root),
405+
FRAMERATE=_get_framerate(),
403406
STARTFRAME=startframe,
404407
INPUT=input_path,
405408
OUTPUT=output_path,

bookmarks/external/ffmpeg_widget.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ def init_data(self):
6666
if not isinstance(data, dict):
6767
return
6868

69+
# Add no-timecode option
70+
self._data[len(self._data)] = {
71+
QtCore.Qt.DisplayRole: 'No timecode',
72+
QtCore.Qt.DecorationRole: None,
73+
QtCore.Qt.SizeHintRole: self.row_size,
74+
QtCore.Qt.StatusTipRole: 'No timecode',
75+
QtCore.Qt.AccessibleDescriptionRole: 'No timecode',
76+
QtCore.Qt.WhatsThisRole: 'No timecode',
77+
QtCore.Qt.ToolTipRole: 'No timecode',
78+
QtCore.Qt.UserRole: None,
79+
}
80+
6981
template = common.settings.value('ffmpeg/timecode_preset')
7082
for v in data[tokens.FFMpegTCConfig].values():
7183
if template == v['name']:
@@ -100,8 +112,7 @@ class TimecodeComboBox(QtWidgets.QComboBox):
100112
def __init__(self, parent=None):
101113
super().__init__(parent=parent)
102114
self.setView(QtWidgets.QListView())
103-
model = TimecodeModel()
104-
self.setModel(model)
115+
self.setModel(TimecodeModel())
105116

106117

107118
class PresetComboBox(QtWidgets.QComboBox):
@@ -139,10 +150,17 @@ def init_data(self):
139150
140151
"""
141152
db = database.get(*common.active('root', args=True))
142-
width = db.value(db.source(), 'width', database.BookmarkTable)
143-
height = db.value(db.source(), 'width', database.BookmarkTable)
153+
bookmark_width = db.value(db.source(), 'width', database.BookmarkTable)
154+
bookmark_height = db.value(db.source(), 'width', database.BookmarkTable)
155+
asset_width = db.value(common.active('asset', path=True), 'asset_width', database.AssetTable)
156+
asset_height = db.value(common.active('asset', path=True), 'asset_height', database.AssetTable)
157+
158+
width = asset_width or bookmark_width or None
159+
height = asset_height or bookmark_height or None
160+
144161
if all((width, height)):
145162
self.addItem(f'Project | {int(height)}p', userData=(width, height))
163+
self.addItem(f'Project | {int(height * 0.5)}p', userData=(int(width * 0.5), int(height * 0.5)))
146164

147165
self.blockSignals(True)
148166
for v in ffmpeg.SIZE_PRESETS.values():
@@ -179,14 +197,6 @@ class FFMpegWidget(base.BasePropertyEditor):
179197
'placeholder': None,
180198
'description': 'Set the output video size.',
181199
},
182-
2: {
183-
'name': 'Add timecode',
184-
'key': 'ffmpeg_add_timecode',
185-
'validator': None,
186-
'widget': functools.partial(QtWidgets.QCheckBox, 'Add Timecode'),
187-
'placeholder': None,
188-
'description': 'Add an informative bar and a timecode.',
189-
},
190200
3: {
191201
'name': 'Timecode preset',
192202
'key': 'ffmpeg_timecode_preset',
@@ -272,7 +282,7 @@ def save_changes(self):
272282
v['preset'] == preset
273283
)
274284

275-
if self.ffmpeg_add_timecode_editor.isChecked():
285+
if self.ffmpeg_timecode_preset_editor.currentData():
276286
destination = f'{seq.group(1).strip().strip("_").strip(".")}' \
277287
f'{seq.group(3).strip().strip("_").strip(".")}_tc.' \
278288
f'{ext}'
@@ -307,15 +317,12 @@ def save_changes(self):
307317
return
308318

309319
timecode_preset = self.ffmpeg_timecode_preset_editor.currentData()
310-
if not timecode_preset:
311-
common.close_message()
312-
raise RuntimeError('No timecode preset was selected.')
313320

314321
mov = ffmpeg.convert(
315322
source_image_paths[0],
316323
self.ffmpeg_preset_editor.currentData(),
317324
size=self.ffmpeg_size_editor.currentData(),
318-
timecode=self.ffmpeg_add_timecode_editor.isChecked(),
325+
timecode=bool(timecode_preset),
319326
timecode_preset=timecode_preset,
320327
output_path=destination,
321328
parent=self

0 commit comments

Comments
 (0)