f80ceb31d6e9eea3758d05bd715df43d3e147a3f
[goodguy/cin-manual-latex.git] / parts / Tips.tex
1 \chapter{Performance and other Tips}%
2 \label{cha:performance_tips}
3
4 Performance of Cinelerra is related to the software and video format being used in conjunction with your computer system hardware -- the number of CPUs and its speed, I/O bus speed, graphics card, and amount of available memory. A basic, less powerful system will be sufficient for users working with audio only or lower resolution video formats.  Higher end computers will be needed when playing and working with higher resolution formats, like 1080p or 4k. Adding effects and multiple tracks will require more cpu, memory, and various other resources to 
5 perform at an acceptable level.
6
7 Perhaps the easiest method for determining if your performance could be improved is to look at the numerical value displayed as \textit{Framerate achieved}.  Good performance means that when \textit{Play every frame} is set 
8 in \texttt{Settings $\rightarrow$ Preferences, Playback A} tab, the frames/second (frames per second or fps) in playback might be almost always at the maximum rate of your project setting and/or video frame rate. You can check this in \texttt{Settings $\rightarrow$ Preferences, Playback A}, by watching \textit{Framerate achieved} while playing forward.  A higher number is better, up to the format frame rate of the video.
9
10 Some computer hardware factors to consider for better performance are listed here:
11 \begin{itemize}
12         \item Multi-core and more SMP processors greatly improve Cinelerra speed by making use of threads.
13         \item A large amount of free memory available can help speed up operations by avoiding unnecessary disk
14         swaps and keeping videos easily accessible in memory.
15         \item Video editing is almost always I/O intensive. To create longer running videos at high resolution
16         you will want to have a lot of disk space available on fast access disks.
17         \item Cinelerra benefits from OpenGL hardware acceleration. A good graphics card is worthwhile to have.
18         \item Multiple monitors really come in handy to increase productivity as you can see more information and
19         in bigger windows so you do not have to keep moving windows around.
20 \end{itemize}
21 Besides the above hardware recommendations, this section covers tips for performance improvements and tips on how to perform some specific tasks, often for older media.
22
23 \section{Hardware video acceleration}%
24 \label{sec:hardware_video_acceleration}
25
26 With certain newer, more powerful graphics boards and newer device drivers, there is the potential for enhanced \textit{decode} and \textit{encode} performance.   Decode refers to loading and playing video in Cinelerra. The GPU, Graphics Processing Unit, on the graphics board is accessed via one of the following libraries: vdpau or vaapi. The hardware acceleration done by the graphics card increases performance by activating certain functions in connection with a few of the FFmpeg decoders. This use makes it possible for the graphics card to decode video, thus offloading the CPU.  Decode operations are described here next.  
27 Encode refers to rendering video and is described at the end of this section
28 under \hyperref[sub:gpu_hardware_encoding]{GPU hardware encoding}.
29
30 VDPAU, Video Decode and Presentation API for Unix, is an open source library to offload portions of the video decoding process and video post-processing to the GPU of graphics boards, such as Nvidia.  It may also apply to Nouveau and Amdgpu boards (by wrapper), but that has not been verified.
31
32 VA-API, Video Acceleration API, is an open source library which provides both hardware accelerated video encoding and decoding for use mostly with Intel (and AMD) graphics boards. 
33
34 Currently only the most common codecs, such as MPEG-1, MPEG-2, MPEG-4, and H.264 /MPEG-4, are accelerated/optimized by the graphics card to play these particular video formats efficiently. The other formats are not optimized so you will see no performance improvement since the CPU will handle them as before, just as if no hardware acceleration was activated. There are many different graphics cards and computer systems setup, so you will have to test which specific settings work best for you.  So far this has been tested at least with Nvidia, Radeon, and Broadwell graphics boards on some AMD and Intel computers; depending on the graphics card, two to ten times higher processing speeds can be achieved.  However, most graphic operations are single-threaded so that 
35 performing the operations in the hardware may actually be slower than in software making use of multiple CPUs, which frequently multi-thread many operations simultaneously.
36
37 \subsection{GPU hardware decoding}%
38 \label{sub:gpu_hardware_decoding}
39
40 \begin{enumerate}
41         \item Verify that you have installed \textit{libva-dev} or \textit{libva} on your operating system.
42         \item Verify that you also have \textit{libvdpau-dev} or \textit{libvdpau} installed.
43         \item Verify \texttt{Settings $\rightarrow$ Preferences, Playback} tab, Video Driver is set to\textit{ X11} -- or \textit{X11-OpenGL} if that   produces better results for your configuration.
44         \item Before starting CinelerraGG, you can set an environment variable that can be easily reversed and
45         then, to run from the Cinelerra installed directory, key in:
46 \end{enumerate}
47
48 \begin{lstlisting}[numbers=none]
49 CIN_HW_DEV=vdpau ./cin  # for computers with Nvidia and some other graphics cards
50 CIN_HW_DEV=vaapi ./cin  # mostly for computers with Intel or AMD specific graphics hardware
51 \end{lstlisting}
52
53 If you find that the environment variable setting is advantageous for your CinGG usage and you want to always use it, you can add it in your \texttt{\$HOME} directory \texttt{.profile} file which takes effect every time you log in.  The line you would add would look something like this:
54
55 \begin{lstlisting}[numbers=none]
56 export CIN_HW_DEV=vdpau
57 or
58 export CIN_HW_DEV=vaapi
59 \end{lstlisting}
60
61 It might be more difficult to analyze problems as a result of using the GPU because of the wide variation in hardware.  When you do not set the \texttt{CIN\_HW\_DEV} environment variable, the code will work exactly as before since this feature is self-contained.
62
63 There is also a \texttt{Settings $\rightarrow$ Preferences, Performance} tab, \textit{Use HW device} flag
64 with a pulldown to set up \textit{none, vdpau, vaapi,} or \textit{cuda}.  To ensure it takes effect, it is best to set it the way you want, quit out of Cinelerra and then restart.  Its current purpose is for flexibility, but there is a possibility that it might eventually take the place of \texttt{CIN\_HW\_DEV} -- both are not needed.
65
66 Precedence of the decode hardware acceleration settings are:
67
68 -- \texttt{yourfile.opts} is checked first so is of the highest priority; special .opts usage is described below
69
70 -- environment variable \texttt{CIN\_HW\_DEV} is checked next
71
72 -- preferences \textit{Use HW device} settings is of the lowest priority
73
74 \subsubsection*{Hardware decoding in Cinelerra GG}%
75 \label{ssub:hardware_decoding_cinelerra}
76
77 There are 4 phases during Cinelerra’s handling of hardware acceleration. These first 2 steps occur just \textit{before} the first read.
78
79 \begin{enumerate}
80         \item Check to see if Hardware Acceleration is enabled, usually indicated by \texttt{CIN\_HW\_ \_DEV} being set to
81         vaapi or vdpau.  If enabled, try to activate the decode device, and if that fails revert to software.
82         \item The next step is to send some data to decode to see if that works. If this does not work, you will see
83         an error message of \textit{HW device init failed, using SW decode}.
84 \end{enumerate}
85
86 \noindent These next 2 steps occur \textit{during} any read.  Now there is no turning back to software so if the hardware gets an error, that video will not be handled correctly.
87
88 \begin{enumerate} [resume]
89         \item Read the media and send the raw stream data to the device for processing.
90         \item Read the device to receive the decoded data, and convert it to the session color model.  If the GPU
91         can not convert the data, you will see the error message of \textit{Error retrieving data from GPU to CPU}.
92 \end{enumerate}
93
94 Due to variations in user’s computer hardware configuration, it is often suggested that you refer to your startup window to check for error messages.   Since your situation is unique, the error may not have been seen by anyone else and is probably unknown/undocumented.
95
96 \subsubsection*{Possible improvements or differences}%
97 \label{ssub:possible_improvements_differences}
98
99 \begin{enumerate}
100         \item The Frames Per Second (FPS) in playback might usually be at the maximum rate.  You can check
101         this in \texttt{Settings $\rightarrow$ Preferences, Playback A}, looking at \textit{Framerate achieved}; the higher, the better.
102         \item Percent of the CPU used should be less, thus saving more CPU for other operations.
103         \item Some users get the the impression that playing seems smoother.
104         \item The CPU fan noise may go down as the CPU is used less.
105         \item The GPU graphics fan noise may go up as the GPU is used more.
106 \end{enumerate}
107
108 Using the GPU is going to react differently depending on your hardware, software, and the number of files loaded. A good way to determine how well it is performing, is to watch the CPU load from another window running the command line routine \texttt{top}. Consider the following possibilities:
109
110 \begin{itemize}
111         \item If you only use smaller videos occasionally and then use other codecs than the ones mentioned
112         previously as being the optimized set, it is usually a better idea to stay with the default settings
113         without all the hardware tests.
114         \item If you have 4 cores or less, but a really good \textit{gaming card}, using vaapi/vdpau could be a big help.
115         \item If you load only a couple of files, the GPU vaapi/vdpau should be faster depending on your graphics
116         board and how capable it is.
117         \item If you load 10 camera Mixers of H.264 format, it always seems to work a lot better playing them.
118         \item If you have an epyc AMD chip with 128 CPUs and load 50 files, without vaapi/vdpau may be better.
119 \end{itemize}
120
121 \subsubsection*{Special .opts file}%
122 \label{ssub:special_opts_file}
123
124 The situation may arise where you have enabled hardware acceleration and after loading several files for a project, you find that a file had some kind of error resulting in a black video instead of an image or you see an error message pop up which states something like \textit{Error retrieving data from GPU to CPU} or \textit{err: Unknown error occurred}. Because the \texttt{CIN\_HW\_DEV} environment variable is either all or none, ordinarily in order to correct the non-working video you would have to turn off hardware acceleration for the entire project/session.  However, there is a way to continue working on your project without having to reload all of your files. You still use the environment variable and it will be effective for all of the formats it is able to handle, but you make an exception for any of the files that erred out. To do this you simply create a file in the same directory with the same name as the erring file with the different extension of .opts. The contents of this .opts file would just be the one line of:
125
126 \begin{lstlisting}[numbers=none]
127 cin_hw_dev=none
128 \end{lstlisting}
129 Conversely, if you have a bunch of files in your project, like dnxhd format, that are not hardware accelerated, but you have an accompanying large file of type .mp4 for which you would like the hardware acceleration, you can leave the \texttt{CIN\_HW\_DEV} variable unset (that is, do not use it) and just create an .opts file containing the line:
130
131
132 \begin{lstlisting}[numbers=none]
133 cin_hw_dev=vdpau
134 \end{lstlisting}
135
136 For example your file, \texttt{test.mp4}, would have a side-kick called \texttt{test.opts} that will use the GPU for decoding/playing and the other files will just use the software. This is of some advantage because the ones that can not use the GPU if the environment variable is enabled, will not have to even check which saves a minuscule bit of time.
137
138 It is important to note that if using the .opts file to override the default \texttt{ffmpeg / decode.opts} file, you will most likely see more warnings (not really errors) in the Cinelerra startup window because the standard \texttt{decode.opts} file has \textit{loglevel = fatal} whereas the default is \textit{loglevel = error}.  To avoid seeing all of the extra warnings, you can simply add the line   \textit{loglevel=fatal}   to your .opts file.
139
140 \subsubsection*{To verify hardware acceleration}%
141 \label{ssub:verify_hardware_acceleration}
142
143 Probably the easiest way to tell if hardware acceleration is working, is just to look at the messages in the window from where you started Cin (not available if start using the application icon).  For example load a png, dnxhd, or some other non-supported format file and you will see messages similar to those below.  The line \textit{HW device init failed, using SW decode} indicates that the vdpau/vaapi HW (hardware) decode is not available so will use SW (software) decode instead.
144
145 \begin{lstlisting}[numbers=none]
146 Failed to get HW surface format.
147 HW device init failed, using SW decode.
148 file:/tmp/media/aer_zypr.mp4
149 err: Success
150
151 or
152
153 Decoder dnxhd does not support device type vdpau.
154 HW device init failed, using SW decode.
155 File:/tmp/media/test.gxf
156 err: Success
157
158 or
159
160 HEVC with NVIDIA, VDPAU driver is buggy, skipping
161 \end{lstlisting}
162
163 If you would like to see more information on what is occurring, you can modify in the Cinelerra ffmpeg subdirectory, the file:  \texttt{decode.opts}   by temporarily changing the line from \textit{loglevel =fatal} to \textit{loglevel =verbose} and restarting Cinelerra.  Then you will see messages in the startup window like:
164
165 \begin{lstlisting}[numbers=none]
166 [AVHWDeviceContext @ 0x7fc9540be940] Successfully created a VDPAU device 
167 (NVIDIA VDPAU Driver Shared Library 390.116 Sun Jan 27 06:28:58 PST 2019) on X11 display :0
168 [h264 @ 0x7fc950159380] Reinit context to 1920x1088, pix_fmt: vdpau
169 [h264 @ 0x7fc92c3dd4c0] Reinit context to 1920x1088, pix_fmt: yuv420p
170 \end{lstlisting}
171
172 Again, to measure the performance run \texttt{top} from another window to check the CPU usage which will go lower as more work is offloaded to the GPU graphics card instead (it may go down by 2 to 10 times) or check the \textit{Framerate achieved} while playing.
173
174 Some mixed preliminary results that have been reported are provided below.
175
176 \subsubsection*{Case 1:}%
177 \label{ssub:case_1}
178
179 \noindent X11 Video Driver set in \texttt{Settings $\rightarrow$ Preferences, Playback A} tab:
180
181 \begin{center}
182         \begin{tabular}{lcr}
183                 CIN\_HW\_DEV=off ./cin & &CPU $58\%$ \\
184                 CIN\_HW\_DEV=vdpau ./cin & &CPU $32\%$ \\
185                 CIN\_HW\_DEV=vaapi ./cin & &CPU $82\%$ \\
186         \end{tabular}
187 \end{center}
188
189 \noindent X11-OpenGL Video Driver set in \texttt{Settings $\rightarrow$ Preferences, Playback A} tab:
190
191 \begin{center}
192         \begin{tabular}{lcr}
193                 CIN\_HW\_DEV=off ./cin & &CPU $48\%$ \\
194                 CIN\_HW\_DEV=vdpau ./cin & &CPU $12\%$ \\
195                 CIN\_HW\_DEV=vaapi ./cin & &CPU $80\%$ \\
196         \end{tabular}
197 \end{center}
198
199 \noindent Best is the least amount of CPU usage. Note that in this Case 1, using the X11-OpenGL video driver is  
200 better than using the X11 video driver.
201
202 \subsubsection*{Case 2:}%
203 \label{ssub:case_2}
204
205 \noindent X11 Video Driver set in \texttt{Settings $\rightarrow$ Preferences, Playback A} tab:
206
207 \begin{center}
208         \begin{tabular}{lcr}
209                 CIN\_HW\_DEV=off ./cin & &CPU $60\%$ \\
210                 CIN\_HW\_DEV=vdpau ./cin & &CPU $11\%$ \\
211                 CIN\_HW\_DEV=vaapi ./cin & &CPU $60\%$ \\
212         \end{tabular}
213 \end{center}
214
215 \noindent X11-OpenGL Video Driver set in \texttt{Settings $\rightarrow$ Preferences, Playback A} tab:
216
217 \begin{center}
218         \begin{tabular}{lcr}
219                 CIN\_HW\_DEV=off ./cin & &CPU $67\%$ \\
220                 CIN\_HW\_DEV=vdpau ./cin & &CPU $60\%$ \\
221                 CIN\_HW\_DEV=vaapi ./cin & &CPU $67\%$ \\
222         \end{tabular}
223 \end{center}
224
225 \noindent Best is the least amount of CPU usage. Note that in this Case 2, using the X11 video driver is better
226 than using the X11-OpenGL video driver.
227
228 Older graphics cards or non-performing graphics cards will probably bring only a small amount of improvement or no speed advantage at all.  You can check to see if vdpau is implemented for your specific Nvidia board at:
229
230 {\small \url{https://download.nvidia.com/XFree86/Linux-x86_64/304.137/README/supportedchips.html}}
231
232 And, you can see what your specific hardware and software might support by running either \texttt{vainfo} or \texttt{vdpauinfo} from the command line.  Partial examples of each are shown below.
233
234 \begin{lstlisting}[numbers=none]
235 # vainfo
236 vainfo: VA-API version: 1.4 (libva 2.4.0)
237 vainfo: Driver version: Intel i965 driver for Intel(R) Broadwell - 2.4.0.pre1 (2.3.0-11-g881e67a)
238 vainfo: Supported profile and entrypoints
239 VAProfileMPEG2Simple                            
240 ...
241 VAProfileH264Main              
242 VAProfileH264High  
243 ...
244 VAProfileH264MultiviewHigh 
245 VAProfileH264StereoHigh 
246 ...
247 VAProfileVC1Simple 
248 ...
249 VAProfileVP8Version0_3 
250 \end{lstlisting}
251
252 \begin{lstlisting}[numbers=none]
253 # vdpauinfo
254 display: :0   screen: 0
255 API version: 1
256 Information string: G3DVL VDPAU Driver Shared Library version 1.0
257 ...
258 Decoder capabilities:
259
260 name                        level macbs width height
261 ----------------------------------------------------
262 MPEG1                          --- not supported ---                                                                      
263 MPEG2_SIMPLE           3 65536  4096  4096                                                                       
264 MPEG2_MAIN               3 65536  4096  4096                                                                       
265 H264_BASELINE         52 65536  4096  4096                                                                       
266 H264_MAIN                  52 65536  4096  4096                                                                       
267 H264_HIGH                  52 65536  4096  4096                                                                       
268 VC1_SIMPLE                 1 65536  4096  4096                                                                       
269 VC1_MAIN                     2 65536  4096  4096                                                                       
270 VC1_ADVANCED         4   65536  4096  4096 
271 \end{lstlisting}
272
273 One last item of note, \textit{nvdec} is also enabled in the ffmpeg build, but at this time it is not known how this decode option on Nvidia graphics boards works or does not work in conjunction with vdpau.
274
275 \subsection{GPU hardware encoding}%
276 \label{sub:gpu_hardware_encoding}
277
278 Encoding using hardware acceleration of your graphics board GPU is included in CinelerraGG but it is of limited availability and works only with a specific set of hardware graphics boards, a certain level of graphics driver versions and only with certain ffmpeg formats.  The encoding is done via vaapi (libva installed), which is known to work with Intel HD graphics boards and some others or via nvenc as developed by Nvidia for Nvidia graphics boards.
279
280 \subsubsection*{Broadcom, Intel HD, AMD}%
281 \label{ssub:broadcom_intel_amd}
282
283 To use hardware acceleration for rendering (that is, encoding) you do not have to set a preference or an environment variable, as was required for decoding.  To use this feature you use an ffmpeg render options file which specifies a vaapi codec, such as h264\_vaapi.  You must include this line in that options file to trigger the hardware probe: \qquad      \texttt{CIN\_HW\_DEV=vaapi}
284
285 There are currently 4 options files available in the Render menu already set up for you that you see when you select the Video wrench and use the down arrow on the first line in the menu.  These are:
286
287 \begin{description}
288         \item[h264\_vaapi.mp4] known to work on Intel computer with Intel Broadwell graphics driver
289         \item[mpeg2\_vaapi.mp4] known to work on Intel computer with Intel Broadwell graphics driver
290         \item[mjpeg\_vaapi.mp4] error message of \textit{open failed with mjpeg\_vaapi$\dots$} on above computer
291         \item[hevc\_vaapi.mp4] error message of \textit{open failed with hevc\_vaapi$\dots$} on above computer
292 \end{description}
293 Other option files can be added as needed for your specific hardware if it is known to work for you, such as VP8 and VP9.  An example of the included Cinelerra’s \texttt{ffmpeg/video/h264\_vaapi.mp4} file (figure~\ref{fig:render-vaapi}):
294
295
296 \begin{lstlisting}[numbers=none]
297 mp4 h264_vaapi
298 cin_hw_dev=vaapi
299 profile=high
300 \end{lstlisting}
301
302 \begin{figure}[htpb]
303         \centering
304         \includegraphics[width=0.7\linewidth]{images/render-vaapi.png}
305         \caption{Render menu setup to encode using GPU with vaapi}
306         \label{fig:render-vaapi}
307 \end{figure}
308
309 According to an online wiki, hardware encoders usually create output of lower quality than some software encoders like x264, but are much faster and use less CPU. Keep this in mind as you might want to set a higher bitrate to get output of similar visual quality.
310
311 Results of a particular test case performed on a Intel, 4-core computer, with Broadwell Graphics using an mp4 input video/audio file with dimensions of
312 $1440x1080 / 29.97fps$ is shown next (note, filename is \texttt{tutorial.mp4}).  This may very well be a \textit{best case} scenario!  But clearly, at least on this computer with only 4 cores, the hardware acceleration seems to be quite advantageous.  A comparison of the 2 output files 
313 using \texttt{ydiff} as described in the Appendix (\ref{sec:ydiff_check_results}) shows no obvious defects.
314
315 \begin{center}
316         \begin{tabular}{l|cccc}
317                 &CPU usage & Render Time & File Size & File \\
318                 \hline
319                 none & 388\% &100 secs &36,862,542 & h264.mp4 \\
320                 vaapi & 150\% & 19 secs & 74,522,736 & h264\_vaapi.mp4 \\
321         \end{tabular}
322 \end{center}
323
324 \subsubsection*{Nvidia graphics boards}%
325 \label{ssub:nvidia_graphics_card}
326
327 To use hardware acceleration for rendering (that is, encoding) you do not have to set a preference or an environment variable, as was required for decoding.  To use this feature you use an ffmpeg render options file which specifies the nvenc codec, either \texttt{h264\_nvenc.mp4} or \texttt{nvenc.mp4}.  There are several requirements in order for this to work on your computer as listed here:
328
329 \begin{enumerate}
330         \item Nvidia graphics board at or above a certain hardware level.  For h265, newer boards are required.
331         \item Software drivers for your graphics board must be installed on your computer.
332         \item The driver must support at least API version 9.0 -- minimum required Nvidia driver for nvenc is
333         390.25 or newer.  You will see error messages on the startup window if you are on lower versions.
334 \end{enumerate}
335
336 If you try to render using\texttt{ h264/h265\_nvenc.mp4} formats and do not have an Nvidia graphics card or this feature was not built in, you will see in the window from where you started Cinelerra, the error message: \qquad \textit{Cannot load libcuda.so.1}
337
338 A small test using 2 minutes from the 4k version of Big Buck Bunny shows using nvenc can be about 4 times faster.  The test was done on a 4 core Intel laptop with an Nvidia 950M graphics board.
339
340 \begin{center}
341         \begin{tabular}{l|cccl}
342                 &CPU usage & Render Time & File Size & File \\
343                 \hline
344                 none & 388\% &20 mins 18 secs & 156,517,069 & h264.mp4 \\
345                 nvenc & 252\% & 5 mins 44 secs & 42,052,920 & h264\_nvenc.mp4 \\
346         \end{tabular}
347 \end{center}
348
349 Of note in this test, 388\% CPU usage with only 4 cores shows that there is probably slow down because there is no more CPU power available. Therefore, using the GPU hardware acceleration with nvenc provides a significant speed-up.  Also, note the larger file size without making use of the GPU – this probably indicates that there is a big difference in bitrate or quality parameter settings used in the options file and this should be taken into consideration.
350
351 \subsubsection*{Important Tip}%
352 \label{ssub:important_tip}
353
354 There is one last potentially significant graphics speedup when using the X11-OpenGL driver for users with Nvidia graphics boards who are seeing frames/sec achieved lower than what the video format is set to.  You may want to disable \textit{sync to vblank} (an option for OpenGL) in NVIDIA X Server Settings for the proprietary drivers.  This could increase your frames per second on playback.
355
356 \subsection{Effects (OpenCL, Cuda)}%
357 \label{sub:effects_opencl_cuda}
358
359 CUDA® is a parallel computing platform / programming model developed by Nvidia that provides big increases in computing performance through use of the GPU. It was first introduced in about 2006 for applications in computationally intense fields such as astronomy, biology, chemistry, and physics.
360
361 At the time this was written, the use of Cuda is not going to improve the playing and rendering of video in Cinelerra except in the case where you use a specific Cuda-enabled plugin that is computationally intense -- sadly, most of what Cin does, Cuda will not help.  Cuda is mostly a \textit{block oriented algorithm} which works well for such things as \textit{a flock of birds all flying next to each other}.
362
363 The same as for vaapi and vdpau, you can enable Cuda in the:\\
364 \texttt{ Settings $\rightarrow$ Preferences, Performance} tab, \textit{Use HW Device}\\
365 but it will not affect anything unless you have Cuda installed on your system and have built Cinelerra yourself with Cuda build enabled.  To install it on your computer, you will need to do the following:
366
367 \begin{enumerate}
368         \item Make sure you have the Nvidia proprietary library drivers for your graphics board already installed.
369         \item Go to the Nvidia Cuda development website and choose one of the available operating system’s
370         such as Fedora, OpenSuse, CentOS, Ubuntu, $\dots$ at   {\small \url{https://developer.nvidia.com/}}
371         \item You will be installing repositories by package -- this will be around 3 GB.
372         \item Also, install the Fusion repo, although it is unknown if necessary or not.
373 \end{enumerate}
374
375 There is a very good set of directions on the website to just follow.  Once you have installed the Cuda software on your computer, you must build Cinelerra yourself -- 
376 the default flag for a build in the configure script for cuda is \textit{auto}.  For Arch, and possibly
377 other distros, you may have to supply the CUDA\_PATH if it is not in the standard place.  This would be
378 something like:
379
380
381 \begin{lstlisting}[numbers=none]
382         env CUDA_PATH=/opt/cuda
383 OR if using the bash shell: 
384         export CUDA_PATH=/opt/cuda
385 \end{lstlisting}
386 For all distros you will need to add to the ./configure line in your build script, the following:
387
388
389 \begin{lstlisting}[numbers=none]
390         --with-cuda
391 so your configure line will look something like this:
392         ./configure --with-single-user --with-booby --with-cuda
393 \end{lstlisting}
394
395 There are currently 4 available plugins for \textit{show and tell} that take advantage of the hardware acceleration of Cuda -- \textit{N\_Body} and \textit{Mandelbrot} as shown next (figure~\ref{fig:cuda-effects}), \textit{F\_scale\_cuda} and \textit{F\_yadif\_cuda}.
396
397 \begin{figure}[htpb]
398         \centering
399         \begin{minipage}[h]{0.99\linewidth}
400                 \center{\includegraphics[width=0.99\linewidth]{images/n_body.png}} \\
401         \end{minipage}
402         \vfill
403         \begin{minipage}[h]{0.7\linewidth}
404                 \center{\includegraphics[width=0.99\linewidth]{images/mandelbrot.png}} \\
405         \end{minipage}
406         \caption{N\_Body and Mandelbrot effects}
407         \label{fig:cuda-effects}
408 \end{figure}
409
410 An error you may see on your Cinelerra startup window when you have Cuda installed and try to run one of the 2 plugins is \textit{cudaErrorInsufficientDriver}.  This indicates CUDA 10 (the current version at the time of this writing) is not compatible with the driver version on your computer.  You can either:
411
412 \begin{enumerate}
413         \item Upgrade the driver if your board supports newer nvidia builds.
414         \item downgrade the cuda development package to a version that works for your board.
415 \end{enumerate}
416
417 \subsection{Final Note}%
418 \label{sub:final_note_on_acceleration}
419
420 In wrapping up this Hardware Acceleration section, you may want to refer to the following to determine the current supported formats:
421
422 {\small \url{https://wiki.archlinux.org/index.php/Hardware_video_acceleration}}
423
424 \section{Optimized Playback -- X11 Direct}%
425 \label{sec:optimized_playback}
426
427 Normally, when Cinelerra reads a video frame, it is copied into a \textit{Vframe}.  This frame may also need other actions performed on it, such as a color model change.  In addition, ffmpeg and libzmpeg \textit{can\_scale\_input}.  So the read can be color transformed and scaled just by asking the library to do that.  This means that if the compositor is in a \textit{good} state with no zoom, the VFrame read can be done in the fastest render color model, and already scaled to the correct size for the compositor.  In reality, this is not what you need for editing, but quite often the \textit{virtualconsole} is not used because the render is media only -- that is \textit{just data}.  If no data transforms are needed and the input scaling can be done, the vrender program detects this, and tells the codec to transmit the data in a compatible way to the compositor canvas. This is the \textit{X11 direct} data path.
428
429 With the X11 video driver choice, large format files such as 4K, will playback faster than either X11-XV or X11-OpenGL.  However, you still have the option to turn off the X11 direct data path if you use
430 \texttt{Settings $\rightarrow$ Preferences, Playback A} tab set video driver to X11 and uncheck \textit{use direct X11 render if possible}.
431
432
433 \section{Proxy Settings and Transcode}%
434 \label{sec:proxy_settings}
435
436 Working with videos that have large image geometry can greatly impede editing.  Instead you can substitute \textit{proxies} which will create smaller video image files from the original file that can then be edited more quickly.   When you are done working on this smaller scale, you will need to bring up the Proxy settings menu again, and change the Scale factor back to the Original size so that all of your edits/work take affect on that original higher quality video on the timeline.  
437
438 To use this feature, select \texttt{Settings $\rightarrow$ Proxy settings} and change the Scale factor from Original size to your downsized choice.  You can choose ffmpeg as the File Format and a choice of various codecs associated with that.  A good choice is the default of mpeg which can usually be quite fast.  In addition, to modify values for that codec, click on the wrench icon.  When you have completed your choices, just click OK, and then the video tracks will be rendered. This may take some time, but previous proxy renders will be reused.  
439 The proxy videos will be added to your assets in a separate Proxy folder, and the video track edits will use the proxies.
440 The assets in both the Media folder and Proxy folder will look proxied when dragged to the Viewer although the scale may be different.
441 Proxy downsizing renders all loaded tracks, but only work on the $1^{st}$ video layer of any multi-layer media.  Rendered proxy media is saved in the same directory as the original media.
442 However, if you proxy your session, the clips do not get proxied to the Proxy folder, but if you Drag and Drop the clip from the Clip folder to the Viewer or the Timeline, you will see that it too is proxied.  
443 As usual, you can delete proxy files from the project or disk in the Resources window if you no longer want to retain them.
444 And you can save your project either as proxied or not.
445
446 You can also nest clips while in a proxied state, but you can not drag the proxied nested clips
447 to the viewer or the timeline.
448 If you create proxies for Nested clips they will be saved in \texttt{\$HOME/Videos} unless you modify that in
449 \texttt{Settings $\rightarrow$ Preferences, Interface} tab, \textit{Nested Proxy Path}. 
450
451 There are two ways that the proxy files can be used, with or without input scaling. When the proxy is done without rescaling, the Mask, Camera and Projector automations are re-scaled accordingly. In this situation, the entire project will be re-sized so that the session is in the resized geometry.  Not all plugins are useful when the project is rescaled, because the keyframe data must be in the original geometry.  In this case, you can use the rescaler, by enabling \textit{Use scaler (FFMPEG only)}. This has the added advantage that the project size does not change and the proxy media is down-scaled as usual and up-scaled on read-in, which means the project editing is done in full scale.   Since decoding is done on smaller video, there is a time savings, but all rendering is done full scale.  The main reason for using \textit{scaler} is that it does not change the image coordinate data, so that automation and plugin parameters will be in the original project geometry.   This is not as fast as the first option, but is a performance gain, and may be needed if you are using plugins that need coordinate data such as the Title plugin.  As noted, the scaler only works on ffmpeg video formats.
452
453 In the upper right hand corner of the main window, there is a toggle button to easily switch back and forth when you have a proxied file on the timeline.  The icon is to the left of the FF icon.  It will have the letter “P” as the icon for Proxy or if \textit{Using Scaler}, the letter “S”. \quad \includegraphics[height=\baselineskip]{images/proxy-01.png} \quad This quick switch is especially useful when editing and you need to see a better image temporarily.
454
455 Screencast in figure~\ref{fig:proxy-02} shows the Use scaler checked so you can still use plugins and the original project size is kept.  The Scale factor pull-down gives you available size options.  Note the new media dimensions shown (partially covered).  If the size is an odd number, 1 is added to make the dimensions both even numbers.
456
457 In the case of the scaler checkbox, it will retain that setting for ease of use.
458
459 \begin{figure}[htpb]
460         \centering
461         \includegraphics[width=0.6\linewidth]{images/proxy-02.png}
462         \caption{Proxy settings dialog}
463         \label{fig:proxy-02}
464 \end{figure}
465
466 There is also a convenient \textit{Beep on done volume} dial included so that you can work on other tasks until there is an audible notify of completion.  The default volume is set to 0 for no audible notify.
467
468 A good choice for proxy settings with 1080p source video is:
469
470 \begin{lstlisting}[numbers=none]
471 Scale Factor:   1/4
472 Use Scaler:     unchecked
473 File Format:    FFMPEG - mpeg
474 Video Preset:
475 Compression:    mpeg.mpeg
476 Bitrate:        1800000
477 Quality:        -1
478 Pixels:         yuv420p
479 \end{lstlisting}
480
481 If you get errors for some videos, such as those with strange variable bit rate or some types of files made on a smartphone, a usually reliable alternative is to change the following parameters:
482
483 \begin{lstlisting}[numbers=none]
484 File Format:    FFMPEG - mov
485 Video Preset:
486 Compression:    mov.mov
487 \end{lstlisting}
488
489 Or if you want small files with high image quality, a File Format of m2ts is optimal.  For example a 1 GB file can be reduced to 50 MB with scale $\frac{1}{2}$. 
490
491 Checking the \textit{Auto proxy/scale media loads} results in any additional media loads to be automatically proxy scaled.  However, single frame media such as PNG or JPEG \textit{stills}, can not be scaled to \textit{stream} media.  If this type of media exists, you should \textit{use scaler}.
492
493 If you get error messages when creating proxies, check the Video wrench settings.  These usually default to values that are expected to work correctly for the \textit{File Format} and codec you selected but they can be changed and may result in errors.  If you get an error message of \textit{check\_frame\_rate failed} followed by \textit{Error making proxy} in the popup Errors window, do just that and check the Frame rate value by going to the Resources window, Media folder, and use the right mouse button for the Info option for that specific media in question.  You can change the frame rate in this window to a more codec acceptable value.  Different codecs may have different legal values.
494
495 More specific information on which plugins need to use scaler is provided here next.  If the keyframe data uses coordinate data that is absolute, then the scaler should be used.  If the data is normalized (like always $0-100\%$) then the proxy can be done without the scaler.  The session geometry format, shown in \texttt{Settings $\rightarrow$ Format} as $width \times height$, is changed if the scaler is not used to cause all of the data to be in the reduced format.  If this affects the plugin operation, then scaler should be used.  Examples of plugins that need the scaler are: Title, AutoScale, Scale, ScaleRatio, and Translate.  Most others are safe to use without scaling.
496
497  This makes its so that you can save your project
498 either as proxied or not.
499
500 \textbf{Transcode}, an option under the Settings pulldown right next to the Proxy settings option, is a type of full resolution \textbf{1:1 Proxy}.
501 The process of transcoding works directly from the resource; it is independent of the timeline. 
502 All of the loaded asset media will be converted, that is, rendered in the selected format and loaded onto the timeline. 
503 Menu choices besides the usual File Format and File Type include: \textit{Tag suffix} (to add to media filename), \textit{Remove originals from project}, \textit{Into Nested Proxy directory} (an option to have the file saved here instead of the location of the original media), and \textit{Beep on done} volume.
504
505 The settings of the project have an effect, for example the dimensions are taken into account. The resulting files are also larger than if they were created directly with ffmpeg.
506 Transcode works for videos with or without audio and even single frame files, like png's.
507 If you have a video file that also contains audio, and you convert only the video, the original audio will stay on the timeline if do not check \textit{Remove originals from project}. Or vice versa if audio converted and not video.
508 Multiple stream media will only transcode the first stream (this would be like the TV channel recordings in the United States).
509 You will get an error message if you already have a transcoded file in the selected format with the same suffix name and try to transcode it again with a different selection made -- you will have to delete that file first. An example would be
510 an already converted file that has both video and audio and now you request video only. 
511
512 The BIGGEST gain from using this is if you have media that is not \textit{seekable}, that is, you can play it from the beginning but can not move to another spot and have the audio or video play correctly. A video file with no keyframes makes seeking next to impossible, but then a Transcode generally adds these keyframes. 
513
514 \section{Some Settings Parameter Values}%
515 \label{sec:settings_parameter_values}
516
517 \texttt{Cache} in \texttt{Settings $\rightarrow$ Preferences, Performance} tab is used to store images on the timeline.  One 1080p frame uses about 10 MB.  The default setting is 256 and this is enough for testing and running.  However, why not use more memory if it is available.   To experiment for testing a good number tuned to the way you use your computer, set the cache to 0, start up Cinelerra, load a typical media file, play it and run \texttt{top} on the command line in another window to see how much memory is being used.  In the \textit{top} display, look at \textit{free} memory.  Whatever your computer is not using, is a good number to use for cache.  If you start other programs, or change the design of the session so that it uses a lot of frame storage, you may need to experiment again later and resize accordingly.
518
519 For system \textit{swap}, 1 GB seems to be more than sufficient.  If the amount of memory being used by the program is \textit{close}, then swap might save you but often if swapping becomes necessary, it presents more problems and you end up killing the Cinelerra process anyway.
520
521 \section{Tips for Improving Smaller Computers Use}%
522 \label{sec:tips_improving_smaller_computers}
523
524 A list of items to check for smaller computers that will help to use less cpu/memory/resources follows:
525
526 \begin{itemize}
527         \item For large media files, use proxy to do your main editing.
528         \item In \texttt{Settings $\rightarrow$ Preferences, Appearance} tab, uncheck \textit{Use thumbnails in resource window}.
529         \item In \texttt{Settings $\rightarrow$ Preferences, Appearance} tab, uncheck \textit{Autocolor assets}.
530         \item  Speed-up certain time-consuming FFmpeg plugins through use of a carefully selected \texttt{.opts} file.
531         \item For large media files, in \texttt{Settings $\rightarrow$ Preferences, Playback A}, Video Driver set \textit{use direct X11 render if possible}.
532         \item For the Video Driver in \texttt{Settings $\rightarrow$ Preferences, Playback A}, if using a good graphics card, choose \textit{X11-OpenGL}.
533         \item Set \textit{CIN\_HW\_DEV=vdpau} or \textit{vaapi} to use the graphics GPU for certain ffmpeg media decoding.
534         \item If you have multiple cpus or multiple computers, even if slow, take advantage of using \textit{Render Farm}.
535         \item When editing, \textit{background rendering} causes temporary output to be rendered constantly while the
536         timeline is being modified. The temporary output is displayed during playback whenever possible so 
537         it does not have to be recalculated -- very useful for transitions and previewing effects that are slow.
538         \item In  \texttt{Settings $\rightarrow$ Preferences, Playback A}, uncheck \textit{Play every frame} which means frames will be skipped as playback of the video falls behind.
539         \item Adjust \textit{Cache size} in \texttt{Settings $\rightarrow$ Preferences, Performance} tab, to not exhaust the memory and yet still provide decent playback.
540 \end{itemize}
541
542 \section{General Crash Handling Tips}%
543 \label{sec:general_crash_tips}
544
545 This section is a handy guide for describing various kinds of software computer system failures.  Only some of these various lockups or crashes can be dealt with.  Hopefully, it will help to have some hints to know what kind of failure it is, or to save your work or to avoid future problems.  For most of this, your user name must be root, although you can certainly try to see if it works for you when not root.
546
547 \begin{description}
548         \item[System lockups:] When the system locks up, it is usually a system problem.  Normally an application program cannot lock up the system.  It is a major goal of system design to prevent an application (app) from failing a system interface.  This does not mean an app can not cause a system lockup, but it is unusual.
549         \item[Cinelerra crash:] This is covered in  \hyperref[cha:crash_dumps_analysis]{Crash Dumps for Analysis}.  Just a reminder that for best results you should be root and by providing a crash dump and as much other information as possible, you will be helping the developer to analyze the problem and fix it so that it can be avoided in the future.
550         \item[X Server crash:] Keyboard does not respond, screen is frozen, caps lock may operate LED light.  Sometimes using Ctrl-Alt-F1 $\dots$ Ctrl-Alt-F7 (etc.) will allow you to regain control of a VT console.  You can use this to login and check logs: eg. \texttt{/var/log/Xorg.0.log}, \textit{dmesg}, \textit{journalctl} $\dots$ etc.  If you have another computer, make sure a terminal server is configured (for example: rsh, ssh, or telnet), then remote login via this other computer and check the logs.  Most important is to immediately note the current software state, and the very last thing that preceded the crash, i.e. last button click, last keystroke, $\dots$ or whatever.
551         \item[Kernel crash:] The machine goes completely dead.  The keyboard caps lock LED will probably be flashing.  Most likely the only way to see anything after the kernel crashes is to use a serial port console log and usually kdb, the kernel debugger, and special cabling.  This requires a lot of setup, and is normally reserved for experts.  Login from another computer will not work.  Pinging the ip address will not respond since the network stack is part of the kernel.  There are some virtual machine setups that will let you debug a \textit{guest} kernel, but this also requires a lot of setup, and affects which kernel is currently under test.  The kdb route is preferable.
552         \item[Keyboard grabs, Server grabs, and Deadlocks:] A grab is an X-server state where all events are forced to just one window event stream.  This forces the user to respond to the dialog.  Things seems to be working, but no keypresses do anything useful. The system clock and other programs will still be working.  The network will work for remote logins. Grabs can be canceled if the \texttt{/etc/X11/xorg.conf} X config contains special setup as shown below:
553 \end{description}
554
555 \begin{lstlisting}[numbers=none]
556 Section "ServerFlags"
557         Option      "HandleSpecialKeys" "Always"
558         Option      "AllowDeactivateGrabs" "True"
559         Option      "AllowClosedownGrabs" "True"
560 EndSection
561
562 Section "InputDevice"
563         Identifier  "Keyboard"
564         Driver      "evdev"
565         ...
566         Option "XkbOptions" "terminate:ctrl_alt_bksp"
567         Option "XkbOptions" "grab:break_actions"
568 EndSection
569 \end{lstlisting}
570
571 or to \texttt{\$HOME/.xinitrc}, add:
572
573 \begin{lstlisting}[numbers=none]
574 #  xkb terminate/grab actions disabled in xorg.conf, use:       
575 setxkbmap -option "grab:break_actions"
576 setxkbmap -option "terminate:ctrl_alt_bksp"
577 ctrl-alt-bksp = terminate the X-server, may restart automatically
578 \end{lstlisting}
579
580
581 Modal forms (always on top, and usually ptr/kbd grab) dialog boxes can lock a system by putting a form over another form holding a grab.  This means the form that needs input may never get any because you can not get to it, and the result is a deadlock.  Usually you will have to restart X (Ctrl-Alt-Bksp).
582
583 \begin{description}
584         \item[Window Manager issues:] The \textit{desktop} window manager can intercept and modify all kinds of user input.  Mostly, this is a good thing, but can be a nuisance.  If user keypresses can be programmed to trigger actions, then they may be useful to send \texttt{KILL} or \texttt{INTR} to an app that seems to be holding X's attention.  For example:
585         \begin{lstlisting}[numbers=none]
586         killall -INTR cinelerra,
587         killall -9 cinelerra,   
588         killall X,
589         # but you must run as root to be able do this
590         \end{lstlisting}
591         The ALT and META keys may be intercepted by the window manager, and this can cause unexpected interface operations.
592 \end{description}
593
594 \section{Tips for Specific Operations}%
595 \label{sec:tips_specific_operations}
596
597 \subsection{Generating a 440 Hz tone}%
598 \label{sub:generating_440_tone}
599
600 To create a specific 440 Hz tone, follow these steps.  You can vary the length, use more channels, or change the frequency to a different desired value (figure~\ref{fig:aeval}).
601
602 \begin{enumerate}
603         \item Make sure there is an armed audio track on the timeline, get into Cut and Paste mode, and highlight
604         a selection or define In/Out points where you want to insert the audio tone.
605         \item Go to \texttt{Audio $\rightarrow$ Render effect}.  Rendered effect usage is described in \hyperref[sec:rendered_effects]{Effect Plugins}. This brings up a menu where you will select the desired effect which in this case is \textit{F\_aeval}.  Also Select a file to render to, a File Format, and Insertion strategy of Paste at insertion point.
606         \item Click on the green OK checkmark which will popup the F\_aeval effect so that you can set the
607         parameters.
608         \item Highlight the \textit{exprs} option and key in a specific audio filter expression which for 440 Hz would be:
609         $\sin(2\pi t\times440)$.  Then hit the Apply button.
610         \item Next when you hit the green OK checkmark on the Cinelerra: Effect Prompt popup, you will have
611         your 440 Hz tone on the timeline plus in the select file that you chose to render it to.
612         \item To use 2 channels instead of 1, in the F\_aeval menu highlight the \textit{channel\_layout} option and change
613         that to 1C|2C instead of the usual default of 1C.
614 \end{enumerate}
615
616 \begin{figure}[htpb]
617         \centering
618         \includegraphics[width=1.0\linewidth]{images/aeval.png}
619         \caption{Use Audio$\rightarrow$Render effect to set render parameter values and then that effect can be varied.}
620         \label{fig:aeval}
621 \end{figure}
622
623 \subsection{Camera supplied LUTs}%
624 \label{sub:camera_supplied_luts}
625
626 A LUT, acronym for Look-Up Table, is a mathematically precise way of taking specific RGB image values from a source image and modifying them to new RGB values by changing the hue, saturation and brightness values of that source image. In other words, LUTs are used to map one color space to another.  Some high-end cameras supply a .cube file to use as input. There are several different ffmpeg plugins included with CinGG for using Lut's.  These are:
627
628 \begin{description}
629         \item[F\_lut:] Compute and apply a lookup table to the RGB/YUV input video.
630         \item[F\_lut1d:] Adjust colors using a 1D LUT.
631         \item[F\_lut3d:] Apply a 3D LUT to an input video.
632         \item[F\_lutrgb:] Compute and apply a lookup table to the RGB input video.
633         \item[F\_lutyuv:] Compute and apply a lookup table to the YUV input video.
634 \end{description}
635
636 For example, to use a 3dlut simply load your video, drop the F\_lut3d plugin on that track, and bring up the lut3d controls window, highlight the \textit{file} option, key in your file name (whit path), and hit apply to have the lut take effect.  To easily adjust, move the \textit{fader} slider in the patchbay for that video track.
637
638 \subsection{Encoding into Dolby Pro Logic}%
639 \label{sub:encoding_dolby_pro_logic}
640
641 Dolby pro logic is an easy way to output 6 channel audio from a 2-channel soundcard with degraded but useful results. Rudimentary Dolby pro logic encoding can be achieved with usage of some effects.
642
643 \begin{enumerate}
644         \item First, create the front left and right channels. Create 2 audio tracks, each carrying either the left or
645         right channel. Pan the left channel to the left and the right channel to the right with the pan control.
646         \item Now create the rear left and right channels. Create another 2 audio tracks as above -- the left channel
647         panned left and the right channel panned right. Then apply invert audio to both new channels and
648         the signals will come out of the rear speakers.
649         \item Next, create the center channel by creating a single audio track with monaural audio from a
650         different source. Center it with the pan control and the signal will come out of the center speaker.
651 \end{enumerate}
652
653 \begin{itemize}
654         \item If a copy of the signal in the back speakers is desired in any single front speaker, the signal in the back
655         speakers must be delayed by at least $0.05$ seconds and a single new track should be created. Pan the
656         new track to orient the signal in the front speakers.
657         \item If the same signal is desired in all the speakers except the center speaker, delay the back speakers by
658         $0.5$ seconds and delay either the front left or front right by $0.2$ seconds.
659         \item If you want to hear something from the subwoofer, create a new track, select a range, drop a
660         synthesizer effect, and set the frequency below $60 Hz$. The subwoofer merely plays anything below
661         $60Hz$ or so.
662 \end{itemize}
663
664 Other tricks you can perform to separate the speakers are parametric equalization to play only selected ranges of frequencies through different speakers and lowpass filtering to play signals through the subwoofer.
665
666 \subsection{Improving Analog TV Quality}%
667 \label{sub:improving_tv_quality}
668
669 The picture quality on analog TV is not always good but you can modify parameters in Cinelerra to make it look more like it did in the studio.
670
671 First, when capturing the video, capture it in the highest resolution possible. For Europeans this would be $720\times576$ and for North Americans, $720\times480$. Do not adjust the brightness or contrast in the recording monitor, but you might want to max out the color. Capture the video using MJPEG or uncompressed Component Video if possible; if not possible, then capture it using JPEG preferably or RGB if that is all that will work.  Now on the timeline use \texttt{Settings $\rightarrow$ Format} to set a YUV colorspace, drop a \textit{Downsample} effect on the footage and set it as follows:
672
673 \begin{lstlisting}[numbers=none]
674 Horizontal:                                     2
675 Horizontal offset:      0
676 Vertical:                                               2
677 Vertical offset:                0
678          red
679 x  green
680 x  blue
681          alpha
682 \end{lstlisting}
683
684 Use the Camera in the compositor to shift the picture up or down a line to remove the most color interference from the image. If you have vertical blanking information or crawls which constantly change in each frame, block them out by using a Mask. This improves compression ratios.   More invasive quality improvement techniques involve removing the interlace via deinterlacing.
685
686 \subsection{Remove Interlacing}%
687 \label{sub:remove_interlacing}
688
689 Interlacing often exists on older video sources, such as camcorders, and was previously used in broadcast television. Playing this video results in jagged images on a computer monitor, but with Cinelerra you can use deinterlacing effects to solve this.  After some experimentation, it has been determined that the FFmpeg \textit{F\_kerndeint} plugin seems to produce the best results with the least amount of fiddling.  But some of the parameters described next are pertinent to other potential plugin usage.
690
691 \begin{description}
692         \item[Line Doubling:] done by the \textit{Deinterlace} effect when set to \textit{Odd} lines or \textit{Even} lines.  When applied to a track it reduces the vertical resolution by $\frac{1}{2}$ and gives you progressive frames with stairstepping. This is only useful when followed by a scale effect which reduces the image to half its size.
693         \item[Line averaging:] the \textit{Deinterlace} effect when set to \textit{Average even} lines or \textit{Average odd} lines does exactly what line doubling does except instead of making straight copies of the lines, it makes averages of the lines. This is actually useful for all scaling.
694         \item[Inverse Telecine:] this is the most effective deinterlacing tool when the footage is an NTSC TV broadcast of a film. It is described in Effect Plugins (\ref{sub:inverse_telecine}), chapter 10.
695         \item[Time base correction:] the previously discussed three tools either destroy footage irreversibly or do not work at times. Time base correction may be a better tool to use because it leaves the footage intact. It does not reduce resolution, perceptually at least, and does not cause jittery timing.
696         \item[Frames to Fields effect:] converts each frame to two frames, so it must be used on a timeline whose project frame rate is twice the footage's frame rate. In the first frame it puts a line-averaged copy of the even lines. In the second frame it puts a line-averaged copy of the odd lines. When played back at full framerate it gives the illusion of progressive video with no loss of detail. This effect can be reversed with the \textit{Fields to Frames} effect, which combines two frames of footage back into the one original interlaced frame at half the framerate. However, keep in mind that Frames to Fields inputs frames at half the framerate as the project. Effects before Frames to Fields process at the reduced framerate.  The output of Frames to Fields can not be compressed as efficiently as the original because it introduces vertical twitter and a super high framerate. Interlaced $29.97$ fps footage can be made to look like film by applying Frames to Fields and then reducing the project frame rate of the resulting $59.94$ fps footage to $23.97$ fps. This produces no timing jitter and the occasional odd field gives the illusion of more detail than there would be if you just line averaged the original. It is described in Effect Plugins (\ref{sub:frames_to_fields}), chapter 10.
697         \item[HDTV exceptions:] $1920\times1080$ HDTV is encoded in a special way. If it is a broadcast of original HDTV film, an inverse telecine works.  But if it is a rebroadcast of a $720\times480$ source, you need to use a time base and line doubling algorithm to deinterlace it.
698 \end{description}
699
700 \subsection{Making video look like film}%
701 \label{sub:making_video_look_film}
702
703 With an older camcorder video which has low quality video, you can improve the results by turning it into progressive 24 fps output as close as possible.  Only do this for low quality video.
704
705 \begin{enumerate}
706         \item Set project framerate to twice the video framerate.
707         \item Apply a \textit{Sharpen} effect. Set it to sharpness: 25, no interlacing, and horizontal only.
708         \item Drop a \textit{Frame to Fields} effect on the same track. Set Average Empty Rows to on and play through 
709         the video a few times to figure out which field is first. If the wrong field is first, the motion is shaky.
710         Any editing in the doubled frame rate may now damage the field order. It is not clear which is the
711         easiest way to support warnings for field glitches but you should go back to the normal framerate to
712         do editing or play test to make sure the fields are right.
713         \item Render just the video to the highest quality file possible.
714         \item Import the video back to a new track. Set the project framerate to 24. The new track should now
715         look more like a file with sharper images than the original footage.
716 \end{enumerate}
717
718 This entire procedure could be implemented in one non-realtime effect, but the problem with that is you will most often want to keep the field based output and the 24 fps output for historical purposes. A non-realtime effect would require all that processing just for the 24 fps copy.
719
720 \subsection{Clearing out haze}%
721 \label{sub:clearing_out_haze}
722
723 If you photograph a lot of haze instead of blue sky, these horizon shots will usually need more depth. You can use the \texttt{gradient} effect to improve your video. Drop the gradient effect on hazy tracks and set the following parameters:
724
725 \begin{lstlisting}[numbers=none]
726 Angle:                          0
727 Inner radius: 0
728 Outer radius: 40
729 Inner color:  blue 100% alpha 
730 Outer color:  blue 0% alpha
731 \end{lstlisting}
732
733 It is important to set the $0\%$ alpha color to blue even though it is $0\%$ alpha. The color of the outer alpha is still interpolated with the inner color. This is a generally applicable setting for gradient. Some scenes may work better with orange or brown for an evening feel.
734
735 \subsection{Making a ringtone for a cell phone}%
736 \label{sub:make_ringtone_phone}
737
738 \begin{enumerate}
739         \item Go to \texttt{File $\rightarrow$ Load files$\dots$} and load a sound file with Insertion strategy: \textit{Replace current project}.
740         \item Go to \texttt{Settings $\rightarrow$ Format }change \textit{Channels} to 1 and \textit{Samplerate} to 16000 or 22050.
741         \item Highlight a region of the timeline to use for the ringtone. To improve sound quality on the cell
742         phone, you need the maximum amplitude in as many parts of the sound as possible.
743         \item Right click on track Audio 1 and select \textit{Attach effect}. Highlight the \textit{Compressor} effect and hit
744         Attach in the attachment popup.
745         \item Make sure the insertion point or highlighted area is in the region with the Compressor effect.
746         \item Right click on track Audio 2 and select \textit{Attach effect}.
747         \item Highlight Audio 1 Compressor and hit Attach.
748         \item Click the Audio 1 Compressor's magnifying glass to bring up the compressor GUI.
749         \item Set the following parameters:
750         \begin{lstlisting}[numbers=none]
751         Reaction secs: -0.1
752         Decay secs: 0.1
753         Trigger Type: Total
754         Trigger: 0
755         Smooth only: No
756         \end{lstlisting}
757         \item Click Clear to clear the graph. Click anywhere in the grid area and drag a new point to 0 Output
758         and -50 Input. The graph should look similar to the figure~\ref{fig:ringtone}.
759         \item Go to \texttt{File $\rightarrow$ Render}. Specify the name of an mp3 file to output to. Set the file format to MPEG
760         Audio. Click the wrench for Audio and set Layer to III and Kbits per second to 24 or 32. Check
761         Render audio tracks and uncheck Render video tracks. Hit OK to render the file.
762 \end{enumerate}
763
764 \begin{figure}[htpb]
765         \centering
766         \includegraphics[width=0.8\linewidth]{images/ringtone.png}
767         \caption{Using the Compressor plugin graph to create a ringtone}
768         \label{fig:ringtone}
769 \end{figure}
770
771 The resulting .mp3 file can be uploaded to a web server and then the phone's web browser can download the .mp3 file directly from the URL. There may be a size limit on the file.
772
773 \subsection{Time stretching audio}%
774 \label{sub:time_stretching_audio}
775
776 It may appear that time stretching audio is a matter of selecting a region of the audio tracks, enabling recording for the desired tracks, going to\texttt{ Audio $\rightarrow$ Render Effect}, and applying \textit{TimeStretch}. In actuality there are 3 audio effects for time stretching: Time Stretch, Resample, and Asset info dialog.
777
778 \textit{Time Stretch} applies a fast Fourier transform to try to change the duration without changing the pitch, but this introduces windowing artifacts to the audio. It is only useful for large changes in time because obvious changes in duration make windowing artifacts less obtrusive.
779
780 For smaller changes in duration, in the range of $5\%$, \textit{Resample} should be used. This changes the pitch of the audio but small enough changes are not noticeable. Resample does not introduce any windowing artifacts, so this is most useful for slight duration changes where the listener is not supposed to know what is going on.
781
782 Another way to change duration slightly is to go to the Resources window, highlight the media folder, right click on an audio file, click on \textit{Info}. Adjust the sample rate in the Info dialog to adjust the duration. This method also requires left clicking on the right boundary of the audio tracks and dragging left or right to correspond to the length changes.
783
784 \subsection{Pan and zoom: still images}%
785 \label{sub:pan_zoom_still_image}
786
787 Cinelerra's powerful keyframe features allow you to use pan and zoom effects on still pictures.
788
789 \begin{enumerate}
790         \item Load and create a clip from a still image. Make the clip 10 seconds long.
791         \item Activate the automatic generation of keyframes.
792         \item Using the transport controls, go to the beginning of the clip.
793         \item Using the compositing camera control set the clip's initial position.
794         \item Using the transport controls, move forward a couple of seconds on the clip.
795         \item Dragging on the compositing camera, move the camera center to a new position further along.
796         \item Next go to the beginning of the clip and play it.
797 \end{enumerate}
798
799 You can see that the camera smoothly flows from keyframe point to next keyframe point, as Cinelerra automatically adjusts the camera movement in straight lines from point to point.
800