]> git.parisson.com Git - telemeta.git/commitdiff
add kdenlive scripts from promaster
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 8 Apr 2013 10:28:17 +0000 (12:28 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 8 Apr 2013 10:28:17 +0000 (12:28 +0200)
telemeta/util/kdenlive/auto_fade.py [new file with mode: 0644]
telemeta/util/kdenlive/auto_fade_batch.py [new file with mode: 0644]
telemeta/util/kdenlive/fade.py [new file with mode: 0644]
telemeta/util/kdenlive/mlt_threads.sh [new file with mode: 0644]
telemeta/util/kdenlive/process_batch.py [new file with mode: 0644]

diff --git a/telemeta/util/kdenlive/auto_fade.py b/telemeta/util/kdenlive/auto_fade.py
new file mode 100644 (file)
index 0000000..342a465
--- /dev/null
@@ -0,0 +1,13 @@
+
+import sys
+from fade import AutoFade
+
+if __name__ == '__main__':
+    path = sys.argv[-1]
+    fade = AutoFade(path)
+    data = fade.run()
+    f = open(path, 'w')
+    f.write(data)
+    f.close()
+
+
diff --git a/telemeta/util/kdenlive/auto_fade_batch.py b/telemeta/util/kdenlive/auto_fade_batch.py
new file mode 100644 (file)
index 0000000..4cf29d3
--- /dev/null
@@ -0,0 +1,19 @@
+
+import os, sys
+from fade import AutoFade
+
+if __name__ == '__main__':
+    dir = sys.argv[-2]
+    ext = sys.argv[-1]
+
+    for filename in os.listdir(dir):
+        prefix, extension = os.path.splitext(filename)
+        path = dir + os.sep + filename
+        flag = path + '.faded'
+        if ext in extension and not os.path.exists(flag):
+            fade = AutoFade(path)
+            data = fade.run()
+            f = open(path, 'w')
+            f.write(data)
+            f.close()
+            os.system('touch ' + flag)
diff --git a/telemeta/util/kdenlive/fade.py b/telemeta/util/kdenlive/fade.py
new file mode 100644 (file)
index 0000000..d6b2921
--- /dev/null
@@ -0,0 +1,199 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2012-2013 Guillaume Pellerin <yomguy@parisson.com>
+
+# This file is part of TimeSide.
+
+# TimeSide 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 2 of the License, or
+# (at your option) any later version.
+
+# TimeSide 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 TimeSide.  If not, see <http://www.gnu.org/licenses/>.
+
+# Author: Guillaume Pellerin <yomguy@parisson.com>
+
+
+from xmltodict2 import *
+
+
+class AutoFade(object):
+    """ Automatically applies a fade in and a fade out trasitions between each segment of a KdenLive session.
+        Each video clip needs to be splitted into one video track and an audio one ("Split audio"),
+        so that an audio fade in/out is also applied.
+
+        MLT files are also supported.
+    """
+
+    def __init__(self, path, audio_frames_out=2, audio_frames_in=1,
+                       video_frames_out=3, video_frames_in=3):
+        self.audio_frames_in = audio_frames_in
+        self.audio_frames_out = audio_frames_out
+        self.video_frames_in = video_frames_in
+        self.video_frames_out = video_frames_out
+        self.path = path
+        self.session = xmltodict(self.path)
+
+    def audio_fade_out(self, frame_out):
+        child = {'attributes': {u'id': u'fadeout',
+        u'in': unicode(int(frame_out)-self.audio_frames_out),
+        u'out': unicode(frame_out)},
+       'children': [{'attributes': {u'name': u'track'},
+         'cdata': '0',
+         'name': 'property'},
+        {'attributes': {u'name': u'window'},
+         'cdata': '75',
+         'name': 'property'},
+        {'attributes': {u'name': u'max_gain'},
+         'cdata': '20dB',
+         'name': 'property'},
+        {'attributes': {u'name': u'mlt_type'},
+         'cdata': 'filter',
+         'name': 'property'},
+        {'attributes': {u'name': u'mlt_service'},
+         'cdata': 'volume',
+         'name': 'property'},
+        {'attributes': {u'name': u'kdenlive_id'},
+         'cdata': 'fadeout',
+         'name': 'property'},
+        {'attributes': {u'name': u'tag'},
+         'cdata': 'volume',
+         'name': 'property'},
+        {'attributes': {u'name': u'kdenlive_ix'},
+         'cdata': '1',
+         'name': 'property'},
+        {'attributes': {u'name': u'gain'}, 'cdata': '1', 'name': 'property'},
+        {'attributes': {u'name': u'end'}, 'cdata': '0', 'name': 'property'}],
+       'name': 'filter'}
+
+        return child
+
+    def audio_fade_in(self, frame_in):
+        child = {'attributes': {u'id': u'fadein',
+        u'in': unicode(frame_in),
+        u'out': unicode(int(frame_in)+self.audio_frames_in)},
+       'children': [{'attributes': {u'name': u'track'},
+         'cdata': '0',
+         'name': 'property'},
+        {'attributes': {u'name': u'window'},
+         'cdata': '75',
+         'name': 'property'},
+        {'attributes': {u'name': u'max_gain'},
+         'cdata': '20dB',
+         'name': 'property'},
+        {'attributes': {u'name': u'mlt_type'},
+         'cdata': 'filter',
+         'name': 'property'},
+        {'attributes': {u'name': u'mlt_service'},
+         'cdata': 'volume',
+         'name': 'property'},
+        {'attributes': {u'name': u'kdenlive_id'},
+         'cdata': 'fadein',
+         'name': 'property'},
+        {'attributes': {u'name': u'tag'},
+         'cdata': 'volume',
+         'name': 'property'},
+        {'attributes': {u'name': u'kdenlive_ix'},
+         'cdata': '1',
+         'name': 'property'},
+        {'attributes': {u'name': u'gain'}, 'cdata': '0', 'name': 'property'},
+        {'attributes': {u'name': u'end'}, 'cdata': '1', 'name': 'property'}],
+       'name': 'filter'}
+
+        return child
+
+
+    def video_fade_out(self, frame_out):
+        child = {'attributes': {u'id': u'fade_to_black',
+        u'in': unicode(int(frame_out)-self.video_frames_out),
+        u'out': unicode(frame_out)},
+       'children': [{'attributes': {u'name': u'track'},
+         'cdata': '0',
+         'name': 'property'},
+        {'attributes': {u'name': u'start'}, 'cdata': '1', 'name': 'property'},
+        {'attributes': {u'name': u'mlt_type'},
+         'cdata': 'filter',
+         'name': 'property'},
+        {'attributes': {u'name': u'mlt_service'},
+         'cdata': 'brightness',
+         'name': 'property'},
+        {'attributes': {u'name': u'kdenlive_id'},
+         'cdata': 'fade_to_black',
+         'name': 'property'},
+        {'attributes': {u'name': u'tag'},
+         'cdata': 'brightness',
+         'name': 'property'},
+        {'attributes': {u'name': u'kdenlive_ix'},
+         'cdata': '1',
+         'name': 'property'},
+        {'attributes': {u'name': u'end'}, 'cdata': '0', 'name': 'property'}],
+       'name': 'filter'}
+
+        return child
+
+
+    def video_fade_in(self, frame_in):
+        child = {'attributes': {u'id': u'fade_from_black',
+        u'in': unicode(frame_in),
+        u'out': unicode(int(frame_in)+self.video_frames_in)},
+       'children': [{'attributes': {u'name': u'track'},
+         'cdata': '0',
+         'name': 'property'},
+        {'attributes': {u'name': u'start'}, 'cdata': '0', 'name': 'property'},
+        {'attributes': {u'name': u'mlt_type'},
+         'cdata': 'filter',
+         'name': 'property'},
+        {'attributes': {u'name': u'mlt_service'},
+         'cdata': 'brightness',
+         'name': 'property'},
+        {'attributes': {u'name': u'kdenlive_id'},
+         'cdata': 'fade_from_black',
+         'name': 'property'},
+        {'attributes': {u'name': u'tag'},
+         'cdata': 'brightness',
+         'name': 'property'},
+        {'attributes': {u'name': u'kdenlive_ix'},
+         'cdata': '1',
+         'name': 'property'},
+        {'attributes': {u'name': u'end'}, 'cdata': '1', 'name': 'property'}],
+       'name': 'filter'}
+
+        return child
+
+    def run(self):
+        audio_count = 0
+        video_count = 0
+
+        for attr in self.session['children']:
+            if 'playlist' in attr['name'] and 'children' in attr:
+                for att in attr['children']:
+                    if 'producer' in att['attributes']:
+                        producer = att['attributes']['producer']
+                        if producer != 'black':
+                            frame_in = att['attributes']['in']
+                            frame_out = att['attributes']['out']
+
+                            if 'audio' in producer:
+                                if not audio_count % 2:
+                                    att['children'] = [self.audio_fade_out(frame_out)]
+                                else:
+                                    att['children'] = [self.audio_fade_in(frame_in)]
+                                audio_count += 1
+
+
+                            if 'video' in producer:
+                                if not video_count % 2:
+                                    att['children'] = [self.video_fade_out(frame_out)]
+                                else:
+                                    att['children'] = [self.video_fade_in(frame_in)]
+                                video_count += 1
+
+        return dicttoxml(self.session).encode('utf-8')
+
+
diff --git a/telemeta/util/kdenlive/mlt_threads.sh b/telemeta/util/kdenlive/mlt_threads.sh
new file mode 100644 (file)
index 0000000..cf2c279
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+for file in `ls $1/*.sh`; do
+sudo perl -pi -e 's/threads=2/threads=8/g' $1/$file 
+sudo perl -pi -e 's/threads=4/threads=8/g' $1/$file
+sudo perl -pi -e 's/threads=6/threads=8/g' $1/$file
+done
diff --git a/telemeta/util/kdenlive/process_batch.py b/telemeta/util/kdenlive/process_batch.py
new file mode 100644 (file)
index 0000000..b620ffd
--- /dev/null
@@ -0,0 +1,13 @@
+
+import os, sys
+
+if __name__ == '__main__':
+    dir = sys.argv[-1]
+
+    for filename in os.listdir(dir):
+        prefix, extension = os.path.splitext(filename)
+        path = dir + os.sep + filename
+        flag = path + '.processed'
+        if 'sh' in extension and not os.path.exists(flag):
+            os.system('nice -n 19 ' + path)
+            os.system('touch ' + flag)