Skip to content

Commit 51a44f1

Browse files
author
David Karchmer
committed
Update to use dkarchmervue/moviepy
1 parent c66f2e4 commit 51a44f1

File tree

5 files changed

+33
-136
lines changed

5 files changed

+33
-136
lines changed

Dockerfile

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM ubuntu:trusty
22

33
# https://github.com/ampervue/docker-ffmpeg-moviepy
4+
# https://hub.docker.com/r/dkarchmervue/moviepy/
45

56
MAINTAINER David Karchmer <dkarchmer@ampervue.com>
67

@@ -212,17 +213,25 @@ RUN ./configure --extra-libs="-ldl" \
212213
&& make install
213214
# =================================
214215

216+
# Install moviepy and related packages
217+
# ====================================
218+
RUN pip install -U numpy==$NUMPY_VERSION
219+
RUN pip install -U Pillow==$PILLOW_VERSION
220+
RUN pip install -U scipy==$SCIPY_VERSION
221+
#RUN pip install -U moviepy==$MOVIEPY_VERSION
222+
223+
# Manually build version that allows control of FFMPEG exe
224+
# See https://github.com/Zulko/moviepy/issues/237
225+
RUN git clone -q https://github.com/dkarchmer/moviepy.git
226+
WORKDIR /usr/local/src/moviepy
227+
RUN python setup.py install
228+
ENV FFMPEG_BINARY auto-detect
215229

216230
# Remove all tmpfile
217231
# =================================
218232
WORKDIR /usr/local/
219233
RUN rm -rf /usr/local/src
220234
# =================================
221235

222-
# Install moviepy and related packages
223-
# ====================================
224-
RUN pip install -U numpy==$NUMPY_VERSION
225-
RUN pip install -U Pillow==$PILLOW_VERSION
226-
RUN pip install -U scipy==$SCIPY_VERSION
227-
RUN pip install -U moviepy==$MOVIEPY_VERSION
236+
228237

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Docker Hub: https://registry.hub.docker.com/u/dkarchmervue/ffmpeg-moviepy/
1616
Source and example: https://github.com/ampervue/ffmpeg-moviepy
1717

1818
~~~~
19-
docker pull dkarchmervue/ffmpeg-moviepy
20-
docker run -ti dkarchmervue/ffmpeg-moviepy
19+
docker pull dkarchmervue/moviepy
20+
docker run -ti dkarchmervue/moviepy
2121
~~~~
2222

2323
## Example
@@ -32,13 +32,13 @@ docker pull dkarchmervue/ffmpeg-moviepy
3232
# Get example files and build new image
3333
git clone https://github.com/ampervue/ffmpeg-moviepy
3434
cd example
35-
docker build -t mosaic .
35+
docker build -t example .
3636
3737
# Mount current directory on container so that file can be written back to host
3838
# Assuming videos are on current directory
39-
docker run --rm -ti -v ${PWD}:/code mosaic video1.mp4 video2.mp4 video3.mp4 video4.mp4
40-
ls mosaic.mp4
39+
docker run --rm -ti -v ${PWD}:/code example
40+
ls hello_world.mp4
4141
4242
# To run with bash
43-
docker run --entrypoint bash -ti thumbnail
43+
docker run --entrypoint bash -ti example
4444
~~~~

example/Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
FROM dkarchmervue/ffmpeg-moviepy
1+
FROM dkarchmervue/moviepy
22

33
# https://github.com/ampervue/ffmpeg-moviepy
4+
# https://hub.docker.com/r/dkarchmervue/moviepy/
45

56
MAINTAINER David Karchmer <dkarchmer@gmail.com>
67

78
# ============================================================================
8-
# As an example, the python script uses moviepy to build a 2x2 mosaic
9-
# based on four videos
9+
# As an example, create a clip with a 'Hello World' title
1010
#
1111
# ~~~~
1212
# # Pull image
13-
# docker pull dkarchmervue/ffmpeg-moviepy
13+
# docker pull dkarchmervue/moviepy
1414
#
1515
# # Get example files and build new image
1616
# git clone https://github.com/ampervue/ffmpeg-moviepy
1717
# cd example
18-
# docker build -t mosaic .
18+
# docker build -t example .
1919
#
2020
# # Mount current directory on container so that file can be written back to host
2121
# # Assuming videos are on current directory
22-
# docker run --rm -ti -v ${PWD}:/code mosaic video1.mp4 video2.mp4 video3.mp4 video4.mp4
23-
# ls mosaic.mp4
22+
# docker run --rm -ti -v ${PWD}:/code example
23+
# ls hello_world.mp4
2424
# ~~~~
2525
# ============================================================================
2626

example/app/script.py

Lines changed: 4 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,7 @@
11
__author__ = 'David Karchmer'
22

3-
import os
4-
import sys
5-
import json
6-
import logging
7-
import argparse
8-
from logging import StreamHandler, Formatter
3+
import moviepy.editor as mpy
94

10-
import moviepy.editor as moviepy
11-
12-
if __name__ == "__main__":
13-
14-
# Logger Format
15-
FORMAT = '[%(asctime)-15s] %(levelname)-6s %(message)s'
16-
DATE_FORMAT = '%d/%b/%Y %H:%M:%S'
17-
formatter = Formatter(fmt=FORMAT, datefmt=DATE_FORMAT)
18-
handler = StreamHandler()
19-
handler.setFormatter(formatter)
20-
logger = logging.getLogger(__name__)
21-
logger.addHandler(handler)
22-
logger.setLevel(logging.DEBUG)
23-
24-
parser = argparse.ArgumentParser(description=__doc__,
25-
formatter_class=argparse.RawDescriptionHelpFormatter)
26-
parser.add_argument('-o', dest='output', type=str, help="Output File", default='stack.mp4')
27-
__author__ = 'dkarchmer'
28-
29-
import os
30-
import sys
31-
import json
32-
import logging
33-
import argparse
34-
from logging import StreamHandler, Formatter
35-
36-
#from moviepy.editor import *
37-
import moviepy.editor as moviepy
38-
39-
40-
if __name__ == "__main__":
41-
42-
# Logger Format
43-
FORMAT = '[%(asctime)-15s] %(levelname)-6s %(message)s'
44-
DATE_FORMAT = '%d/%b/%Y %H:%M:%S'
45-
formatter = Formatter(fmt=FORMAT, datefmt=DATE_FORMAT)
46-
handler = StreamHandler()
47-
handler.setFormatter(formatter)
48-
logger = logging.getLogger(__name__)
49-
logger.addHandler(handler)
50-
logger.setLevel(logging.DEBUG)
51-
52-
parser = argparse.ArgumentParser(description=__doc__,
53-
formatter_class=argparse.RawDescriptionHelpFormatter)
54-
55-
parser.add_argument('-o', dest='output', type=str, help="Output File", default='stack.mp4')
56-
parser.add_argument('videos', metavar='videos', type=str, nargs='+', help='Videos to process')
57-
58-
args = parser.parse_args(sys.argv[1:])
59-
60-
logger.debug('ARGS: ' + str(args))
61-
62-
if not args.jsonfile:
63-
logger.error('Missing required configuration json file')
64-
exit(1)
65-
66-
logger.info('Processing data from Json file: {0}'.format(args.jsonfile))
67-
json_file = video_file = os.path.join(args.indir, args.jsonfile)
68-
if not os.path.isfile(json_file):
69-
logger.error('Json file not found: {0}'.format(json_file))
70-
exit(1)
71-
72-
json_data=open(json_file).read()
73-
data = json.loads(json_data)
74-
logger.info(data)
75-
76-
print('Generate Matrix')
77-
78-
79-
clips = []
80-
for v in data['videos']:
81-
# If we need to resize: clip.fx( resize, width=240)
82-
clips.append(moviepy.VideoFileClip(os.path.join(data['input_dir'], v['file']))
83-
.subclip(v['ss'],v['ss']+60*data['duration']).without_audio().margin(10))
84-
# .set_start(v['ss']).set_duration(30).without_audio().margin(10))
85-
86-
final_clip = moviepy.clips_array([[clips[0], clips[1]], [clips[2], clips[3]]])
87-
88-
final_clip.write_videofile(args.output)
89-
90-
args = parser.parse_args(sys.argv[1:])
91-
92-
logger.debug('ARGS: ' + str(args))
93-
94-
if not args.jsonfile:
95-
logger.error('Missing required configuration json file')
96-
exit(1)
97-
98-
logger.info('Processing data from Json file: {0}'.format(args.jsonfile))
99-
json_file = video_file = os.path.join(args.indir, args.jsonfile)
100-
if not os.path.isfile(json_file):
101-
logger.error('Json file not found: {0}'.format(json_file))
102-
exit(1)
103-
104-
json_data=open(json_file).read()
105-
data = json.loads(json_data)
106-
logger.info(data)
107-
108-
print('Generate Matrix')
109-
110-
111-
clips = []
112-
for v in data['videos']:
113-
# If we need to resize: clip.fx( resize, width=240)
114-
clips.append(moviepy.VideoFileClip(os.path.join(data['input_dir'], v['file']))
115-
.subclip(v['ss'],v['ss']+60*data['duration']).without_audio().margin(10))
116-
# .set_start(v['ss']).set_duration(30).without_audio().margin(10))
117-
118-
final_clip = moviepy.clips_array([[clips[0], clips[1]], [clips[2], clips[3]]])
119-
120-
final_clip.write_videofile(args.output)
5+
hello_world = mpy.TextClip('Hello, World!', fontsize=78, color='white', size=(1280,720))
6+
hello_world = hello_world.set_duration(10)
7+
hello_world.write_videofile('hello_world.mp4', fps=24)

example/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
request

0 commit comments

Comments
 (0)