Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

jinja2 dependency overkill killed

  • Loading branch information...
commit ddf08e2bb50e02f4cee0ff02fe9985248ab61109 1 parent fa0b6db
@jabbalaci authored
View
9 README.md
@@ -12,6 +12,7 @@ Get a static FFmpeg build from <http://ffmpeg.gusari.org/static/>.
This mini project was inspired by the LUD-Media-Converter
(<https://github.com/kunaldeo/LUD-Media-Converter>).
+
Usage:
------
@@ -23,4 +24,10 @@ called `movie-resized.mp4`. You can change the ffmpeg settings
by adjusting the `config` dictionary in the source.
You can also pass *several* parameters to the script and they
-will be processed one by one in a queue.
+will be processed one by one in a queue.
+
+
+Contributions:
+--------------
+
+* Bulkan Evcimen (<https://github.com/bulkan>)
View
15 movie2android.py
@@ -32,7 +32,6 @@
import os
import sys
import termcolor
-from jinja2 import Environment
config = {
@@ -43,12 +42,10 @@
'threads': '2'
}
-command = """{{ ffmpeg }} -i {input} -codec:v libx264 -quality good -cpu-used 0
--b:v {{ bitrate }} -profile:v baseline -level 30 -y -maxrate 2000k
--bufsize 2000k -vf scale={{ width }}:{{ height }} -threads {{ threads }} -codec:a libvo_aacenc
--b:a 128k {output}""".replace('\n', ' ')
-
-command = Environment().from_string(command).render(config)
+command = """{ffmpeg} -i %(input)s -codec:v libx264 -quality good -cpu-used 0
+-b:v {bitrate} -profile:v baseline -level 30 -y -maxrate 2000k
+-bufsize 2000k -vf scale={width}:{height} -threads {threads} -codec:a libvo_aacenc
+-b:a 128k %(output)s""".replace('\n', ' ').format(**config)
def resize(fname):
@@ -63,7 +60,7 @@ def resize(fname):
print termcolor.colored('Warning: the file {0} exists!'.format(output), "red")
return
# else
- cmd = command.format(input=fname, output=output)
+ cmd = command % {'input': fname, 'output': output}
print termcolor.colored(cmd, "green")
os.system(cmd)
@@ -77,7 +74,7 @@ def main(movies):
if __name__ == "__main__":
if len(sys.argv) < 2:
- print "Usage: {0} <movie>".format(sys.argv[0])
+ print "Usage: {0} <movie>".format(os.path.split(sys.argv[0])[1])
sys.exit(1)
else:
main(sys.argv[1:])
View
2  old/README
@@ -0,0 +1,2 @@
+In this version we used jinja2 for formatting.
+This dependency was removed in newer versions.
View
83 old/movie2android-old.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+
+"""
+movie2android
+=============
+
+* Author: Laszlo Szathmary, 2013 (<jabba.laci@gmail.com>)
+* Website: <https://ubuntuincident.wordpress.com/2013/02/26/resize-movies-for-androidios-with-ffmpeg/>
+* GitHub: <https://github.com/jabbalaci/movie2android>
+
+Resize a movie for your Android/iOS device with ffmpeg.
+
+Get a static FFmpeg build from <http://ffmpeg.gusari.org/static/>.
+
+This mini project was inspired by the LUD-Media-Converter
+(<https://github.com/kunaldeo/LUD-Media-Converter>).
+
+Usage:
+------
+
+ ./movie2android.py movie.avi
+
+It will resize the movie and produce a `movie.mp4` file.
+If the input was called `movie.mp4`, the output will be
+called `movie-resized.mp4`. You can change the ffmpeg settings
+by adjusting the `config` dictionary in the source.
+
+You can also pass *several* parameters to the script and they
+will be processed one by one in a queue.
+"""
+
+import os
+import sys
+import termcolor
+from jinja2 import Environment
+
+
+config = {
+ 'ffmpeg': '/opt/ffmpeg.static/ffmpeg',
+ 'bitrate': '600k',
+ 'width': '480',
+ 'height': '320',
+ 'threads': '2'
+}
+
+command = """{{ ffmpeg }} -i {input} -codec:v libx264 -quality good -cpu-used 0
+-b:v {{ bitrate }} -profile:v baseline -level 30 -y -maxrate 2000k
+-bufsize 2000k -vf scale={{ width }}:{{ height }} -threads {{ threads }} -codec:a libvo_aacenc
+-b:a 128k {output}""".replace('\n', ' ')
+
+command = Environment().from_string(command).render(config)
+
+
+def resize(fname):
+ """
+ Resize the current video file with ffmpeg.
+ """
+ fileBaseName = os.path.splitext(fname)[0]
+ output = fileBaseName+'.mp4'
+ if os.path.isfile(output):
+ output = "{0}-resized.mp4".format(fileBaseName)
+ if os.path.isfile(output):
+ print termcolor.colored('Warning: the file {0} exists!'.format(output), "red")
+ return
+ # else
+ cmd = command.format(input=fname, output=output)
+ print termcolor.colored(cmd, "green")
+ os.system(cmd)
+
+
+def main(movies):
+ """process each argument"""
+ for movie in movies:
+ resize(movie)
+
+#############################################################################
+
+if __name__ == "__main__":
+ if len(sys.argv) < 2:
+ print "Usage: {0} <movie>".format(os.path.split(sys.argv[0])[1])
+ sys.exit(1)
+ else:
+ main(sys.argv[1:])
Please sign in to comment.
Something went wrong with that request. Please try again.