Skip to content

Commit

Permalink
Burnin adapter (#167)
Browse files Browse the repository at this point in the history
* Uses ffmpeg to burn text overlays into the media based on metadata in each clip.
* Added Pillow (PIP) to travis' pip install to support this.
  • Loading branch information
repsac authored and jminor committed Oct 5, 2017
1 parent c4916c7 commit 9e7eeda
Show file tree
Hide file tree
Showing 6 changed files with 616 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ python:
- "3.5" - "3.5"


install: install:
- pip install pep8 pyflakes flake8 coverage - pip install pep8 pyflakes flake8 coverage Pillow


script: script:
- make lint - make lint
Expand Down
1 change: 1 addition & 0 deletions LICENSE.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -173,3 +173,4 @@
incurred by, or claims asserted against, such Contributor by reason incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability. of your accepting any such warranty or additional liability.


OpenTimelineIO bundles ffmpeg_burnins.py, which is available under the MIT License. For details contrib/adapters.
89 changes: 89 additions & 0 deletions contrib/adapters/burnins.py
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,89 @@
#
# Copyright 2017 Pixar Animation Studios
#
# Licensed under the Apache License, Version 2.0 (the "Apache License")
# with the following modification; you may not use this file except in
# compliance with the Apache License and the following modification to it:
# Section 6. Trademarks. is deleted and replaced with:
#
# 6. Trademarks. This License does not grant permission to use the trade
# names, trademarks, service marks, or product names of the Licensor
# and its affiliates, except as required to comply with Section 4(c) of
# the License and to reproduce the content of the NOTICE file.
#
# You may obtain a copy of the Apache License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#
"""FFMPEG Burnins Adapter"""
import os
import sys


def build_burnins(input_otio):
"""
Generates the burnin objects for each clip within the otio container
:param input_otio: OTIO container
:rtype: [ffmpeg_burnins.Burnins(), ...]
"""

if os.path.dirname(__file__) not in sys.path:
sys.path.append(os.path.dirname(__file__))

import ffmpeg_burnins
key = 'burnins'

burnins = []
for clip in input_otio.each_clip():

# per clip burnin data
burnin_data = clip.media_reference.metadata.get(key)
if not burnin_data:
# otherwise default to global burnin
burnin_data = input_otio.metadata.get(key)

if not burnin_data:
continue

media = clip.media_reference.target_url
if media.startswith('file://'):
media = media[7:]
streams = burnin_data.get('streams')
burnins.append(ffmpeg_burnins.Burnins(media,
streams=streams))
burnins[-1].otio_media = media
burnins[-1].otio_overwrite = burnin_data.get('overwrite')
burnins[-1].otio_args = burnin_data.get('args')

for burnin in burnin_data.get('burnins', []):
align = burnin.pop('align')
function = burnin.pop('function')
if function == 'text':
text = burnin.pop('text')
options = ffmpeg_burnins.TextOptions()
options.update(burnin)
burnins[-1].add_text(text, align, options=options)
elif function == 'frame_number':
options = ffmpeg_burnins.FrameNumberOptions()
options.update(burnin)
burnins[-1].add_frame_numbers(align, options=options)
else:
raise RuntimeError("Unknown function '%s'" % function)

return burnins


def write_to_file(input_otio, filepath):
"""required OTIO function hook"""

for burnin in build_burnins(input_otio):
burnin.render(os.path.join(filepath, burnin.otio_media),
args=burnin.otio_args,
overwrite=burnin.otio_overwrite)
7 changes: 7 additions & 0 deletions contrib/adapters/contrib_adapters.plugin_manifest.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
"execution_scope" : "in process", "execution_scope" : "in process",
"filepath" : "ale.py", "filepath" : "ale.py",
"suffixes" : ["ale"] "suffixes" : ["ale"]
},
{
"OTIO_SCHEMA" : "Adapter.1",
"name" : "burnins",
"execution_scope" : "in process",
"filepath" : "burnins.py",
"suffixes" : []
} }
] ]
} }
Loading

0 comments on commit 9e7eeda

Please sign in to comment.