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