Mat's noted corrections
[goodguy/cin-manual-latex.git] / parts / Rendering.tex
1 \chapter{Rendering}%
2 \label{cha:rendering}
3
4 Rendering takes a section of the timeline, performs all the editing,
5 effects and compositing, and creates a new media file.  You can then
6 delete all the source assets, play the rendered file, or bring it
7 back into \CGG{} for more editing.  All rendering operations are
8 based on a region of the timeline to be rendered.  You need to
9 define this region on the timeline.  The rendering functions define
10 the region based on a set of rules.  When a region is highlighted or
11 in/out points are set, the affected region is rendered.  When no
12 region is highlighted, everything after the insertion point is
13 rendered.  By positioning the insertion point at the beginning of a
14 track and unsetting all in/out points, the entire track is rendered.
15 But you also have the choice to render \textit{one frame}.
16
17 \section{Single File Rendering}%
18 \label{sec:single_file_rendering}
19
20 Use the File pulldown and select Render to start the render dialog
21 (figure~\ref{fig:render}).  Then choose the desired parameters.
22
23 \begin{figure}[htpb] \centering
24   \includegraphics[width=0.7\linewidth]{render.png}
25   \caption{Example of the Render menu}
26   \label{fig:render}
27 \end{figure}
28
29 \begin{description}
30 \item[Select a file to render to:] enter the path and filename to
31   write the rendered file to in the textbox below.
32 \item[File Format:] use the down arrow to see file format options.
33   For ffmpeg, which has its own set of options, you will then have to
34   select an ffmpeg file type from the down arrow choices. The format
35   of the file determines whether you can render audio or video or
36   both.
37 \item[Render audio tracks:] check this toggle to generate audio
38   tracks
39 \item[Render video tracks:] check this toggle to generate video
40   tracks. The Render window will sometimes automatically update the
41   Render Audio Tracks or Render Video Tracks checkbox as allowed by
42   the chosen file format, but you should always check
43   (figure~\ref{fig:render01}).  For example, if the PNG file format is
44   selected, only the \textit{Render Video Tracks} will be checked.  Or
45   if an ffmpeg format is chosen and the file format does not render
46   audio, the \textit{Render Audio Tracks} will be unchecked. The
47   invalid choices will be ghosted out.
48 \end{description}
49
50 \begin{figure}[htpb] \centering
51   \includegraphics[width=0.7\linewidth]{render01.png}
52   \caption{Audio and Video tracks automatically checked for Pro file
53     type}
54   \label{fig:render01}
55 \end{figure}
56
57 \begin{description}
58 \item[Wrench:] select the \textit{wrench} next to each toggle to set
59   compression parameters.  If the file format can not store audio or
60   video the compression parameters will be blank.  If \textit{Render
61     audio tracks} or \textit{Render video tracks} is selected and the
62   file format does not support it, trying to render will result in an
63   error message. More details in the section:
64   \nameref{sub:extra_cin_option_ffmpeg}
65 \item[Create new file at each label] the option causes a new file to
66   be created when every label in the timeline is encountered – a
67   separate file for each.  This is useful for dividing long audio
68   recordings into individual tracks.  When using the Render Farm
69   (described later), \textit{Create new file at each label} causes one
70   render farm job to be created at every label instead of using the
71   internal load balancing algorithm to space jobs.  If the filename
72   given in the render dialog has a 2 digit number in it, the 2 digit
73   number is overwritten with a different incremental number for every
74   output file. If no 2 digit number is given, \CGG{} automatically
75   concatenates a number to the end of the given filename for every
76   output file.  For example, in the filename
77   \texttt{/movies/track01.wav} the $01$ would be overwritten for every
78   output file.  The filename \texttt{/movies/track.wav}; however,
79   eventually would become \texttt{/movies/track.wav001} and so on.
80   Filename regeneration is only used when either render farm mode is
81   active or creating new files for every label is active.
82 \item[Render range:] choices are \textit{Project},
83   \textit{Selection}, \textit{In/Out points}, and \textit{One Frame}
84   for single images like Tiff.  For these images, Render range will
85   have \textit{One Frame} automatically checked and all of the others
86   ghosted since nothing else makes sense (figure~\ref{fig:render02}).
87   This makes it easy to set the insertion point where you want the 1
88   frame to be rendered rather than having to precisely zoom in to set
89   the in/out pointers.  Note that whichever Render range is checked,
90   remains checked so that if \textit{One Frame} gets automatically
91   checked, the next time you render it will still be checked and you
92   will have to select a different one if desired.  That is why you
93   should always check the settings.
94 \end{description}
95
96 \begin{figure}[htpb] \centering
97   \includegraphics[width=0.7\linewidth]{render02.png}
98   \caption{Render menu displaying a PNG \textit{one frame} option}
99   \label{fig:render02}
100 \end{figure}
101
102 \begin{description}
103 \item[Beep on done:] as a convenience when a render is complete,
104   check this box.  It gives you the chance to work on something else
105   while waiting and still be immediately notified when the render is
106   complete.
107 \item[Render Profile:] another convenience feature to take advantage
108   of if you use specific render formats frequently, is to save that
109   profile for future usage without having to set it up again.
110 \item[Save Profile:] after setting up your render preference
111   formats, use the save profile button to save it.
112 \item[Delete Profile:] if you want to delete a saved profile,
113   highlight the one you no longer want and delete.
114 \item[Insertion strategy:] select an insertion mode from the
115   available choices as seen when you click on the down arrow on the
116   right hand side of the option. The insertion modes are the same as
117   with loading files.  In the case if you select “insert nothing” the
118   file will be written out to disk without changing the current
119   project. For other insertion strategies be sure to prepare the
120   timeline to have the output inserted at the right position before
121   the rendering operation is finished.
122
123   Even if you only have audio or only have video rendered, a paste
124   insertion strategy will behave like a normal paste operation,
125   erasing any selected region of the timeline and pasting just the
126   data that was rendered.  If you render only audio and have some
127   video tracks armed, the video tracks will get truncated while the
128   audio output is pasted into the audio tracks.
129 \end{description}
130
131 \section{Batch Rendering}%
132 \label{sec:batch_rendering}
133
134 Batch Rendering automates the rendering of audio/video files in that
135 you can establish a set of job parameters, save them, and use them
136 repeatedly.  It also allows for \CGG{} to be run by external
137 programs, with no need for the user to manually interact with the
138 user interface (figure~\ref{fig:batch01}).
139
140 If you want to render many projects to media files without having to
141 constantly set up the render dialog for each one, batch rendering is
142 a more efficient method of rendering.  In the Batch Render menu, you
143 specify one or more \CGG{} project XML files, the EDL, to render and
144 unique output files for each. (The EDL is the Edit Decision List or
145 the set of changes to be applied to the project and media files.)
146 Then \CGG{} loads each project file and renders it
147 automatically. The project XML files, combined with the settings for
148 rendering an output file, are called a batch.  This allows a large
149 amount of media to be processed without user intervention.
150
151 \begin{figure}[htpb] \centering
152   \includegraphics[width=1.0\linewidth]{batch01.png}
153   \caption{Example of the Batch Render menu}
154   \label{fig:batch01}
155 \end{figure}
156
157 The first thing to do when preparing to do batch rendering is to
158 create one or more \CGG{} projects to be rendered and save them as a
159 normal project, such as \texttt{ProjectA.xml}.  The batch renderer
160 requires a separate project file for every batch to be rendered.
161 You can use the same \CGG{} project file if you are rendering to
162 different output files, as in an example where you might be creating
163 the same output video in different file formats.
164
165 To create a project file which can be used in batch render, set up
166 your project and define the region to be rendered either by
167 highlighting it, setting in/out points around it, or positioning the
168 insertion point before it. Then save the project as usual to your
169 \texttt{project.xm}l file. Define as many projects as needed this
170 way.  The batch renderer takes the active region from the EDL file
171 for rendering. If we have not set active regions, it is better to
172 bring the insertion point to the beginning of the timeline to avoid
173 possible problems with the rendering.
174
175 With all the \CGG{} xml project files prepared with active regions,
176 go to \texttt{File $\rightarrow$ Batch Render}. This brings up the
177 batch render dialog. The interface for batch rendering is more
178 complex than for single file rendering.  A list of batches must be
179 defined before starting a batch rendering operation.  The table of
180 batches appears on the bottom of the batch render dialog and is
181 called \textit{Batches to render}.  Above this are the configuration
182 parameters for a single batch; a batch is simply a pairing of a
183 project file with a choice of output file and render settings.
184
185 Set the \textit{Output path}, \textit{File format}, \textit{Audio},
186 \textit{Video}, and \textit{Create new file at each label}
187 parameters as if you were rendering a single file.  These parameters
188 apply to only one batch.  In addition to the standard rendering
189 parameters, you must select the \textit{EDL Path} to be the project
190 file (such as \texttt{ProjectA.xml}) that will be used in the batch
191 job.  In this case, \textit{EDL Path} is not related in anyway with
192 the EDL files as created by \texttt{File/Export EDL}.  In batch
193 render mode the program will not overwrite an existing output file
194 and will simply fail, so make sure that no files with the same name
195 as the output files exist before starting.
196
197 If the batches to render list is empty or nothing is highlighted,
198 click \texttt{New} to create a new batch. The new batch will contain
199 all the parameters you just set.  Repeatedly press the \texttt{New}
200 button to create more batches with the same parameters.  When you
201 highlight any batch, you can edit the configuration on the top of
202 the batch render window. The highlighted batch is always
203 synchronized to the information displayed.  You can easily change
204 the order in which the batch jobs are rendered, by clicking and
205 dragging a batch to a different position.  Hit \texttt{Delete} to
206 permanently remove a highlighted batch. In the list box is a column
207 which enables or disables the batch with an \texttt{X} meaning the
208 batch job is enabled and will be run.  This way batches can be
209 skipped without being deleted.  Click on the \texttt{Enabled} column
210 in the list box to enable or disable a batch.
211
212 The description of each of the columns in the batch list are as
213 follows:
214
215 \begin{description}
216 \item[Enabled:] an X in this column means the batch job will be run.
217 \item[Labeled:] an \texttt{X} in this column goes hand in hand with
218   create new file at each label.
219 \item[Output:] path and filename for the generated output.
220 \item[EDL:] the path and filename of the source EDL for the batch
221   job.
222 \item[Elapsed:] the amount of time taken to render the batch if
223   finished.  If field is empty, it did not run.
224 \end{description} To start rendering from the first enabled batch,
225 hit \texttt{Start}.  Once rendering, the main window shows the
226 progress of the batch. After each batch finishes, the elapsed column
227 in the batch list is updated and the next batch is rendered until
228 all the enabled batches are finished.  The currently rendering batch
229 is always highlighted red.  To stop rendering before the batches are
230 finished without closing the batch render dialog, hit \texttt{Stop}.
231 To stop rendering before the batches are finished and close the
232 batch render dialog, hit \texttt{Close}.  Or you can exit the batch
233 render dialog whether or not anything is being rendered, by hitting
234 \texttt{Close}.
235
236 You can automate \CGG{} batch renders from other programs.  In the
237 batch render dialog, once you have created your list of batch render
238 jobs, you can click the button \texttt{Save Jobs} and choose a file
239 to save your batch render list to.  Once you have created this file,
240 you can start up a batch render without needing to interact with the
241 \CGG{} user interface.  From a shell prompt, from a script, or other
242 program, execute:
243
244 \begin{lstlisting}[style=sh]
245 {path_to_cinelerra}/cin -r batchjob.xml
246 \end{lstlisting} substituting your actual filename for
247 \texttt{batchjob.xml}.  When invoked with these parameters, \CGG{}
248 will start up and perform the rendering jobs in that list, without
249 creating its usual windows.
250
251 \subsection{Command Line Rendering}%
252 \label{sub:command_line_rendering}
253
254 The command line rendering method consists of a way to load the
255 current set of batch rendering jobs and process them without a
256 GUI\@. This is useful if you want to do rendering on the other side
257 of a low bandwidth network and you have access to a high powered
258 computer located elsewhere. Setting up all the parameters for this
259 operation is somewhat difficult. That is why the command line aborts
260 if any output files already exist.
261
262 To perform rendering from the command line, first run \CGG{} in
263 graphical mode. Go to \texttt{File $\rightarrow$ Batch
264   Render}. Create the batches you intend to render in the batch window
265 and close the window. This saves the batches in a file. Set up the
266 desired render farm attributes in \texttt{Settings $\rightarrow$
267   Preferences} and quit out of \CGG{} if you want to use the Render
268 Farm capability.  These settings are used the next time command line
269 rendering is used to process the current set of batch jobs without a
270 GUI\@.
271
272 On the command line run:
273
274 \begin{lstlisting}[style=sh]
275 cin -r
276 \end{lstlisting}
277
278 \subsection{More about Save/Use EDL and Save/Load Jobs}%
279 \label{sub:more_save_use_edl_jobs}
280
281 The \texttt{File $\rightarrow$ Batch Render} pulldown brings up the
282 Batch Render window to be used for batch rendering as well as DVD/BD
283 creation.  There are some additional buttons that can save time and
284 mistakes.  These are described next.
285
286 The \textit{Save to EDL Path} and \textit{Use Current EDL} buttons
287 can be valuable tools for advanced usage or for developers doing
288 testing.  Description of how you can expect them to work will help
289 to illustrate how to take advantage of their capabilities.
290
291 \begin{description}
292 \item[Save to EDL Path] if you have made a change to the EDL, use
293   this button to save the changes so that they will be used in the
294   render operation.  Although you can get the same results by using
295   \texttt{File $\rightarrow$ Save\dots}, this capability was initially
296   added to assist developers in testing the batch jobs needed to
297   create dvd/bluray media as it keeps the work focused in a single
298   window and retains the original job name.  An example --you have
299   everything all set up with a new job in the Batch Render window
300   using \texttt{generic.xml} for the EDL path and with a job name of
301   \texttt{original\_name.xml}.  Then you realize that you forgot to
302   cut out a section in the media that is not wanted in the final
303   product.  You can cut that out and then \textit{Save to EDL Path} so
304   your change will be in effect for the rendering.  Without this
305   button, you would be using the EDL you started with and the cut
306   would be ignored.  Alternatively, if the cut changes are saved via
307   \texttt{File $\rightarrow$ Save as}\dots with a filename of
308   \texttt{new.xml} and then you use \textit{Save to EDL Path}, the
309   current highlighted job displayed in the window as
310   \texttt{original\_name.xml} will be replaced with \texttt{new.xml}.
311   However, it is important to note that the result will be saved with
312   the name \texttt{original\_name} – that is, the new content from
313   \texttt{new.xml} but with the old name of
314   \texttt{original\_name.xml}.
315 \item[Use Current EDL] if you are working on media and still testing
316   out the results, you can take advantage of this click-box to quickly
317   get results.  Basically, you change the media, save that change with
318   another name (in order to preserve the original name in case you
319   don't like the changes), and press \textit{Use Current EDL}.  As an
320   example, a user creates a new job in the Batch Render window using
321   the current media, previously defined in generic.xml, with the EDL
322   path of \texttt{generic.xml}.  The user then changes the media on
323   the timeline, saves the changes via \texttt{File $\rightarrow$ Save
324     as\dots} with a new name, such as \texttt{new\_name.xml}, and then
325   clicks on \textit{Use Current EDL}.  In this case, the EDL path
326   listbox will be automatically updated to the \texttt{new\_name.xml}
327   and the current existing highlighted job will be replaced with the
328   \texttt{new\_name.xml} in the EDL column.
329 \item[Save Jobs] when you have set up the batch jobs the way you
330   want and you think you may have to run them more than once, it is
331   beneficial to save the jobs for later use so you easily run them
332   again.
333 \item[Load Jobs] reload a previous set of saved jobs.  This can come
334   in handy if you did not have the time to render them when you
335   originally set them up, if you need to rerun, or if you got
336   interrupted.
337 \item[Warn if Jobs/Session mismatched] After you set up your render
338   and press Start, the program checks to see if the current EDL
339   session matches your Batch Render job.  If the EDL has been changed
340   since the batch job was created, it warns you so that you have the
341   opportunity to \textit{Save to EDL} path to record those changes.
342   Otherwise, you can dismiss that warning box, disable the warning
343   message by unchecking the box and use the original values.  If you
344   never want to be warned about the mismatches, leave the box
345   unchecked (figure~\ref{fig:batch02}).
346 \end{description}
347
348 \begin{figure}[htpb] \centering
349   \includegraphics[width=1.0\linewidth]{batch02.png}
350   \caption{Batch render with the 4 ghosted buttons on the right side
351     + the Warning message below}
352   \label{fig:batch02}
353 \end{figure}
354
355 \section{Background Rendering}%
356 \label{sec:background_rendering}
357
358 Background rendering causes temporary output to be rendered
359 constantly while the timeline is being modified. The temporary
360 output is displayed during playback whenever possible. This is
361 useful for transitions and previewing effects that are too slow to
362 display in real time. If a Render Farm is enabled, the render farm
363 is used for background rendering. This gives you the potential for
364 real-time effects if enough network bandwidth and CPU nodes exist.
365
366 Background rendering is enabled in the \texttt{Performance} tab of
367 the \texttt{Preferences} window. It has one interactive function
368 \texttt{Settings $\rightarrow$ Toggle background rendering}. This
369 sets the point where background rendering starts up to the position
370 of the insertion point. If any video exists, a red bar appears in
371 the time ruler showing what has been background rendered
372 (figure~\ref{fig:back-ren02}).
373
374 \begin{figure}[htpb] \centering
375   \includegraphics[width=1.0\linewidth]{back-ren02.png}
376   \caption{Settings Background Rendering}
377   \label{fig:back-ren02}
378 \end{figure}
379
380 It is often useful to insert an effect or a transition and then
381 select \texttt{Settings $\rightarrow$ Toggle background rendering}
382 right before the effect to preview it in real time and full frame
383 rates (figure~\ref{fig:back-ren}).
384
385 \begin{figure}[htpb] \centering
386   \includegraphics[width=1.0\linewidth]{back-ren.png}
387   \caption{Timeline with the top red bar}
388   \label{fig:back-ren}
389 \end{figure}
390
391 \begin{description}
392 \item[Frames per background rendering job] This only works if a
393   Render Farm is being used; otherwise, background rendering creates a
394   single job for the entire timeline. The number of frames specified
395   here is scaled to the relative CPU speed of rendering nodes and used
396   in a single render farm job. The optimum number is 10 - 30 since
397   network bandwidth is used to initialize each job.
398 \item[Frames to preroll background] This is the number of frames to
399   render ahead of each background rendering job. Background rendering
400   is degraded when preroll is used since the jobs are small. When
401   using background rendering, this number is ideally 0. Some effects
402   may require 3 frames of preroll.
403 \item[Output for background rendering] Background rendering
404   generates a sequence of image files in a certain directory. This
405   parameter determines the filename prefix of the image files. It
406   should be accessible to every node in the render farm by the same
407   path. Since hundreds of thousands of image files are usually
408   created, ls commands will not work in the background rendering
409   directory. The browse button for this option normally will not work
410   either, but the configuration button for this option works.
411 \item[File format] The file format for background rendering has to
412   be a sequence of images. The format of the image sequences
413   determines the quality and speed of playback. JPEG generally works
414   well.
415 \end{description}
416
417 \section{Render Farm Usage}%
418 \label{sec:render_farm_usage}
419
420 Render Farm uses background rendering, a feature of \CGG{} where the
421 video is rendered in the background, to speed up rendering
422 significantly.  Because rendering is memory and cpu intensive, using
423 multiple computers on a network via a render farm is a significant
424 gain.  With \CGG{} installed on all nodes, the master node and the
425 clients communicate via a network port that you specify.
426
427 \CGG{} can distribute the rendering tasks over the network to the
428 other computers of the Render Farm.  The render farm software tries
429 to process all of the rendering in parallel so that several
430 computers can be used to render the results.  The \textit{Total jobs
431   to create} in the setup or labels on the timeline are used to divide
432 a render job into that specified number of tasks.  Each background
433 job is assigned a timeline segment to process and the jobs are sent
434 to the various computer nodes depending upon the load balance.  The
435 jobs are processed by the nodes separately and written to individual
436 files.  You will have to put the files back together via a load with
437 concatenation, or typically by using a command line tool from a
438 script.
439
440 \subsection{Basic Steps to Start a Render Farm}%
441 \label{sub:basic_steps_start_render_farm}
442
443 The following steps are just a guideline to start your render farm.
444 It is assumed that you already have the master and client nodes
445 communication, shared filesystem, permissions and usernames synched.
446
447 \begin{enumerate}
448 \item On the master computer, use \texttt{Settings} $\rightarrow$
449   \texttt{Preferences} $\rightarrow$ \texttt{Performance} \texttt{tab}
450   to set up a Render Farm:
451   \begin{itemize}
452   \item check the \textit{Use render farm} box;
453   \item in the \textit{Hostname} box, keyin your hostname or ip
454     address such as 192.168.1.12 or \textit{localhost};
455   \item enter in a port number such as 401--405 (only a root user
456     can use privileged ports) or $1025$ and click on \textit{Add Nodes};
457   \item you will see something like the following in the Nodes
458     listbox to the right:\newline
459     \begin{tabular}{lllc} On & Hostname & Port & Framerate
460       \\\midrule
461       X & 192.168.1.12 & 401 & 0.0 \\
462       X & 192.168.1.12 & 402 & 0.0 \\
463       X & 192.168.1.12 & 403 & 0.0 \\
464       X & 192.168.1.12 & 404 & 0.0 \\
465       X & 192.168.1.12 & 405 & 0.0 \\
466       X & localhost & 406 & 0.0 \\
467       X & localhost & 407 & 0.0 \\
468     \end{tabular}
469   \item set the Total number of jobs to create;
470   \item click OK on the bottom of the Preferences window.
471   \end{itemize}
472 \item On the client computers ($192.168.1.12$), start 5 background
473   \CGG{} tasks via:
474 \begin{lstlisting}[style=sh]
475 cd {path_to_cinelerra}
476 cin -d 401 cin -d 402
477 ...
478 cin -d 405
479 \end{lstlisting}
480 \item On the master node (localhost), start the 2 background \CGG{}
481   tasks via:
482 \begin{lstlisting}[style=sh]
483 cd {path_to_cinelerra}
484 cin -d 406
485 cin -d 407
486 \end{lstlisting}
487 \item When your video is ready, setup a render job via \texttt{File
488     $\rightarrow$ Render} or \texttt{File $\rightarrow$ Batch Render}
489   and check OK.
490 \item The results will be in the shared file \texttt{path/filename}
491   that you selected in the render menu with the additional numbered
492   job section on the end as $001, 002, 003, \dots 099$ (example,
493   \texttt{video.webm001}).
494 \item When finished, load your new files on new tracks via
495   \texttt{File $\rightarrow$ Load} \textit{concatenate to existing
496     tracks} or if you used ffmpeg, run \textit{RenderMux} from the Shell
497   Scripts icon.
498 \item If you plan on doing more rendering, you can just leave the
499   master/client jobs running to use again and avoid having to restart
500   them.  Or you can kill them when you no longer are using them.
501 \end{enumerate}
502
503 \subsection{Render Farm Menu and Parameter Description}%
504 \label{sub:render_farm_parameter_description}
505
506 Below we describe the Performance tab for configuring a render farm
507 (figure~\ref{fig:farm}).
508
509 \begin{figure}[htpb] \centering
510   \includegraphics[width=1.0\linewidth]{farm.png}
511   \caption{Settings: Preferences: Performance tab, menu
512     to set up your Render Farm}
513   \label{fig:farm}
514 \end{figure}
515
516 \begin{description}
517 \item[Project SMP cpus] although this field is not Render Farm
518   specific, it is useful for \CGG{} to have the CPU count and for
519   using multiple threads.
520 \item[Use render farm] check this to turn on the render farm option.
521   Once checked ALL rendering will be done via the farm including the
522   usual Render (\texttt{Shift-R}).  You may want to turn if off for
523   small jobs.
524 \item[Nodes listbox] displays all the nodes on the render farm and
525   shows which ones are currently enabled. The Nodes listbox has 4
526   columns -- On, Hostname, Port, Framerate -- which show the current
527   values.  An \textit{X} in the \textit{On} designates that that host
528   is currently enabled; \textit{Hostname} shows the name of the host;
529   \textit{Port} shows the port number that host uses; and
530   \textit{Framerate} will either be zero initially or the current
531   framerate value.
532 \item[Hostname] this field is used to edit the hostname of an
533   existing node or enter a new node.
534 \item[Port] keyin the port number of an existing or new node here.
535   You can also type in a range of port numbers using a hyphen, for
536   example $1501-1505$ when you need to add many.
537 \item[Apply Changes] this will allow you to edit an existing node
538   and to then commit the changes to hostname and port. The changes
539   will not be committed if you do not click the OK button.
540 \item[Add Nodes] Create a new node with the hostname and port
541   settings.
542 \item[Sort nodes] sorts the nodes list based on the hostname.
543 \item[Delete Nodes] deletes whatever node is highlighted in the
544   nodes list.  You can highlight several at once to have them all
545   deleted.
546 \item[Client Watchdog Timeout] a default value of $15$ seconds is
547   used here and the tumbler increments by $15$ seconds.  A value of
548   $0$ (zero) disables the watchdog so that if you have a slow client,
549   it will not kill the render job while waiting for that client to
550   respond.
551 \item[Total jobs to create] determines the number of jobs to
552   dispatch to the render farm.  Total jobs is used to divide a render
553   job into that specified number of tasks.  Each background job is
554   assigned a timeline segment to process.  The render farm software
555   tries to process all of the rendering in parallel so that several
556   computers can be used to render the results.
557
558   To start, if you have computers of similar speed, a good number
559   for \textit{Total jobs to create} is the number of computers
560   multiplied by $3$.  You will want to adjust this according to the
561   capabilities of your computers and after viewing the framerates.
562   Multiply them by $1$ to have one job dispatched for every node.  If
563   you have $10$ client nodes and one master node, specify $33$ to have
564   a well balanced render farm.
565 \item[(overridden if new file at each label is checked)] instead of
566   the number of jobs being set to \textit{Total jobs to create}, there
567   will be a job created for each labeled section.  If in the render
568   menu, the option \textit{Create new file at each label} is selected
569   when no labels exist, only one job will be created.  It may be quite
570   advantageous to set labels at certain points in the video to ensure
571   that a key portion of the video will not be split into two different
572   jobs.
573 \item[Reset rates] sets the framerate for all the nodes to $0$.
574   Frame rates are used to scale job sizes based on CPU speed of the
575   node.  Frame rates are calculated only when render farm is enabled.
576 \end{description}
577
578 Framerates can really affect how the Render Farm works.  The first
579 time you use the render farm all of the rates are displayed as $0$
580 in the \texttt{Settings $\rightarrow$ Preferences}, Performance tab
581 in the Nodes box.  As rendering occurs, all of the nodes send back
582 framerate values to the master node and the preferences page is
583 updated with these values.  A rate accumulates based on speed.  Once
584 all nodes have a rate of non-zero, the program gives out less work
585 to lower rated nodes in an effort to make the total time for the
586 render to be almost constant.  Initially, when the framerate scaling
587 values are zero, the program just uses package length -- render size
588 divided by the number of packages to portion out the work (if not
589 labels).  If something goes wrong or the rates become suspect, then
590 all of the rest of the work will be dumped into the last job.  When
591 this happens, you really should \textit{reset rates} for the next
592 render farm session to restart with a good balance.
593
594 \begin{lstlisting}[style=sh]
595 {path_to_cinelerra}/cin -h  # displays some of the options.
596 \end{lstlisting}
597
598 \subsection{Detailed Setup Description}%
599 \label{sub:detailed_setup_description}
600
601 {\color{red} CAUTION }, any exact command lines worked as of
602 $01/2018$ on a Fedora system.  These can change over time and on
603 different operating systems/levels.  Always check/verify any command
604 line before using.
605
606 \begin{description}
607 \item[Set up \CGG{}] A \CGG{} render farm is organized into a master
608   node and any number of client nodes.  The master node is the
609   computer which is running the gui.  The client nodes are anywhere
610   else on the network with \CGG{} installed and are run from the
611   command line.  Before you start the master node for \CGG{}, you need
612   to set up a shared filesystem on the disk storage node as this is
613   the node that will have the common volume where all the data will be
614   stored.  The location of the project and its files should be the
615   same in the client computers as in the master computer and to avoid
616   problems of permissions, it is better to use the same user in master
617   and clients.  For example, if you have the project in
618   \texttt{/home/<user>/project-video} you must create the same
619   directory path on the clients, but empty.  Sharing the directory of
620   the location of your project on the master computer can be done with
621   NFS as described next.  Alternatively, you can look up on the
622   internet how to use Samba to share a directory.
623 \item[Create a shared filesystem and mount using NFS] All nodes in
624   the render farm should use the same filesystem with the same paths
625   to the project files on all of the master and client nodes.  This is
626   easiest to do by setting up an NFS shared disk system.
627   \begin{enumerate}
628   \item On each of the computers, install the nfs software if not
629     already installed.  For example, on Debian 9 you will need to run:
630     (be sure to check/verify before using any command line):
631 \begin{lstlisting}[style=sh]
632 apt-get install nfs-kernel-server
633 \end{lstlisting}
634   \item On the computer that contains the disk storage to be shared,
635     define the network filesystem.  For example to export \texttt{/tmp},
636     edit the \texttt{/etc/exports} file to add the following line:
637 \begin{lstlisting}[style=sh]
638  192.168.1.0/24(rw,fsid=1,no_root_squash,sync,no_subtree_check)
639 \end{lstlisting}
640   \item Next reset the exported nfs directories using:
641 \begin{lstlisting}[style=sh]
642 exportfs -ra
643 \end{lstlisting} and you may have to start or restart nfs:
644 \begin{lstlisting}[style=sh]
645 systemctl restart nfs
646 \end{lstlisting}
647   \item Each of the render farm computers must mount the exported
648     nfs target path.  To see the exports which are visible from a
649     client, login as root to the client machine and keyin:
650 \begin{lstlisting}[style=sh]
651 showmount -e <ip-addr> #using the ip address of the storage host
652 \end{lstlisting}
653   \item to access the host disk storage from the other computers in
654     the render farm, mount the nfs export on the corresponding target
655     path: (be sure to check/verify before using any command line):
656 \begin{lstlisting}[style=sh]
657 mount -t nfs <ip-addr>:/<path> <path>
658 \end{lstlisting} where \texttt{<path>} is the storage host
659     directory, and \texttt{<ip-addr>} is the network address of the
660     storage host.  Because all of the computers must have the same
661     directory path, create that same directory path with the same
662     uid/gid/permissions on each storage client computer ahead of time.
663   \item To make this permanent across reboots on the client nodes,
664     add the following line to \texttt{/etc/fstab}:
665 \begin{lstlisting}[style=sh]
666 {masternode}:/nfsshare /mnt nfs defaults 0 0
667 \end{lstlisting} You can make this permanent on the disk storage
668     host BUT the command lines shown, which were correct in January 2018
669     on Fedora, may be different for your operating system or in the
670     future.  In addition if your network is not up, there may be
671     numerous problems.  If you make a mistake, your system may not boot.
672     To make permanent, add the following line to \texttt{/etc/fstab}:
673 \begin{lstlisting}[style=sh]
674 192.168.1.12:/tmp /tmp nfs rw,async,hard,intr,noexec,noauto 0 0
675 \end{lstlisting} You will still have to mount the above manually
676     because of the \textit{noauto} parameter but you won’t have to
677     remember all of the other necessary parameters.  Depending on your
678     expertise level, you can change that.
679
680     Later, to remove access to the storage host filesystem:
681 \begin{lstlisting}[style=sh]
682 umount <path>
683 \end{lstlisting}
684
685     Be aware that you may have to adjust any security or firewalls
686     you have in place.  \textit{Most firewalls will require extra rules
687       to allow nfs access}.  Many have built-in configurations for this.
688   \end{enumerate}
689 \item[Configure Rendering on Master Node] There is 1 master node
690   which is running the \CGG{} gui and where the video will be edited
691   and the command given to start up the rendering.  Any number of
692   client computers can be run from the command line only, so they can
693   be headless since no X or any graphical libraries are needed.  Of
694   course, the \CGG{} software must be installed on each of the client
695   computers.
696   \begin{enumerate}
697   \item Assuming you already have \CGG{} installed on the master
698     node, start \CGG{} by clicking on the icon or by typing the
699     following command on the terminal screen:
700     \texttt{/{cinelerra\_path}/cin}.
701   \item Use the file pulldown \texttt{Settings $\rightarrow$
702       Preferences}, the Performance tab, to set up your Render Farm
703     options in the Render Farm pane.
704   \item Check the \textit{Use render farm} option.  By default, once
705     you enable the option of Render Farm, rendering is usually done
706     using the render farm.  Batch rendering can be done locally, or
707     farmed.
708   \item Add the hostname or the IP address of each of the client
709     nodes in the Hostname textbox and the port number that you want to
710     use in the Port textbox.  You can make sure a port number is not
711     already in use by keying in on the command line:
712 \begin{lstlisting}[style=sh]
713 netstat -n -l -4 --protocol inet
714 \end{lstlisting} Next, click on the \textit{Add Nodes} button and
715     then you will see that host appear in the Nodes list box to the
716     right.  The \texttt{X} in the first column of the nodes box denotes
717     that the node is active.  To review the \textit{standard} port
718     allocations, check the \texttt{/etc/services} file.
719   \item Enter the total jobs that you would like to be used in the
720     \textit{Total job} textbox.
721   \item The default watchdog timer initial state is usually just
722     fine but can be adjusted later if needed.
723   \item Click OK on the Preferences window when done.
724   \end{enumerate}
725 \item[Create Workflow] While working on the master computer, it is
726   recommended that you keep all the resources being used on the same
727   shared disk.  Load your video/audio piece and do your editing and
728   preparation.  Add any desired plugins, such as a Title, to fine-tune
729   your work.  You want to make sure your video is ready to be rendered
730   into the final product.
731 \item[Start the Client Nodes] To start up the client nodes run
732   \CGG{} from the command line on each of the client computers using
733   the following command:
734 \begin{lstlisting}[style=sh]
735 /{cinelerra_pathname}/cin -d [port number]
736 # for example:
737 /mnt1/bin/cinelerra -d 401
738 \end{lstlisting} This starts \CGG{} in command prompt mode so that
739   it listens to the specified port number for commands from the master
740   node for rendering.  When you start each of the clients up, you will
741   see some messages scroll by as each client is created on that
742   computer, such as:
743 \begin{lstlisting}[style=sh]
744 RenderFarmClient::main_loop: client started
745 RenderFarmClient::main_loop: Session started from 127.0.0.1
746 \end{lstlisting} As it completes its jobs, you will should see:
747 \begin{lstlisting}[style=sh]
748 RenderFarmClientThread::run: Session finished
749 \end{lstlisting} A quick way to start a sequence of clients is to
750   use:
751 \begin{lstlisting}[style=sh,mathescape]
752 for n in `seq 1501 1505`; do
753   cin -d $\$$n
754 done
755 \end{lstlisting}
756 \item[Render Using Render Farm] After you have followed the
757   preceding steps, you are ready to use the render farm.  Click on
758   \texttt{File $\rightarrow$ Render}\dots which opens the render
759   dialog.  The most important point here is to use for \textit{the
760     Output path / Select a file to render to} a path/file name that is
761   on the shared volume that is also mounted on the clients.  Click on
762   OK to render. The \CGG{} program divides the timeline into the
763   number of jobs specified by the user.  These jobs are then
764   dispatched to the various nodes depending upon the load balance. The
765   first segment will always render on the master node and the other
766   segments will be farmed out to the render nodes.  Batch Rendering,
767   as well as BD/DVD rendering, may use the render farm.  Each line in
768   the batchbay can enable/disable the render farm.  Typically, video
769   can be rendered into many file segments and concatenated, but
770   normally audio is rendered as one monolithic file (not farmed).
771
772   Another performance feature which can use the Render Farm is
773   \textit{Background Rendering}.  This is also enabled on the
774   \texttt{Preferences $\rightarrow$ Performances} tab.  The background
775   render function generates a set of image files by pre-rendering the
776   timeline data on the fly.  As the timeline is update by editing, the
777   image data is re-rendered to a \textit{background render} storage
778   path.  The Render Farm will be used for this operation if it is
779   enabled at the same time as the \textit{background render} feature.
780 \item[Assemble the Output Files] Once all of the computer jobs are
781   complete, you can put the output files together by using the shell
782   script, \textit{RenderMux} (from the menubar \textit{scripts} button
783   just above FF), if the files were rendered using ffmpeg, or you can
784   load these by creating a new track and specifying concatenate to
785   existing tracks in the load dialog in the correct numerical order.
786   File types which support direct copy can be concatenated into a
787   single file by rendering to the same file format with render farm
788   disabled as long as the track dimensions, output dimensions, and
789   asset dimensions are equal.
790 \end{description}
791
792 \subsection{Quick and Easy Render Farm Setup – The Buddy System
793   Way}%
794 \label{sub:buddy_system_way}
795
796 These steps are for quickly setting up render farm with the least
797 amount of additional system work, but it is non-optimal.  It is
798 useful in situations where a few people all show up with their
799 laptops to work together on the same video/audio file and you don’t
800 want to bother setting up NFS for a shared disk.
801
802 \begin{enumerate}
803 \item Make sure the \CGG{} program is installed on all of the
804   computers and the network between the main computer and the client
805   computers is working.  Use the same version if possible.
806 \item Load your video file on the master node and use \texttt{File
807     $\rightarrow$ Save as}\dots to save it to \texttt{/tmp}.
808 \item Move that same file with the same name to \texttt{/tmp} on all
809   of the client computers via rsh or sneaker net -- the ONLY reason
810   you are doing this is to avoid having to set up NFS or Samba on the
811   buddy client laptops that show up!
812 \item Edit your video/audio file to get it the way you want it and
813   add the plugins, such as a Title, etc.
814 \item Check for a set of unused ports in \texttt{/etc/services}
815   file, if username is root usually $401-425$ are available; if
816   non-root, then $1024-1079$.
817 \item On the master computer, in \texttt{Settings $\rightarrow$
818     Preferences, Performance} tab:
819   \begin{itemize}
820   \item check the box \textit{Use render farm}
821   \item keyin localhost for the hostname or an ip address of the
822     buddy client node
823   \item keyin the desired port number for each client; and use
824     \textit{Add Node} for each host
825   \item set total jobs to the number of client computers $+1$
826     multiplied by $3$ (or proportion to client speeds)
827   \item check OK
828   \end{itemize}
829 \item On each buddy client, create a job for each port:
830 \begin{lstlisting}[style=sh]
831 /{cinelerra_pathname}/cin -d port#
832 \end{lstlisting}
833 \item On the master, bring up the render menu and name the output
834   files, for example \texttt{/tmp/myoutput.mp4}.
835 \item The client nodes output results will be on their local
836   \texttt{/tmp} filesystems so you will have to again use
837   \textit{rsh/ftp} or \textit{usb sneaker net} to move them over to
838   the main computer.  File names will be the render job output file
839   name with port number tacked on
840   (e.g. \texttt{/tmp/hb.mp4001...mp4005}).
841 \item Load the files by concatenate to existing track on the master
842   node or use RenderMux shell script.
843 \end{enumerate}
844
845 \subsection{Multi-core Computers Render Farm Setup}%
846 \label{sub:multi_core_render_farm_setup}
847
848 If you are lucky enough to have a computer with a large cpu core
849 count, setting up a render farm can really take advantage of using
850 all of the cpus. This is much faster than the default automatic
851 threading capability. Since you don’t need to communicate with other
852 computers, you will not have to be concerned about TCP communication
853 or shared disks/files. When you are going to be doing other work
854 simultaneously while rendering a large job, you will want to leave
855 some of the cpus available for that.  Be sure to set “Project SMP
856 cpus” in the Settings $\rightarrow$ Preferences, Performance tab to your CPU
857 count.
858
859 \subsection{Troubleshooting Tips and Warnings}%
860 \label{sub:troubleshhoting_tips_warnings}
861
862 \noindent If you have problems running the Render Farm.  Here is a
863 list of items to check.
864
865 \begin{itemize}
866 \item \CGG{} must be installed on the master node and all client
867   machines.
868 \item It is best to have the same username available on all nodes to
869   avoid problems with access rights.
870 \item Check file permissions and ownership to ensure that the
871   clients all have access.
872 \item If a node does not have access to an input asset it will not
873   die, but just display error messages.
874 \item If a node can not access an output asset, the rendering will
875   abort.
876 \item A port in use when stopped may take up to $30$ seconds to time
877   out before you can restart the jobs.
878 \item Each of the port combinations have to be unique across
879   clients, and not already in use in the network.
880 \item \CGG{} load balances on a first come, first serve basis.  If
881   the last section of the video is sent to the slowest node, the
882   render job will have to wait for the slowest node to finish.  It
883   would be better to start on the slowest node with the earlier
884   section of the video so keep that in mind when designating port
885   numbers.
886 \item If not running as root, a port number in the higher range of
887   $1024$ and above must be used instead of the $400+$ range.
888 \item The master and client jobs on the ports do not go away so if
889   you want to stop them, you will have to kill them via: \texttt{kill
890     PID\#}.
891 \item Check to see if there are services listening on the ports to
892   use: \texttt{netstat -n -l -4 --protocol inet}
893 \item There is a watchdog timer in \CGG{} and if there is no
894   response from a client in the designated number of seconds, it will
895   kill the render job.
896 \item The \textit{localhost} should exist as $127.0.0.1$ in
897   \texttt{/etc/hosts} and as the \texttt{lo} network device in
898   ifconfig.
899 \item If the job loads become unbalanced, you may want to
900   \textit{reset rates} to start over for new framerates.
901 \item If jobs are split in a key section on the timeline, you may
902   wish to \textit{use labels} to prevent this.
903 \item For testing purposes, you may want to start a client in the
904   foreground using \texttt{-f} instead of \texttt{-d}.
905 \item If one of the client computers is unavailable, check to see if
906   there is an \texttt{X} to the left of the \texttt{nodename} in the
907   Nodes listbox.  Check the \texttt{X} to disable it which sets ON to
908   OFF.
909 \item A red message in the lower left hand corner of the main
910   timeline that reads \textit{Failed to start render farm} often means
911   that the client \CGG{} programs were not started up.
912 \item A message of \texttt{RenderFarmWatchdog::run 1 killing server
913     thread \\ \#address\#} means that the client did not respond in
914   time.  You can adjust the timer in \texttt{Settings $\rightarrow$
915     Preferences, Performance} tab.
916 \item When you get the message \texttt{RenderFarmClient::main\_loop:
917     bind port 400: Address already in use}, use a different port.
918 \item A message of \texttt{RenderFarmServerThread::open\_client:
919     unknown host abcompany} means that the hostname of abcompany is not
920   in \texttt{/etc/hosts} so you will have to add it or use the ip
921   address instead.
922 \item There are numerous error messages associated with file
923   \textit{open/close/status} or problems with the file that should be
924   dealt with according to what is printed out.
925 \item Other illustrative messages may be shown such as:
926   \texttt{RenderFarmClientThread:: run: Session finished}.
927 \end{itemize}
928
929 And here are a couple of more tips for making Render Farm specific
930 for your setup.
931 \begin{itemize}
932 \item Because \textit{index files} speed up displaying the video you
933   may want to share these files with the clients on a shared
934   filesystem. More information on index files configuration is
935   outlined in~\ref{sub:index_file_section}.
936 \item Or, one of the convenient features of \CGG{} is the
937   redirection of the path via \texttt{CIN\_CONFIG} as in:
938 \begin{lstlisting}[style=sh]
939 CIN_CONFIG="/<shared_file_pathname>/<filename_such_as_.bcast5>" cin
940 \end{lstlisting} This means that you can make project related
941   configurations that do not impact the default \texttt{\$HOME}
942   config.  You can either export your default \texttt{\$HOME} config
943   or the \texttt{CIN\_CONFIG} config to use on the render farm.
944 \end{itemize}
945
946 \paragraph{Warnings}
947
948 If one of the render farm computers is connected to the internet,
949 you should use a firewall to maintain the safety of all of the
950 computers.  The ports have to be reachable for the intranet but you
951 do not want the ports to be open to the outside.
952
953 \section{Some Specific Rendering}%
954 \label{sec:some_specific_rendering}
955
956 \noindent The next few pages relate to rendering for specific common
957 cases.
958
959 \subsection{FFmpeg Common H.264 Rendering}%
960 \label{sub:ffmpeg_h264_rendering}
961
962 Because H.264 is so widely used, the method in \CGG{} Infinity is
963 outlined below.  These setup steps make it easy to just get started.
964
965 \begin{itemize}
966 \item File $\rightarrow$ Render
967 \item File Format $\rightarrow$ FFMPEG + mp4
968 \item Video Wrench $\rightarrow$ Preset $\rightarrow$ h264.mp4 +
969   bitrate: 6000000 (or whatever) + OK
970 \item Audio Wrench $\rightarrow$ Preset $\rightarrow$ h265.mp4 +
971   bitrate: 224000 (or whatever) + OK
972 \item Set your target path in: Render $\rightarrow$ Select a file to
973   render to
974 \item Set your timeline in: Render $\rightarrow$ Render range +
975   click Project
976 \item Set your insertion strategy: Replace project (or whatever)
977 \item Press OK to start rendering.
978 \end{itemize}
979
980 \subsection{Lossless Rendering}%
981 \label{sub:loseeless_rendering}
982
983 Lossless means that in the compression of a file, all of the
984 original data, every single bit, can be recovered when the file is
985 uncompressed.  This is different than \textit{lossy compression}
986 where some data is permanently deleted so that when uncompressed,
987 all of the original data can not be exactly recovered.  Lossy is
988 generally used for video and sound, where a certain amount of
989 information loss will not be detected by most users or the playback
990 hardware does not reproduce it anyway -- it is a trade-off between
991 file size and image/sound quality.  The files created will be more
992 than 10 times larger than usual.  Most players will not be able to
993 decode lossless as the bitrate will overwhelm the device.
994
995 For x264 lossless compression to work, the only color model allowed
996 here is yuv420p.  Any other specification will be converted to
997 yuv420p and the data will be modified.  Also, keep in mind that the
998 YUV color model has to be converted to RGB, which also modifies the
999 data.
1000
1001 To use x264 lossless rendering -- choose File format of ffmpeg, m2ts
1002 in the Render window.  Click on the Video wrench, which brings up
1003 the Video Preset window and scroll down in the Compression filebox
1004 and choose \texttt{lossless.m2ts}.  \textit{Preset=medium} is the
1005 default, but can be varied from \textit{ultrafast} (least amount of
1006 compression, but biggest file size) to \textit{veryslow} (most
1007 amount of compression, but still HUGE) in the parameter box where
1008 you see $qp=0$.  This option is also available for bluray creation.
1009
1010 \subsection{Extra “cin\_” Options for Render with FFmpeg}%
1011 \label{sub:extra_cin_option_ffmpeg}
1012
1013 There are several special parameters that can be used in the ffmpeg
1014 options file to pass values to the codecs that are not normally
1015 available.  They're called Global Options. These are explained
1016 below.
1017
1018 \paragraph{cin\_pix\_fmt} The Render menus allows you to choose the
1019 codec input pixel format (figure~\ref{fig:yuv420}).  The Pixels
1020 selection provides the available pixel format options for the chosen
1021 codec type; valid choices vary for the different file types.  This
1022 list represents the formats that the codec advertises.  It is not
1023 always complete, and it may include options that are not legal with
1024 all parameter configurations.
1025
1026 \begin{figure}[htpb] \centering
1027   \includegraphics[width=1.0\linewidth]{yuv420.png}
1028   \caption{Render \& Video Preset menus displaying Pixel choices}
1029   \label{fig:yuv420}
1030 \end{figure}
1031
1032 \begin{itemize}
1033 \item The \textit{Bitrate}, \textit{Quality}, and \textit{Pixels}
1034   fields are only updated when the Video Options are reloaded.  This
1035   occurs when you either change the ffmpeg file format, or video
1036   presets compression fields.
1037 \item If the video options preset has \textit{cin\_pix\_fmt}
1038   defined, its value will be loaded as the default.  If you override
1039   the default, the value you specify will be used.
1040 \item If the video options preset does not have
1041   \textit{cin\_pix\_fmt}, the default pixel format will be computed by
1042   ffmpeg (\textit{avcodec\_find\_best\_pix\_fmt\_of\_list}), using the
1043   session format as the source choice.  The \textit{best} is usually
1044   the format which is most similar in color and depth.
1045 \item If no choices are available, yuv420p for video will be used.
1046 \item You can also specify ffmpeg pixel formats which are not in the
1047   list.  The list is provided by ffmpeg as input selection, but is
1048   more like suggestions than fact.  For example, the raw formats can
1049   take almost any format, but the rawvideo codec actually specifies no
1050   legal formats.
1051 \end{itemize}
1052
1053 \noindent Some option files provide \textit{cin\_pix\_fmt} to
1054 suggest a choice for good quality output or to prevent parameter
1055 errors when the other provided parameters conflict with the
1056 \textit{best} pixel format.  This is the case in
1057 \texttt{faststart\_h264.mp4} where the \textit{profile=high}
1058 parameter dictates pixel format must be \texttt{yuv420p}.
1059
1060 \paragraph{cin\_bitrate} If you specify the bitrate, you can not
1061 specify the quality.\\ Example: \textit{cin\_bitrate=2000000}
1062
1063 \paragraph{cin\_quality} If you specify the quality, you can not
1064 specify the bitrate.\\ Example: \textit{cin\_quality=7}
1065
1066 \paragraph{cin\_stats\_filename} This parameter is useful for 2 pass
1067 operations.\\ Example: \texttt{cin\_stats\_filename
1068   /tmp/cin\_video\_vp9\_webm}
1069
1070 \paragraph{cin\_sample\_fmt} For audio the preset sample format
1071 default is computed in a similar way as stated above for video or
1072 can be set with the \textit{cin\_sample\_fmt} parameter
1073 (figure~\ref{fig:audio}).  If no choices are provided, s16 will be
1074 used.\\ Example: \textit{cin\_sample\_fmt=s16}
1075
1076 \begin{figure}[htpb] \centering
1077   \includegraphics[width=0.7\linewidth]{audio.png}
1078   \caption{Render menu showing where Samples is}
1079   \label{fig:audio}
1080 \end{figure}
1081
1082 \paragraph{Private Options} (muxers). In the window of the
1083 \textit{wrench} in addition to the \textit{View} button, which
1084 allows more global options and changes to the formats, there is an
1085 additional \textit{Format} button that allows you to modify the
1086 Private Options, i.e.\ relating to specific muxing formats. More
1087 information on all these options can be found at
1088 \href{https://ffmpeg.org/ffmpeg-all.html#Format-Options}{ffmpeg.org}
1089 sections 19 and 21.
1090
1091 \subsection{Two-pass Encoding with FFmpeg}%
1092 \label{sub:two_pass_encoding_ffmpeg}
1093
1094 In \CGG{} for two-pass, you need to run ffmpeg twice, with the same
1095 settings, except for designating the options of pass~1 for the first
1096 pass and then pass~2.  In pass~1, a logfile that ffmpeg needs for
1097 the second pass is created.  In pass~1 the audio codec should be
1098 specified that will be used in pass~2.  For more information on
1099 ffmpeg 2-pass, check
1100 \href{https://trac.ffmpeg.org/wiki/Encode/H.264}{ffmpeg.org}.
1101 Different libraries may have different requirements and you will
1102 probably have to determine this by looking online at ffmpeg or
1103 looking directly at that code.
1104
1105 This 2 line ffmpeg 2-pass operation can be functionally duplicated
1106 in \CGG{} in the steps below them:
1107
1108 \begin{lstlisting}[style=sh]
1109 ffmpeg -y -i $INPUT \
1110   -c:v libx264 -b:v 2600k -pass 1 \
1111   -c:a aac -b:a 128k -f mp4 /dev/null && \
1112   ffmpeg -i $INPUT \
1113     -c:v libx264 -b:v 2600k -pass 2 \
1114     -c:a aac -b:a 128k $OUTPUT.mp4
1115 \end{lstlisting}
1116
1117 \begin{enumerate}
1118 \item After you have completed your editing, do a Save Session with
1119   \texttt{File $\rightarrow$ Save as}\dots Before starting, be sure
1120   your session is ready for batch render. That is, positioned at the
1121   beginning and nothing selected.
1122 \item Bring up \texttt{File $\rightarrow$ Batch Render}\dots where
1123   you will do the setup.
1124 \item Click on the \textit{Delete} box to remove old jobs
1125   highlighted in the bottom listbox.
1126   \begin{itemize}
1127   \item For the \textit{File Format} choose ffmpeg and mp4 for the
1128     type.
1129   \item Set \textit{Output path} to the path and filename for the
1130     render output file.
1131   \item Click on \textit{Use Current EDL} to use the designated EDL
1132     Path file.
1133   \item Click on \textit{New} and you will see a new highlighted job
1134     show up in the listbox at the bottom.
1135   \item Use the Audio wrench to set bitrate to $128000$ ($128k$ as
1136     in ffmpeg example above).
1137   \item Click checkmark OK\@.  Open the video tools with the video
1138     wrench.
1139   \item Set the Video Compression to \textit{h264.mp4} (as seen in
1140     the example).
1141   \item Set the bitrate to $2600000$ ($2600k$ as in ffmpeg example
1142     above).
1143   \item Add the following 2 lines after the first line:
1144 \begin{lstlisting}[style=sh]
1145 flags +pass1
1146 passlogfile /tmp/"{temporary log file name}.log"
1147 \end{lstlisting} Click checkmark OK.
1148   \end{itemize}
1149 \item Click on \textit{New} to create the second pass job.  You will
1150   see this second job in the listbox below.  Use the Video wrench and
1151   change pass1 to pass2 as follows.
1152 \begin{lstlisting}[style=sh]
1153 flags +pass2
1154 \end{lstlisting}
1155 \item Click checkmark OK.
1156 \item Click on the \textit{Start} box and watch it go!
1157 \item You can now check the output file for results.  At the time
1158   this was documented, \textit{rc=2pass} will be in the output.
1159 \end{enumerate}
1160
1161 If you need to re-render this, the Batch Render will still be set up
1162 but you have to click on the \textit{Enabled} column in the listbox
1163 to re-enable the jobs to run which puts an X there.  Click Start
1164 again. You can reuse batch job using the \textit{save jobs} and
1165 \textit{load jobs} buttons in the batch render dialog.
1166
1167 \paragraph{Render shortcuts for webm, h264, h265} are available by
1168 using the option files that are already set up for this purpose.
1169 Use the render menu as usual, with ffmpeg/mp4, choose h264 or h265
1170 \textit{pass1of2\_h26x} for the video and
1171 \textit{passes1and\-2\_h26x} for the audio; with ffmpeg/webm, choose
1172 \textit{pass1of2\_vp9}.  When that is finished, you will have to use
1173 the render menu again and this time for video, choose
1174 \textit{pass2of2\_h26x} or \textit{pass2of2\_vp9}.  The logfile is
1175 hard coded in the options file so will write over any currently
1176 existing logfile if you do not change it before you start the
1177 render.
1178
1179 \paragraph{Requirements for some other libraries} (used instead
1180 of \textit{flags +pass1} \& \textit{passlogfile}):
1181 \begin{description}
1182 \item[x265:] add this line:
1183 \begin{lstlisting}[style=sh]
1184 x265-params=pass=1:stats=/tmp/{temporary-log-file-name}.log
1185 \end{lstlisting} at the time this document was written, you should
1186   see in the output: \textit{stats-read=2}
1187 \item[libvpx-vp9, xvid, and huffyuv:]~
1188 \begin{lstlisting}[style=sh]
1189 cin_stats_filename /tmp/{temporary-log-file-name}.log
1190 flags +pass1 (or flags +pass2 for the second pass)
1191 \end{lstlisting}
1192 \end{description}
1193
1194 \textit{NOTE:} for vp9, the best Pixels is \textit{gbrp}
1195
1196 \subsection{Use case: High Efficiency Video Coding (HEVC)}%
1197 \label{sub:use_case_hevc}
1198
1199 An example of video profile based on CRF, a quality-controlled
1200 variable bitrate, instead of fixed quality scale (ABR).  HEVC
1201 (H.265) was developed as a successor to AVC (H.264) to more
1202 efficiently compress the future large amounts of data from 2/4/8k
1203 videos.  In comparison to AVC, an average saving of around 30
1204 percent can be assumed for the same quality.  Because HEVC is not
1205 bound to any size format, it is suitable for virtually any image
1206 size.
1207
1208 The following example is HD and FullHD oriented and produces a
1209 picture quality similar to the Blu-ray with some limitations.  As
1210 container Matroska (\texttt{.mkv}) is used, but also mp4 and others
1211 are possible.
1212
1213 \begin{lstlisting}[style=sh]
1214 matroska libx265
1215
1216 # CRF 16 creates a balanced compromise
1217 # between quality and file size.
1218 crf=16
1219
1220 # Preset changes encoding speed and generally
1221 # degrades the overall result. Medium (default)
1222 # always fits.
1223 preset=medium
1224
1225 # Additional parameters that are passed on to the codec.
1226 # me=star improves the search for very fast
1227 # movements, but slows down the encoding.
1228 #x265-params=me=star
1229
1230 # Keyint does FFmpeg automatically, otherwise
1231 # the setting must match the frame rate.
1232 #keyint_min=25
1233
1234 # Profile does FFmpeg automatically.
1235 #profile=high
1236
1237 # Source sRBG and retention of color space.
1238 # 720/1080=bt709 if no profile set. Useful
1239 # for formats smaller than 720 if no lossy
1240 # conversion is desired.
1241 colorspace=bt709
1242 color_trc=bt709
1243 color_primaries=bt709
1244
1245 # Output in 10 bit, prevents 8-bit step formation
1246 pixel_format=yuv420p
1247 \end{lstlisting}
1248
1249 \noindent \textit{NOTE:}
1250
1251 A CRF of 16 delivers satisfactory results in most cases. However, if
1252 the video material is really \emph{grainy}, a CRF~16 can lead to
1253 unwanted large files.  In this case, a trial export of perhaps one
1254 minute should be performed. The resulting bit rate can be used to
1255 correct the CRF to 17,\,18,\,19\ldots -- remember, a CRF of $0$ (zero)
1256 means lossless, the higher the number the stronger the lossy
1257 compression. The approximate calculation of the final file size can
1258 be extrapolated from the sample export.
1259
1260 The color space information must be used explicitly so that it can
1261 be included in the video. \CGG{} or FFmpeg does not write it by
1262 itself. Without this information the players (e.\,g.\
1263 \href{https://mpv.io/}{mpv}) stick to the dimensions of the video
1264 and take the assumed color model from a table. With videos in the
1265 dimensions from 720 to 1080 this is bt709. For smaller dimensions,
1266 e.\,g.\ DVD, bt601 is assumed and for 4k and above it is
1267 bt2020. Normally this is not a problem, but if you want to export a
1268 FullHD without color loss to a smaller size like 576 for example,
1269 you have to inform the encoder as well as the decoder of the
1270 player. This also applies if the videos are to be loaded on video
1271 platforms, where they are then converted into videos of different
1272 sizes. It is a security measure to prevent false colors, such as the
1273 color profiles in digital photos and the copies made from them.
1274
1275 The HEVC tuning has not been considered here, because it is is
1276 rarely used and requires background knowledge.
1277
1278 Further links:
1279 \begin{itemize}
1280 \item \href{http://x265.readthedocs.org/en/default/}{x265
1281     Documentation}
1282 \item \href{http://x265.readthedocs.org/en/latest/cli.html}{x265
1283     Command Line Options}
1284 \item \href{http://x265.readthedocs.org/en/latest/presets.html}{x265
1285     Presets/Tuning}
1286 \end{itemize}
1287
1288 \subsection{Piping Video to a Command Line}%
1289 \label{sub:piping_video_command_line}
1290
1291 You can pipe a video to any command line on the computer, such as
1292 ffmpeg.  This can be especially useful with raw video files.  Next
1293 is an example usage.
1294
1295 \begin{enumerate}
1296 \item on a terminal window create a named pipe file, for example:
1297 \begin{lstlisting}[style=sh]
1298 mknod /tmp/piper.yuv p
1299 \end{lstlisting} load your video and do your editing
1300 \item set up your Render (\texttt{Shift-R}), you can choose a raw
1301   format such as \textit{yuv} or \textit{rgb}
1302 \item for the filename \textit{Select a file to render to}, use the
1303   named pipe as created in step 1 (\texttt{/tmp/piper.yuv})
1304 \item for \textit{Insertion Strategy}, you will want to make sure to
1305   select \textit{insert nothing}
1306 \item click for OK on the green checkmark.(the \CGG{} gui will look
1307   like it is hanging while waiting for a command line to use the
1308   pipe.)
1309 \item on the terminal window, keyin your command, for example:
1310 \begin{lstlisting}[style=sh]
1311 /mnt0/build5/cinelerra-5.1/thirdparty/ffmpeg-3.4.1/ffmpeg -f \
1312   rawvideo -pixel_format yuv420p -video_size 1280x720 \
1313   -framerate 30000/1001 -i /tmp/piper.yuv /tmp/pys.mov
1314 \end{lstlisting}
1315 \end{enumerate}
1316
1317 A slightly different option can be used instead that may be more
1318 familiar to some.  In the render menu after choosing the File Format
1319 of \textit{ffmpeg}, use the pulldown to choose \textit{y4m} as the
1320 file type.  This choice results in putting a header on the rendered
1321 output with some pertinent information that can be used for ffmpeg
1322 processing thus alleviating the requirement for
1323 \textit{pixel\_format}, \textit{video\_size}, and \textit{framerate}
1324 on the ffmpeg command line.  In this case the format is
1325 \textit{yuv4mpegpipe} instead of \textit{rawvideo}.  An example
1326 command line would look as follows (assuming the created pipe is
1327 called \texttt{piper.y4m}):
1328 \begin{lstlisting}[style=sh]
1329 ffmpeg -f yuv4mpegpipe -i /tmp/piper.y4m -vcodec libx264 /tmp/test.mp4
1330 \end{lstlisting}
1331
1332 \subsection{Faststart Option for MOV type files}%
1333 \label{sub:faststart_option_mov0}
1334
1335 If you have mov video and want to be able to start playing without
1336 having to first load the entire video, \textit{-movflags=+faststart}
1337 is needed for ffmpeg to put the meta-data, known as the \textit{moov
1338   atom}, at the beginning of the file.  Otherwise, ffmpeg puts this
1339 atom at the end of the video file which means you have to wait to
1340 play until the whole video is loaded.  Or worse yet, if the file
1341 becomes damaged in the middle and you can not get to the end, you
1342 won’t be able to play anything.
1343
1344 Now you can have the \textit{moov atom} put on the front of the file
1345 (automatically via a second pass).  To do this, when rendering using
1346 ffmpeg \& either the mp4 or qt format/container, click on the
1347 video/audio wrenches and choose \textit{faststart\_h264}.  With the
1348 \textit{qt} format, settings will just be the default whereas the
1349 \textit{mp4} format uses the highest quality and lowest file size as
1350 possible, but you can easily modify these options in the associated
1351 Video Preset textbox.
1352
1353 %%% Local Variables:
1354 %%% mode: latex
1355 %%% TeX-master: "../CinelerraGG_Manual"
1356 %%% End: