Skip to content

Commit 8ad96fb

Browse files
author
Chris Greenshields
committed
Script to create an MPEG-4 (.mp4) video from PNG-format images
1 parent 80b9cdd commit 8ad96fb

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

bin/foamCreateVideo

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/sh
2+
#------------------------------------------------------------------------------
3+
# ========= |
4+
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5+
# \\ / O peration |
6+
# \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
7+
# \\/ M anipulation |
8+
#-------------------------------------------------------------------------------
9+
# License
10+
# This file is part of OpenFOAM.
11+
#
12+
# OpenFOAM is free software: you can redistribute it and/or modify it
13+
# under the terms of the GNU General Public License as published by
14+
# the Free Software Foundation, either version 3 of the License, or
15+
# (at your option) any later version.
16+
#
17+
# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20+
# for more details.
21+
#
22+
# You should have received a copy of the GNU General Public License
23+
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24+
#
25+
# Script
26+
# foamCreateVideo
27+
#
28+
# Description
29+
# Creates an MPEG-4 compressed (.mp4) video file from PNG images
30+
# - requires mencoder
31+
#
32+
#------------------------------------------------------------------------------
33+
34+
usage () {
35+
exec 1>&2
36+
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
37+
cat <<USAGE
38+
39+
Usage: ${0##*/} [OPTIONS] ...
40+
options:
41+
-d | -dir <dir> directory containing png images (default local dir)
42+
-f | -fps <fps> frames per second (default = 10)
43+
-h | -help help
44+
-i | -image <name> name of image sequence (default = image)
45+
-o | -out <name> name of output video file (default = video)
46+
47+
Creates an MPEG-4 compressed (.mp4) video file from a sequence of PNG images
48+
- A sequence named "image" will expect files image.0000.png, image.0001.png, etc
49+
- An output video named "video" will produce a file video.mp4
50+
- By default the video codec is high resolution (x264) but there is an option to
51+
select a medium resolution codec (lavc)
52+
53+
Requires mencoder
54+
55+
USAGE
56+
exit 1
57+
}
58+
59+
60+
# Default settings
61+
DIR='.'
62+
IMAGE='image'
63+
VIDEO='video'
64+
FPS=10
65+
VCODEC=x264
66+
67+
68+
while [ "$#" -gt 0 ]
69+
do
70+
case "$1" in
71+
-h | -help)
72+
usage
73+
;;
74+
-d | -directory)
75+
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
76+
DIR=$2
77+
shift 2
78+
;;
79+
-f | -fps)
80+
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
81+
FPS=$2
82+
shift 2
83+
;;
84+
-i | -image)
85+
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
86+
IMAGE=$2
87+
shift 2
88+
;;
89+
-o | -out)
90+
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
91+
VIDEO=$2
92+
shift 2
93+
;;
94+
-*)
95+
usage "invalid option '$1'"
96+
;;
97+
*)
98+
break
99+
;;
100+
esac
101+
done
102+
103+
#
104+
# MAIN
105+
#
106+
107+
[ -f "$(ls -1 $DIR/$IMAGE.*.png | head -1)" ] || usage "Cannot find first file in image sequence"
108+
109+
if command -v mencoder >/dev/null 2>&1; then
110+
mencoder \
111+
"mf://$DIR/$IMAGE.*.png" \
112+
-mf fps=$FPS \
113+
-o $VIDEO.mp4 \
114+
-ovc $VCODEC
115+
else
116+
usage "Please install mencoder"
117+
fi

0 commit comments

Comments
 (0)