Welcome to mirror list, hosted at ThFree Co, Russian Federation.

screen_play_rendered_anim.py « op « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a8c97010ccef454876441300a69c3a57eca32a19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Script copyright (C) Campbell J Barton
#
# This program 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.
#
# This program 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 this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****

# <pep8 compliant>

# History
#
# Originally written by Matt Ebb

import bpy
import subprocess
import os
import platform

# from BKE_add_image_extension()
img_format_exts = {
    'IRIS': '.rgb',
    'RADHDR': '.hdr',
    'PNG': 'png',
    'TARGA': 'tga',
    'RAWTARGA': 'tga',
    'BMP': 'bmp',
    'TIFF': 'tif',
    'OPENEXR': 'exr',
    'MULTILAYER': 'exr',
    'CINEON': 'cin',
    'DPX': 'dpx',
    'JPEG': 'jpg',
    'JPEG2000': 'jp2',
    'QUICKTIME_QTKIT': 'mov',
    'QUICKTIME_CARBON': 'mov',
    'AVIRAW': 'avi',
    'AVIJPEG': 'avi',
    'AVICODEC': 'avi',
    'XVID': 'avi',
    'THEORA': 'ogg',
    }

movie_formats = ('QUICKTIME_QTKIT',
                'QUICKTIME_CARBONTKIT',
                'AVIRAW',
                'AVIJPEG',
                'AVICODEC',
                'XVID',
                'THEORA')


def guess_player_path(preset):
    if preset == 'BLENDER24':
        player_path = 'blender'

        if platform.system() == 'Darwin':
            test_path = '/Applications/blender 2.49.app/Contents/MacOS/blender'
        elif platform.system() == 'Windows':
            test_path = '/Program Files/Blender Foundation/Blender/blender.exe'

            if os.path.exists(test_path):
                player_path = test_path

    elif preset == 'DJV':
        player_path = 'djv_view'

        if platform.system() == 'Darwin':
            test_path = '/Applications/djv-0.8.2.app/Contents/Resources/bin/djv_view'
            if os.path.exists(test_path):
                player_path = test_path

    elif preset == 'FRAMECYCLER':
        player_path = 'framecycler'

    elif preset == 'RV':
        player_path = 'rv'


    return player_path


class PlayRenderedAnim(bpy.types.Operator):
    '''Plays back rendered frames/movies using an external player.'''
    bl_idname = "screen.play_rendered_anim"
    bl_label = "Play Rendered Animation"
    bl_register = True
    bl_undo = False

    def execute(self, context):
        sce = context.scene
        rd = sce.render_data
        prefs = context.user_preferences

        preset = prefs.filepaths.animation_player_preset
        player_path = prefs.filepaths.animation_player
        file_path = bpy.utils.expandpath(rd.output_path)

        # try and guess a command line if it doesn't exist
        if player_path == '':
            player_path = guess_player_path(preset)

        # doesn't support ### frame notation yet
        if rd.file_format in movie_formats:
            file = "%s%04d_%04d" % (file_path, sce.start_frame, sce.end_frame)
        elif preset in ('BLENDER24', 'DJV', 'CUSTOM'):
            file = "%s%04d" % (file_path, sce.start_frame)
        elif preset in ('FRAMECYCLER', 'RV'):
            file = "%s#" % file_path

        if rd.file_extensions:
            file += '.' + img_format_exts[rd.file_format]

        cmd = [player_path]
        # extra options, fps controls etc.
        if preset == 'BLENDER24':
            opts = ["-a", "-f", str(rd.fps), str(rd.fps_base), file]
            cmd.extend(opts)
        elif preset == 'DJV':
            opts = [file, "-playback_speed", str(rd.fps)]
            cmd.extend(opts)
        elif preset == 'FRAMECYCLER':
            opts = [file, "%d-%d" % (sce.start_frame, sce.end_frame)]
            cmd.extend(opts)
        elif preset == 'RV':
            opts = ["-fps", str(rd.fps), "-play", "[ %s ]" % file]
            cmd.extend(opts)
        else: # 'CUSTOM'
            cmd.append(file)

        # launch it
        try:
            process = subprocess.Popen(cmd)
        except:
            pass
            #raise OSError("Couldn't find an external animation player.")

        return('FINISHED',)

bpy.types.register(PlayRenderedAnim)