3d810a55b0e2dd5da3ebe285f2ade72b107d6b56
[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_format(RenderOutputButtonsPanel, Panel):
58     bl_label = "Project Format"
59     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
60
61     _preset_class = None
62     _frame_rate_args_prev = None
63
64     @staticmethod
65     def _draw_framerate_label(*args):
66         # avoids re-creating text string each draw
67         if RENDER_PT_format._frame_rate_args_prev == args:
68             return RENDER_PT_format._frame_rate_ret
69
70         fps, fps_base, preset_label = args
71
72         if fps_base == 1.0:
73             fps_rate = round(fps)
74         else:
75             fps_rate = round(fps / fps_base, 2)
76
77         # TODO: Change the following to iterate over existing presets
78         custom_framerate = (fps_rate not in {23.98, 24, 25, 29.97, 30, 50, 59.94, 60})
79
80         if custom_framerate is True:
81             fps_label_text = f"Custom ({fps_rate!r} fps)"
82             show_framerate = True
83         else:
84             fps_label_text = f"{fps_rate!r} fps"
85             show_framerate = (preset_label == "Custom")
86
87         RENDER_PT_format._frame_rate_args_prev = args
88         RENDER_PT_format._frame_rate_ret = args = (fps_label_text, show_framerate)
89         return args
90
91     @staticmethod
92     def draw_framerate(layout, sub, rd):
93         if RENDER_PT_format._preset_class is None:
94             RENDER_PT_format._preset_class = bpy.types.RENDER_MT_framerate_presets
95
96         args = rd.fps, rd.fps_base, RENDER_PT_format._preset_class.bl_label
97         fps_label_text, show_framerate = RENDER_PT_format._draw_framerate_label(*args)
98
99         sub.menu("RENDER_MT_framerate_presets", text=fps_label_text)
100
101         if show_framerate:
102             col = layout.column(align=True)
103             col.prop(rd, "fps")
104             col.prop(rd, "fps_base", text="Base")
105
106     def draw_header_preset(self, context):
107         RENDER_PT_presets.draw_panel_header(self.layout)
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 Ratio X")
124         col.prop(rd, "pixel_aspect_y", text="Y")
125
126         col = layout.column(align=True)
127         col.prop(rd, "use_border")
128         sub = col.column(align=True)
129         sub.active = rd.use_border
130         sub.prop(rd, "use_crop_to_border")
131
132         col = layout.split()
133         col.alignment = 'RIGHT'
134         col.label(text="Frame Rate")
135         self.draw_framerate(layout, col, rd)
136
137
138 class RENDER_PT_frame_range(RenderOutputButtonsPanel, Panel):
139     bl_label = "Frame Range"
140     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
141
142     def draw(self, context):
143         layout = self.layout
144         layout.use_property_split = True
145         layout.use_property_decorate = False  # No animation.
146
147         scene = context.scene
148         rd = scene.render
149
150         col = layout.column(align=True)
151         col.prop(scene, "frame_start", text="Frame Start")
152         col.prop(scene, "frame_end", text="End")
153         col.prop(scene, "frame_step", text="Step")
154
155
156 class RENDER_PT_time_frame_remapping(RenderOutputButtonsPanel, Panel):
157     bl_label = "Time Stretching"
158     bl_parent_id = "RENDER_PT_frame_range"
159     bl_options = {'DEFAULT_CLOSED'}
160     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
161
162     def draw(self, context):
163         layout = self.layout
164         layout.use_property_split = True
165         layout.use_property_decorate = False  # No animation.
166
167         rd = context.scene.render
168
169         col = layout.column(align=True)
170         col.prop(rd, "frame_map_old", text="Old")
171         col.prop(rd, "frame_map_new", text="New")
172
173
174 class RENDER_PT_post_processing(RenderOutputButtonsPanel, Panel):
175     bl_label = "Post Processing"
176     bl_options = {'DEFAULT_CLOSED'}
177     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
178
179     def draw(self, context):
180         layout = self.layout
181         layout.use_property_split = True
182
183         rd = context.scene.render
184
185         flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=False)
186         col = flow.column()
187         col.prop(rd, "use_compositing")
188         col = flow.column()
189         col.prop(rd, "use_sequencer")
190
191         layout.prop(rd, "dither_intensity", text="Dither", slider=True)
192
193
194 class RENDER_PT_stamp(RenderOutputButtonsPanel, Panel):
195     bl_label = "Metadata"
196     bl_options = {'DEFAULT_CLOSED'}
197     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
198
199     def draw(self, context):
200         layout = self.layout
201         layout.use_property_split = True
202         layout.use_property_decorate = False  # No animation.
203
204         rd = context.scene.render
205
206         flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=False)
207
208         col = flow.column()
209         col.prop(rd, "use_stamp_date", text="Date")
210         col = flow.column()
211         col.prop(rd, "use_stamp_time", text="Time")
212
213         col = flow.column()
214         col.prop(rd, "use_stamp_render_time", text="Render Time")
215         col = flow.column()
216         col.prop(rd, "use_stamp_frame", text="Frame")
217         col = flow.column()
218         col.prop(rd, "use_stamp_frame_range", text="Frame Range")
219         col = flow.column()
220         col.prop(rd, "use_stamp_memory", text="Memory")
221         col = flow.column()
222         col.prop(rd, "use_stamp_hostname", text="Hostname")
223
224         col = flow.column()
225         col.prop(rd, "use_stamp_camera", text="Camera")
226         col = flow.column()
227         col.prop(rd, "use_stamp_lens", text="Lens")
228
229         col = flow.column()
230         col.prop(rd, "use_stamp_scene", text="Scene")
231         col = flow.column()
232         col.prop(rd, "use_stamp_marker", text="Marker")
233
234         col = flow.column()
235         col.prop(rd, "use_stamp_filename", text="Filename")
236
237         col = flow.column()
238         col.prop(rd, "use_stamp_sequencer_strip", text="Strip Name")
239
240         if rd.use_sequencer:
241             col = flow.column()
242             col.prop(rd, "use_stamp_strip_meta", text="Use Strip Metadata")
243
244
245 class RENDER_PT_stamp_note(RenderOutputButtonsPanel, Panel):
246     bl_label = "Note"
247     bl_parent_id = "RENDER_PT_stamp"
248     bl_options = {'DEFAULT_CLOSED'}
249     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
250
251     def draw_header(self, context):
252         rd = context.scene.render
253
254         self.layout.prop(rd, "use_stamp_note", text="")
255
256     def draw(self, context):
257         layout = self.layout
258
259         rd = context.scene.render
260
261         layout.active = rd.use_stamp_note
262         layout.prop(rd, "stamp_note_text", text="")
263
264
265 class RENDER_PT_stamp_burn(RenderOutputButtonsPanel, Panel):
266     bl_label = "Burn Into Image"
267     bl_parent_id = "RENDER_PT_stamp"
268     bl_options = {'DEFAULT_CLOSED'}
269     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
270
271     def draw_header(self, context):
272         rd = context.scene.render
273
274         self.layout.prop(rd, "use_stamp", text="")
275
276     def draw(self, context):
277         layout = self.layout
278
279         rd = context.scene.render
280
281         layout.use_property_split = True
282
283         col = layout.column()
284         col.active = rd.use_stamp
285         col.prop(rd, "stamp_font_size", text="Font Size")
286         col.column().prop(rd, "stamp_foreground", slider=True)
287         col.column().prop(rd, "stamp_background", slider=True)
288         col.prop(rd, "use_stamp_labels", text="Include Labels")
289
290
291 class RENDER_PT_output(RenderOutputButtonsPanel, Panel):
292     bl_label = "Output"
293     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
294
295     def draw(self, context):
296         layout = self.layout
297         layout.use_property_split = False
298         layout.use_property_decorate = False  # No animation.
299
300         rd = context.scene.render
301         image_settings = rd.image_settings
302
303         layout.prop(rd, "filepath", text="")
304
305         layout.use_property_split = True
306
307         flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=False)
308
309         col = flow.column()
310         col.active = not rd.is_movie_format
311         col.prop(rd, "use_overwrite")
312         col = flow.column()
313         col.active = not rd.is_movie_format
314         col.prop(rd, "use_placeholder")
315         col = flow.column()
316         col.prop(rd, "use_file_extension")
317         col = flow.column()
318         col.prop(rd, "use_render_cache")
319
320         layout.template_image_settings(image_settings, color_management=False)
321
322
323 class RENDER_PT_output_views(RenderOutputButtonsPanel, Panel):
324     bl_label = "Views"
325     bl_parent_id = "RENDER_PT_output"
326     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
327
328     @classmethod
329     def poll(self, context):
330         rd = context.scene.render
331         return rd.use_multiview
332
333     def draw(self, context):
334         layout = self.layout
335         layout.use_property_split = False
336         layout.use_property_decorate = False  # No animation.
337
338         rd = context.scene.render
339         layout.template_image_views(rd.image_settings)
340
341
342 class RENDER_PT_encoding(RenderOutputButtonsPanel, Panel):
343     bl_label = "Encoding"
344     bl_parent_id = "RENDER_PT_output"
345     bl_options = {'DEFAULT_CLOSED'}
346     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
347
348     def draw_header_preset(self, context):
349         RENDER_PT_ffmpeg_presets.draw_panel_header(self.layout)
350
351     @classmethod
352     def poll(cls, context):
353         rd = context.scene.render
354         return rd.image_settings.file_format in {'FFMPEG', 'XVID', 'H264', 'THEORA'}
355
356     def draw(self, context):
357         layout = self.layout
358         layout.use_property_split = True
359         layout.use_property_decorate = False
360
361         rd = context.scene.render
362         ffmpeg = rd.ffmpeg
363
364         layout.prop(rd.ffmpeg, "format")
365         layout.prop(ffmpeg, "use_autosplit")
366
367
368 class RENDER_PT_encoding_video(RenderOutputButtonsPanel, Panel):
369     bl_label = "Video"
370     bl_parent_id = "RENDER_PT_encoding"
371     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
372
373     @classmethod
374     def poll(cls, context):
375         rd = context.scene.render
376         return rd.image_settings.file_format in {'FFMPEG', 'XVID', 'H264', 'THEORA'}
377
378     def draw(self, context):
379         layout = self.layout
380         layout.use_property_split = True
381         layout.use_property_decorate = False
382
383         self.draw_vcodec(context)
384
385     def draw_vcodec(self, context):
386         """Video codec options."""
387         layout = self.layout
388         ffmpeg = context.scene.render.ffmpeg
389
390         needs_codec = ffmpeg.format in {'AVI', 'QUICKTIME', 'MKV', 'OGG', 'MPEG4'}
391         if needs_codec:
392             layout.prop(ffmpeg, "codec")
393
394         if needs_codec and ffmpeg.codec == 'NONE':
395             return
396
397         if ffmpeg.codec in {'DNXHD'}:
398             layout.prop(ffmpeg, "use_lossless_output")
399
400         # Output quality
401         use_crf = needs_codec and ffmpeg.codec in {'H264', 'MPEG4', 'WEBM'}
402         if use_crf:
403             layout.prop(ffmpeg, "constant_rate_factor")
404
405         # Encoding speed
406         layout.prop(ffmpeg, "ffmpeg_preset")
407         # I-frames
408         layout.prop(ffmpeg, "gopsize")
409         # B-Frames
410         split = layout.split(factor=0.5)
411         split.prop(ffmpeg, "use_max_b_frames", text="Max B-frames")
412         pbox = split.column()
413         pbox.prop(ffmpeg, "max_b_frames", text="")
414         pbox.enabled = ffmpeg.use_max_b_frames
415
416         if not use_crf or ffmpeg.constant_rate_factor == 'NONE':
417             col = layout.column()
418
419             sub = col.column(align=True)
420             sub.prop(ffmpeg, "video_bitrate")
421             sub.prop(ffmpeg, "minrate", text="Minimum")
422             sub.prop(ffmpeg, "maxrate", text="Maximum")
423
424             col.prop(ffmpeg, "buffersize", text="Buffer")
425
426             col.separator()
427
428             col.prop(ffmpeg, "muxrate", text="Mux Rate")
429             col.prop(ffmpeg, "packetsize", text="Mux Packet Size")
430
431
432 class RENDER_PT_encoding_audio(RenderOutputButtonsPanel, Panel):
433     bl_label = "Audio"
434     bl_parent_id = "RENDER_PT_encoding"
435     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
436
437     @classmethod
438     def poll(cls, context):
439         rd = context.scene.render
440         return rd.image_settings.file_format in {'FFMPEG', 'XVID', 'H264', 'THEORA'}
441
442     def draw(self, context):
443         layout = self.layout
444         layout.use_property_split = True
445         layout.use_property_decorate = False
446
447         rd = context.scene.render
448         ffmpeg = rd.ffmpeg
449
450         if ffmpeg.format != 'MP3':
451             layout.prop(ffmpeg, "audio_codec", text="Audio Codec")
452
453         if ffmpeg.audio_codec != 'NONE':
454             layout.prop(ffmpeg, "audio_bitrate")
455             layout.prop(ffmpeg, "audio_volume", slider=True)
456
457
458 class RENDER_UL_renderviews(UIList):
459     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
460         view = item
461         if self.layout_type in {'DEFAULT', 'COMPACT'}:
462             if view.name in {"left", "right"}:
463                 layout.label(text=view.name, icon_value=icon + (not view.use))
464             else:
465                 layout.prop(view, "name", text="", index=index, icon_value=icon, emboss=False)
466             layout.prop(view, "use", text="", index=index)
467
468         elif self.layout_type == 'GRID':
469             layout.alignment = 'CENTER'
470             layout.label(text="", icon_value=icon + (not view.use))
471
472
473 class RENDER_PT_stereoscopy(RenderOutputButtonsPanel, Panel):
474     bl_label = "Stereoscopy"
475     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
476     bl_options = {'DEFAULT_CLOSED'}
477
478     def draw_header(self, context):
479         rd = context.scene.render
480         self.layout.prop(rd, "use_multiview", text="")
481
482     def draw(self, context):
483         layout = self.layout
484
485         scene = context.scene
486         rd = scene.render
487         rv = rd.views.active
488
489         layout.active = rd.use_multiview
490         basic_stereo = rd.views_format == 'STEREO_3D'
491
492         row = layout.row()
493         row.prop(rd, "views_format")
494
495         if basic_stereo:
496             row = layout.row()
497             row.template_list("RENDER_UL_renderviews", "name", rd, "stereo_views", rd.views, "active_index", rows=2)
498
499             row = layout.row()
500             row.label(text="File Suffix:")
501             row.prop(rv, "file_suffix", text="")
502
503         else:
504             row = layout.row()
505             row.template_list("RENDER_UL_renderviews", "name", rd, "views", rd.views, "active_index", rows=2)
506
507             col = row.column(align=True)
508             col.operator("scene.render_view_add", icon='ADD', text="")
509             col.operator("scene.render_view_remove", icon='REMOVE', text="")
510
511             row = layout.row()
512             row.label(text="Camera Suffix:")
513             row.prop(rv, "camera_suffix", text="")
514
515
516 classes = (
517     RENDER_PT_presets,
518     RENDER_PT_ffmpeg_presets,
519     RENDER_MT_framerate_presets,
520     RENDER_PT_format,
521     RENDER_PT_frame_range,
522     RENDER_PT_time_frame_remapping,
523     RENDER_PT_output,
524     RENDER_PT_output_views,
525     RENDER_PT_encoding,
526     RENDER_PT_encoding_video,
527     RENDER_PT_encoding_audio,
528     RENDER_PT_stamp,
529     RENDER_PT_stamp_note,
530     RENDER_PT_stamp_burn,
531     RENDER_UL_renderviews,
532     RENDER_PT_stereoscopy,
533     RENDER_PT_post_processing,
534 )
535
536 if __name__ == "__main__":  # only for live edit.
537     from bpy.utils import register_class
538     for cls in classes:
539         register_class(cls)