cf5f65738c8d79b55e690821d47adabe511d9d77
[blender.git] / release / scripts / startup / bl_ui / properties_output.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2
3 #
4 #  This program is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU General Public License
6 #  as published by the Free Software Foundation; either version 2
7 #  of the License, or (at your option) any later version.
8 #
9 #  This program is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #  GNU General Public License for more details.
13 #
14 #  You should have received a copy of the GNU General Public License
15 #  along with this program; if not, write to the Free Software Foundation,
16 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18 # ##### END GPL LICENSE BLOCK #####
19
20 # <pep8 compliant>
21 import bpy
22 from bpy.types import Menu, Panel, UIList
23 from bl_operators.presets import PresetMenu
24
25
26 class RENDER_PT_presets(PresetMenu):
27     bl_label = "Render Presets"
28     preset_subdir = "render"
29     preset_operator = "script.execute_preset"
30     preset_add_operator = "render.preset_add"
31
32
33 class RENDER_PT_ffmpeg_presets(PresetMenu):
34     bl_label = "FFMPEG Presets"
35     preset_subdir = "ffmpeg"
36     preset_operator = "script.python_file_run"
37
38
39 class RENDER_MT_framerate_presets(Menu):
40     bl_label = "Frame Rate Presets"
41     preset_subdir = "framerate"
42     preset_operator = "script.execute_preset"
43     draw = Menu.draw_preset
44
45
46 class RenderOutputButtonsPanel:
47     bl_space_type = 'PROPERTIES'
48     bl_region_type = 'WINDOW'
49     bl_context = "output"
50     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
51
52     @classmethod
53     def poll(cls, context):
54         return (context.engine in cls.COMPAT_ENGINES)
55
56
57 class RENDER_PT_dimensions(RenderOutputButtonsPanel, Panel):
58     bl_label = "Dimensions"
59     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
60
61     _frame_rate_args_prev = None
62     _preset_class = None
63
64     def draw_header_preset(self, context):
65         RENDER_PT_presets.draw_panel_header(self.layout)
66
67     @staticmethod
68     def _draw_framerate_label(*args):
69         # avoids re-creating text string each draw
70         if RENDER_PT_dimensions._frame_rate_args_prev == args:
71             return RENDER_PT_dimensions._frame_rate_ret
72
73         fps, fps_base, preset_label = args
74
75         if fps_base == 1.0:
76             fps_rate = round(fps)
77         else:
78             fps_rate = round(fps / fps_base, 2)
79
80         # TODO: Change the following to iterate over existing presets
81         custom_framerate = (fps_rate not in {23.98, 24, 25, 29.97, 30, 50, 59.94, 60})
82
83         if custom_framerate is True:
84             fps_label_text = f"Custom ({fps_rate!r} fps)"
85             show_framerate = True
86         else:
87             fps_label_text = f"{fps_rate!r} fps"
88             show_framerate = (preset_label == "Custom")
89
90         RENDER_PT_dimensions._frame_rate_args_prev = args
91         RENDER_PT_dimensions._frame_rate_ret = args = (fps_label_text, show_framerate)
92         return args
93
94     @staticmethod
95     def draw_framerate(layout, sub, rd):
96         if RENDER_PT_dimensions._preset_class is None:
97             RENDER_PT_dimensions._preset_class = bpy.types.RENDER_MT_framerate_presets
98
99         args = rd.fps, rd.fps_base, RENDER_PT_dimensions._preset_class.bl_label
100         fps_label_text, show_framerate = RENDER_PT_dimensions._draw_framerate_label(*args)
101
102         sub.menu("RENDER_MT_framerate_presets", text=fps_label_text)
103
104         if show_framerate:
105             col = layout.column(align=True)
106             col.prop(rd, "fps")
107             col.prop(rd, "fps_base", text="Base")
108
109     def draw(self, context):
110         layout = self.layout
111         layout.use_property_split = True
112         layout.use_property_decorate = False  # No animation.
113
114         scene = context.scene
115         rd = scene.render
116
117         col = layout.column(align=True)
118         col.prop(rd, "resolution_x", text="Resolution X")
119         col.prop(rd, "resolution_y", text="Y")
120         col.prop(rd, "resolution_percentage", text="%")
121
122         col = layout.column(align=True)
123         col.prop(rd, "pixel_aspect_x", text="Aspect X")
124         col.prop(rd, "pixel_aspect_y", text="Y")
125
126         col = layout.column(align=True)
127         col.prop(rd, "use_border", text="Border")
128         sub = col.column(align=True)
129         sub.active = rd.use_border
130         sub.prop(rd, "use_crop_to_border", text="Crop")
131
132         col = layout.column(align=True)
133         col.prop(scene, "frame_start", text="Frame Start")
134         col.prop(scene, "frame_end", text="End")
135         col.prop(scene, "frame_step", text="Step")
136
137         col = layout.split()
138         col.alignment = 'RIGHT'
139         col.label(text="Frame Rate")
140         self.draw_framerate(layout, col, rd)
141
142
143 class RENDER_PT_frame_remapping(RenderOutputButtonsPanel, Panel):
144     bl_label = "Time Remapping"
145     bl_parent_id = "RENDER_PT_dimensions"
146     bl_options = {'DEFAULT_CLOSED'}
147     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
148
149     def draw(self, context):
150         layout = self.layout
151         layout.use_property_split = True
152         layout.use_property_decorate = False  # No animation.
153
154         rd = context.scene.render
155
156         col = layout.column(align=True)
157         col.prop(rd, "frame_map_old", text="Old")
158         col.prop(rd, "frame_map_new", text="New")
159
160
161 class RENDER_PT_post_processing(RenderOutputButtonsPanel, Panel):
162     bl_label = "Post Processing"
163     bl_options = {'DEFAULT_CLOSED'}
164     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
165
166     def draw(self, context):
167         layout = self.layout
168         layout.use_property_split = True
169
170         rd = context.scene.render
171
172         flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=False)
173         col = flow.column()
174         col.prop(rd, "use_compositing")
175         col = flow.column()
176         col.prop(rd, "use_sequencer")
177
178         layout.prop(rd, "dither_intensity", text="Dither", slider=True)
179
180
181 class RENDER_PT_stamp(RenderOutputButtonsPanel, Panel):
182     bl_label = "Metadata"
183     bl_options = {'DEFAULT_CLOSED'}
184     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
185
186     def draw(self, context):
187         layout = self.layout
188         layout.use_property_split = True
189         layout.use_property_decorate = False  # No animation.
190
191         rd = context.scene.render
192
193         flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=False)
194
195         col = flow.column()
196         col.prop(rd, "use_stamp_date", text="Date")
197         col = flow.column()
198         col.prop(rd, "use_stamp_time", text="Time")
199
200         col = flow.column()
201         col.prop(rd, "use_stamp_render_time", text="Render Time")
202         col = flow.column()
203         col.prop(rd, "use_stamp_frame", text="Frame")
204         col = flow.column()
205         col.prop(rd, "use_stamp_frame_range", text="Frame Range")
206         col = flow.column()
207         col.prop(rd, "use_stamp_memory", text="Memory")
208
209         col = flow.column()
210         col.prop(rd, "use_stamp_camera", text="Camera")
211         col = flow.column()
212         col.prop(rd, "use_stamp_lens", text="Lens")
213
214         col = flow.column()
215         col.prop(rd, "use_stamp_scene", text="Scene")
216         col = flow.column()
217         col.prop(rd, "use_stamp_marker", text="Marker")
218
219         col = flow.column()
220         col.prop(rd, "use_stamp_filename", text="Filename")
221
222         col = flow.column()
223         col.prop(rd, "use_stamp_sequencer_strip", text="Strip Name")
224
225         if rd.use_sequencer:
226             col = flow.column()
227             col.prop(rd, "use_stamp_strip_meta", text="Use Strip Metadata")
228
229
230 class RENDER_PT_stamp_note(RenderOutputButtonsPanel, Panel):
231     bl_label = "Note"
232     bl_parent_id = "RENDER_PT_stamp"
233     bl_options = {'DEFAULT_CLOSED'}
234     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
235
236     def draw_header(self, context):
237         rd = context.scene.render
238
239         self.layout.prop(rd, "use_stamp_note", text="")
240
241     def draw(self, context):
242         layout = self.layout
243
244         rd = context.scene.render
245
246         layout.active = rd.use_stamp_note
247         layout.prop(rd, "stamp_note_text", text="")
248
249
250 class RENDER_PT_stamp_burn(RenderOutputButtonsPanel, Panel):
251     bl_label = "Burn Into Image"
252     bl_parent_id = "RENDER_PT_stamp"
253     bl_options = {'DEFAULT_CLOSED'}
254     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
255
256     def draw_header(self, context):
257         rd = context.scene.render
258
259         self.layout.prop(rd, "use_stamp", text="")
260
261     def draw(self, context):
262         layout = self.layout
263
264         rd = context.scene.render
265
266         layout.use_property_split = True
267
268         col = layout.column()
269         col.active = rd.use_stamp
270         col.prop(rd, "stamp_font_size", text="Font Size")
271         col.prop(rd, "use_stamp_labels", text="Draw Labels")
272         col.column().prop(rd, "stamp_foreground", slider=True)
273         col.column().prop(rd, "stamp_background", slider=True)
274
275
276 class RENDER_PT_output(RenderOutputButtonsPanel, Panel):
277     bl_label = "Output"
278     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
279
280     def draw(self, context):
281         layout = self.layout
282         layout.use_property_split = False
283         layout.use_property_decorate = False  # No animation.
284
285         rd = context.scene.render
286         image_settings = rd.image_settings
287
288         layout.prop(rd, "filepath", text="")
289
290         layout.use_property_split = True
291
292         flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=False)
293
294         col = flow.column()
295         col.active = not rd.is_movie_format
296         col.prop(rd, "use_overwrite")
297         col = flow.column()
298         col.active = not rd.is_movie_format
299         col.prop(rd, "use_placeholder")
300         col = flow.column()
301         col.prop(rd, "use_file_extension")
302         col = flow.column()
303         col.prop(rd, "use_render_cache")
304
305         layout.template_image_settings(image_settings, color_management=False)
306
307
308 class RENDER_PT_output_views(RenderOutputButtonsPanel, Panel):
309     bl_label = "Views"
310     bl_parent_id = "RENDER_PT_output"
311     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
312
313     @classmethod
314     def poll(self, context):
315         rd = context.scene.render
316         return rd.use_multiview
317
318     def draw(self, context):
319         layout = self.layout
320         layout.use_property_split = False
321         layout.use_property_decorate = False  # No animation.
322
323         rd = context.scene.render
324         layout.template_image_views(rd.image_settings)
325
326
327 class RENDER_PT_encoding(RenderOutputButtonsPanel, Panel):
328     bl_label = "Encoding"
329     bl_parent_id = "RENDER_PT_output"
330     bl_options = {'DEFAULT_CLOSED'}
331     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
332
333     def draw_header_preset(self, context):
334         RENDER_PT_ffmpeg_presets.draw_panel_header(self.layout)
335
336     @classmethod
337     def poll(cls, context):
338         rd = context.scene.render
339         return rd.image_settings.file_format in {'FFMPEG', 'XVID', 'H264', 'THEORA'}
340
341     def draw(self, context):
342         layout = self.layout
343         layout.use_property_split = True
344         layout.use_property_decorate = False
345
346         rd = context.scene.render
347         ffmpeg = rd.ffmpeg
348
349         layout.prop(rd.ffmpeg, "format")
350         layout.prop(ffmpeg, "use_autosplit")
351
352
353 class RENDER_PT_encoding_video(RenderOutputButtonsPanel, Panel):
354     bl_label = "Video"
355     bl_parent_id = "RENDER_PT_encoding"
356     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
357
358     @classmethod
359     def poll(cls, context):
360         rd = context.scene.render
361         return rd.image_settings.file_format in {'FFMPEG', 'XVID', 'H264', 'THEORA'}
362
363     def draw(self, context):
364         layout = self.layout
365         layout.use_property_split = True
366         layout.use_property_decorate = False
367
368         self.draw_vcodec(context)
369
370     def draw_vcodec(self, context):
371         """Video codec options."""
372         layout = self.layout
373         ffmpeg = context.scene.render.ffmpeg
374
375         needs_codec = ffmpeg.format in {'AVI', 'QUICKTIME', 'MKV', 'OGG', 'MPEG4'}
376         if needs_codec:
377             layout.prop(ffmpeg, "codec")
378
379         if needs_codec and ffmpeg.codec == 'NONE':
380             return
381
382         if ffmpeg.codec in {'DNXHD'}:
383             layout.prop(ffmpeg, "use_lossless_output")
384
385         # Output quality
386         use_crf = needs_codec and ffmpeg.codec in {'H264', 'MPEG4', 'WEBM'}
387         if use_crf:
388             layout.prop(ffmpeg, "constant_rate_factor")
389
390         # Encoding speed
391         layout.prop(ffmpeg, "ffmpeg_preset")
392         # I-frames
393         layout.prop(ffmpeg, "gopsize")
394         # B-Frames
395         split = layout.split(factor=0.5)
396         split.prop(ffmpeg, "use_max_b_frames", text="Max B-frames")
397         pbox = split.column()
398         pbox.prop(ffmpeg, "max_b_frames", text="")
399         pbox.enabled = ffmpeg.use_max_b_frames
400
401         if not use_crf or ffmpeg.constant_rate_factor == 'NONE':
402             col = layout.column()
403
404             sub = col.column(align=True)
405             sub.prop(ffmpeg, "video_bitrate")
406             sub.prop(ffmpeg, "minrate", text="Minimum")
407             sub.prop(ffmpeg, "maxrate", text="Maximum")
408
409             col.prop(ffmpeg, "buffersize", text="Buffer")
410
411             col.separator()
412
413             col.prop(ffmpeg, "muxrate", text="Mux Rate")
414             col.prop(ffmpeg, "packetsize", text="Mux Packet Size")
415
416
417 class RENDER_PT_encoding_audio(RenderOutputButtonsPanel, Panel):
418     bl_label = "Audio"
419     bl_parent_id = "RENDER_PT_encoding"
420     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
421
422     @classmethod
423     def poll(cls, context):
424         rd = context.scene.render
425         return rd.image_settings.file_format in {'FFMPEG', 'XVID', 'H264', 'THEORA'}
426
427     def draw(self, context):
428         layout = self.layout
429         layout.use_property_split = True
430         layout.use_property_decorate = False
431
432         rd = context.scene.render
433         ffmpeg = rd.ffmpeg
434
435         if ffmpeg.format != 'MP3':
436             layout.prop(ffmpeg, "audio_codec", text="Audio Codec")
437
438         if ffmpeg.audio_codec != 'NONE':
439             layout.prop(ffmpeg, "audio_bitrate")
440             layout.prop(ffmpeg, "audio_volume", slider=True)
441
442
443 class RENDER_UL_renderviews(UIList):
444     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
445         view = item
446         if self.layout_type in {'DEFAULT', 'COMPACT'}:
447             if view.name in {"left", "right"}:
448                 layout.label(text=view.name, icon_value=icon + (not view.use))
449             else:
450                 layout.prop(view, "name", text="", index=index, icon_value=icon, emboss=False)
451             layout.prop(view, "use", text="", index=index)
452
453         elif self.layout_type == 'GRID':
454             layout.alignment = 'CENTER'
455             layout.label(text="", icon_value=icon + (not view.use))
456
457
458 class RENDER_PT_stereoscopy(RenderOutputButtonsPanel, Panel):
459     bl_label = "Stereoscopy"
460     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
461     bl_options = {'DEFAULT_CLOSED'}
462
463     def draw_header(self, context):
464         rd = context.scene.render
465         self.layout.prop(rd, "use_multiview", text="")
466
467     def draw(self, context):
468         layout = self.layout
469
470         scene = context.scene
471         rd = scene.render
472         rv = rd.views.active
473
474         layout.active = rd.use_multiview
475         basic_stereo = rd.views_format == 'STEREO_3D'
476
477         row = layout.row()
478         row.prop(rd, "views_format", expand=True)
479
480         if basic_stereo:
481             row = layout.row()
482             row.template_list("RENDER_UL_renderviews", "name", rd, "stereo_views", rd.views, "active_index", rows=2)
483
484             row = layout.row()
485             row.label(text="File Suffix:")
486             row.prop(rv, "file_suffix", text="")
487
488         else:
489             row = layout.row()
490             row.template_list("RENDER_UL_renderviews", "name", rd, "views", rd.views, "active_index", rows=2)
491
492             col = row.column(align=True)
493             col.operator("scene.render_view_add", icon='ADD', text="")
494             col.operator("scene.render_view_remove", icon='REMOVE', text="")
495
496             row = layout.row()
497             row.label(text="Camera Suffix:")
498             row.prop(rv, "camera_suffix", text="")
499
500
501 classes = (
502     RENDER_PT_presets,
503     RENDER_PT_ffmpeg_presets,
504     RENDER_MT_framerate_presets,
505     RENDER_PT_dimensions,
506     RENDER_PT_frame_remapping,
507     RENDER_PT_output,
508     RENDER_PT_output_views,
509     RENDER_PT_encoding,
510     RENDER_PT_encoding_video,
511     RENDER_PT_encoding_audio,
512     RENDER_PT_stamp,
513     RENDER_PT_stamp_note,
514     RENDER_PT_stamp_burn,
515     RENDER_UL_renderviews,
516     RENDER_PT_stereoscopy,
517     RENDER_PT_post_processing,
518 )
519
520 if __name__ == "__main__":  # only for live edit.
521     from bpy.utils import register_class
522     for cls in classes:
523         register_class(cls)