1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
21 # Originally written by Matt Ebb
24 from bpy.types import Operator
28 def guess_player_path(preset):
31 if preset == 'BLENDER24':
32 player_path = "blender"
34 if sys.platform == "darwin":
35 test_path = "/Applications/blender 2.49.app/Contents/MacOS/blender"
36 elif sys.platform[:3] == "win":
37 test_path = "/Program Files/Blender Foundation/Blender/blender.exe"
39 if os.path.exists(test_path):
40 player_path = test_path
43 player_path = "djv_view"
45 if sys.platform == "darwin":
46 # TODO, crummy supporting only 1 version,
47 # could find the newest installed version
48 test_path = ("/Applications/djv-0.8.2.app"
49 "/Contents/Resources/bin/djv_view")
50 if os.path.exists(test_path):
51 player_path = test_path
53 elif preset == 'FRAMECYCLER':
54 player_path = "framecycler"
59 elif preset == 'MPLAYER':
60 player_path = "mplayer"
68 class PlayRenderedAnim(Operator):
69 '''Plays back rendered frames/movies using an external player.'''
70 bl_idname = "render.play_rendered_anim"
71 bl_label = "Play Rendered Animation"
72 bl_options = {'REGISTER'}
74 def execute(self, context):
79 prefs = context.user_preferences
81 preset = prefs.filepaths.animation_player_preset
82 player_path = prefs.filepaths.animation_player
83 # file_path = bpy.path.abspath(rd.filepath) # UNUSED
84 is_movie = rd.is_movie_format
86 # try and guess a command line if it doesn't exist
88 player_path = guess_player_path(preset)
90 if is_movie == False and preset in {'FRAMECYCLER', 'RV', 'MPLAYER'}:
91 # replace the number with '#'
92 file_a = rd.frame_path(frame=0)
94 # TODO, make an api call for this
96 file_b = rd.frame_path(frame=frame_tmp)
98 while len(file_a) == len(file_b):
99 frame_tmp = (frame_tmp * 10) + 9
100 file_b = rd.frame_path(frame=frame_tmp)
101 file_b = rd.frame_path(frame=int(frame_tmp / 10))
103 file = ("".join((c if file_b[i] == c else "#")
104 for i, c in enumerate(file_a)))
106 # works for movies and images
107 file = rd.frame_path(frame=scene.frame_start)
109 file = bpy.path.abspath(file) # expand '//'
112 # extra options, fps controls etc.
113 if preset == 'BLENDER24':
114 # -----------------------------------------------------------------
115 # Check blender is not 2.5x until it supports playback again
117 process = subprocess.Popen([player_path, '--version'],
118 stdout=subprocess.PIPE,
121 # ignore and allow the main execution to catch the problem.
124 if process is not None:
126 out = process.stdout.read()
127 process.stdout.close()
128 out_split = out.strip().split()
129 if out_split[0] == b'Blender':
130 if not out_split[1].startswith(b'2.4'):
131 self.report({'ERROR'},
132 "Blender %s doesn't support playback: %r" %
133 (out_split[1].decode(), player_path))
137 # -----------------------------------------------------------------
139 opts = ["-a", "-f", str(rd.fps), str(rd.fps_base), file]
141 elif preset == 'DJV':
142 opts = [file, "-playback_speed", "%d" % int(rd.fps / rd.fps_base)]
144 elif preset == 'FRAMECYCLER':
145 opts = [file, "%d-%d" % (scene.frame_start, scene.frame_end)]
148 opts = ["-fps", str(rd.fps), "-play", "[ %s ]" % file]
150 elif preset == 'MPLAYER':
155 opts += [("mf://%s" % file.replace("#", "?")),
157 "fps=%.4f" % (rd.fps / rd.fps_base),
160 opts += ["-loop", "0", "-really-quiet", "-fs"]
166 print("Executing command:\n %r" % " ".join(cmd))
169 process = subprocess.Popen(cmd)
170 except Exception as e:
172 self.report({'ERROR'},
173 "Couldn't run external animation player with command "
174 "%r\n%s" % (" ".join(cmd), str(e)))