Skip to content

Commit

Permalink
Merge branch 'add-credits'
Browse files Browse the repository at this point in the history
  • Loading branch information
jhenstridge committed Dec 27, 2020
2 parents 9e9127a + b31a006 commit 0644651
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 13 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ Editing Services project.

It takes the following optional parameters to influence the project:

* `--start=SECONDS` and `--end=SECONDS` can be used to trim footage from the start or end of the recording. This can be helpful if the recording was started early, or you want to split the recoridng into multiple projects.
* `--width=WIDTH` and `--height=HEIGHT` control the dimensions of the video. The default resolution is 1920x1080.
* `--webcam-size=PERCENT` controls how much of the frame width will be devoted to the webcam footage. This defaults to 20%.
* `--stretch-webcam` stretches the webcam footage by 33%. This was added to correct the camera aspect ratio in some of our recordings.
* `--backdrop=FILE` sets a still image to place behind other elements. This can be used to fill in the empty space in the frame.
* `--skip=SECONDS` allows you to skip ahead from the beginning of the recording. This is useful if recording was started before the actual presentation.
* `--opening-credits=FILE[:DURATION]` and `--closing-credits=FILE[:DURATION]` will add credits to project. These can either be videos or still images (which will default to 3 seconds duration). These options can be repeated to add multiple credits.

Currently the project includes the following aspects of the BBB
recording:
Expand Down
85 changes: 73 additions & 12 deletions make-xges.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, opts):
# Construct the presentation
self.set_track_caps()
self.set_project_metadata()
self.add_credits()
self.add_webcams()
self.add_slides()
self.add_deskshare()
Expand Down Expand Up @@ -68,12 +69,13 @@ def _constrain(self, dimensions, bounds):
return round(width * max_height / height), max_height

def _add_clip(self, layer, asset, start, inpoint, duration,
posx, posy, width, height):
# Skip clips entirely after the end point
if start > self.end_time:
return
# Truncate clips that go past the end point
duration = min(duration, self.end_time - start)
posx, posy, width, height, trim_end=True):
if trim_end:
# Skip clips entirely after the end point
if start > self.end_time:
return
# Truncate clips that go past the end point
duration = min(duration, self.end_time - start)

# Skip clips entirely before the start point
if start + duration < self.start_time:
Expand All @@ -86,6 +88,9 @@ def _add_clip(self, layer, asset, start, inpoint, duration,
inpoint += -start
start = 0

# Offset start point by the length of the opening credits
start += self.opening_length

clip = layer.add_asset(asset, start, inpoint, duration,
GES.TrackType.UNKNOWN)
for element in clip.find_track_elements(
Expand Down Expand Up @@ -121,6 +126,9 @@ def set_track_caps(self):
else:
self.end_time = round(self.opts.end * Gst.SECOND)

# Offset for the opening credits
self.opening_length = 0

# Add an encoding profile for the benefit of Pitivi
profile = GstPbutils.EncodingContainerProfile.new(
'MP4', 'bbb-render encoding profile',
Expand Down Expand Up @@ -202,16 +210,63 @@ def add_deskshare(self):
def add_backdrop(self):
if not self.opts.backdrop:
return
# Get duration of webcam footage
webcams_asset = self._get_asset(
os.path.join(self.opts.basedir, 'video/webcams.webm'))
duration = webcams_asset.props.duration

layer = self._add_layer('Backdrop')
asset = self._get_asset(self.opts.backdrop)
self._add_clip(layer, asset, 0, 0, duration,
self._add_clip(layer, asset, 0, 0, self.end_time,
0, 0, self.opts.width, self.opts.height)

def add_credits(self):
if not (self.opts.opening_credits or self.opts.closing_credits):
return

layer = self._add_layer('credits')
for fname in self.opts.opening_credits:
duration = None
if ':' in fname:
fname, duration = fname.rsplit(':', 1)
duration = round(float(duration) * Gst.SECOND)

asset = self._get_asset(fname)
if duration is None:
if asset.is_image():
duration = 3 * Gst.SECOND
else:
duration = asset.props.duration

dims = self._get_dimensions(asset)

dims = self._get_dimensions(asset)
width, height = self._constrain(
dims, (self.opts.width, self.opts.height))

self._add_clip(layer, asset, 0, 0, duration,
0, 0, width, height, trim_end=False)
self.opening_length += duration

closing_length = 0
for fname in self.opts.closing_credits:
duration = None
if ':' in fname:
fname, duration = fname.rsplit(':', 1)
duration = round(float(duration) * Gst.SECOND)

asset = self._get_asset(fname)
if duration is None:
if asset.is_image():
duration = 3 * Gst.SECOND
else:
duration = asset.props.duration

dims = self._get_dimensions(asset)

dims = self._get_dimensions(asset)
width, height = self._constrain(
dims, (self.opts.width, self.opts.height))

self._add_clip(layer, asset, self.end_time + closing_length, 0,
duration, 0, 0, width, height, trim_end=False)
closing_length += duration

def save(self):
self.timeline.commit_sync()
self.timeline.save_to_uri(file_to_uri(self.opts.project), None, True)
Expand All @@ -234,6 +289,12 @@ def main(argv):
help='Stretch webcam to 16:9 aspect ratio')
parser.add_argument('--backdrop', metavar='FILE', type=str, default=None,
help='Backdrop image for the project')
parser.add_argument('--opening-credits', metavar='FILE[:DURATION]',
type=str, action='append', default=[],
help='File to use as opening credits (may be repeated)')
parser.add_argument('--closing-credits', metavar='FILE[:DURATION]',
type=str, action='append', default=[],
help='File to use as closing credits (may be repeated)')
parser.add_argument('basedir', metavar='PRESENTATION-DIR', type=str,
help='directory containing BBB presentation assets')
parser.add_argument('project', metavar='OUTPUT', type=str,
Expand Down

0 comments on commit 0644651

Please sign in to comment.