Credit Andrea with Windows.tex changes based on reading updates in CV manual
[goodguy/cin-manual-latex.git] / parts / DVD.tex
1 \chapter{DVD and Bluray Creation}%
2 \label{cha:dvd_bluray_creation}
3 \index{DVD}
4 \index{BluRay}
5
6 This section describes how to create a blu-ray DVD, or \textcolor{red}{BD} referring to a \textcolor{red}{B}lu-ray \textcolor{red}{D}VD, and a regular DVD, or \textcolor{red}{SD} referring to a \textcolor{red}{S}tandard \textcolor{red}{D}VD.  The DVDs (plural usage of DVD means either BD or SD) created are unencrypted, unlike commercially available movie DVDs.  This \CGG{} version conceivably can create different variations of DVD/Blu-ray media but for the casual user the most standard usages are readily usable and will be described here.
7 In \CGG{} DVD and Bluray creation is a convenience for users who want to edit and then just make basic media without having to work too hard, therefore
8 all features will not be available.
9
10 Some preliminary information follows.  For NTSC, SD media is almost always $720\times480$ interlaced (the format in the United States, US).  For PAL, SD media is almost always $720\times576$ interlaced (Europe, EU, and most of the world).  An SD can conceivably be created with a lower resolution – for example $352\times240$ MPEG-1 -- but it is not useful.  Aspect ratio for either NTSC or PAL can be $4:3$ or $16:9$.  
11
12 Frames per seconds is usually $29.97$ for NTSC and $25$ fps for PAL.  The standard SD dvd generally uses the MPEG-2 program stream with a filename extension of \texttt{m2v}.  BD blu-ray media is not normally interlaced, but you can leave it interlaced.  Blu-ray uses the MPEG transport stream which contains 1 or more program streams with a default filename extension of \texttt{m2ts}.
13
14 Requirements for creating DVDs is the hardware device to write the media on and, obviously, the blank media for either BD or SD.  When generating SD media, you will have to install \textit{dvdauthor} and for BD media, install \textit{udftools} if they are not on your system.  Also, keep in mind that to mount filesystems for creating files and to burn DVDs, you will have to be root since you have to have privileges, unless special permissions have been provided for a non-root user.  It is also highly recommended to
15 run the \CGG{} startup from a terminal window, instead of the icon, in order to see informative messages of how to actually write the output (at prompt: keyin \texttt{<install\_directory\_path/bin/cin} or 
16  \texttt{<install\_directory\_path/<your\_version>.AppImage}).
17
18 A warning here -- writing blu-ray BDs and  regular SDs can take a large amount of clock time.  Keep in mind that a blu-ray can contain 25 hours of viewing, so would take multiple hours to just write one.
19
20 The amount of data you have to render determines the amount of disk space you will need for working.  The max disk space needed for a completely full media disc is a little over $100GB$ for $50GB$ Double Layer (DL) media or $50GB$ for a single layer BD blu-ray.  A standard SD of $4.7GB$ needs about $10GB$ disk space. You will need much less if the render for blu-ray is less than 25 hours of media.  Generally you will need twice as much disk space as will be written on the media to ensure you have sufficient space for working and copying.
21
22 The most important thing you need to know about in order to get started is \textit{Format} and \textit{Scale}  in the \textit{Create dvd or bd} window.  Format settings shown in the \texttt{Set Format} window are set accordingly to an algorithm.  Basically, it will take whatever you say in the asset format.  It matches that against the known Presets available so that is what will be shown.  If the asset format doesn't match any of the Presets default formats, then that will be shown as the \textit{User Defined} format.  In addition when you load media, the format is initially set to \textit{same as source} so matches the source input and if that matches a known preset, then that is what is shown.  The PAL versus NTSC only comes into play when there is no known correct matching format when you attempt to create a DVD Render batch job.  It is applied when you click OK. For example, if you load up a YouTube video, it will not match any known format and will choose PAL or NTSC based on time zone.
23
24 Figure~\ref{fig:preset01} shows pulldown \textit{Presets} in \textit{Set Format} window:
25
26 \begin{figure}[htpb]
27     \centering
28     \includegraphics[width=0.7\linewidth]{preset01.png}
29     \caption{When choose PAL, values get changed in window to reflect PAL}
30     \label{fig:preset01}
31 \end{figure}
32
33 A quick set of basic steps to create DVDs is immediately below and usually just using the defaults will get you something.  However there is a serious issue with interaction between the Operating System and bdwrite when creating a BD/blu-ray that requires automount to be turned off.  For more details on using automount see: ~\ref{sec:bluray_workaround_mount_umount}.
34
35 \begin{enumerate}
36     \item If not logged in as root, you will get an error message in order to avoid doing a lot of work and then failing out because root is required for automount and to write on DVD hardware.
37     \item Load your input source media via: \texttt{File $\rightarrow$ Load files}.
38     \item Choose PAL or NTSC for SD/dvd or 1080P/24 for blu-ray in \texttt{Settings $\rightarrow$ Format}.
39     \item If DVD "Interlace Mode" of Bottom Field First is wanted, you MUST set that in \texttt{Settings $\rightarrow$ Format}. If you do, then also remember to change it when you no longer want BFF.
40     \item For blu-ray, choose BD Render or for PAL/NTSC, choose DVD \textit{Render} in  \textit{File} menu.
41     \item Designate a \textit{work path} with sufficient disk space and then Chk-OK.
42     \item When the Batch Render window comes up, click on \textit{Start} and the batch jobs will run.
43     \item Read the final messages echoed to the screen to see the command for burning… OR:
44     \item Use the provided directory name to:\\ 
45     \texttt{cd /<target directory>bd\_(or dvd\_)<date-time>}
46     \item Load your media, format if needed, note device name to substitute for \textit{<bd>} or \textit{<dvd>}
47     \begin{itemize}
48         \item If rewritable blu-ray, use \\
49         \texttt{dd if=./bd.udfs of=/dev/<bd> bs=2048000} \\
50         Note: unwritten media must be quickly formatted one time using: \\
51         \texttt{dvd+rw-format /dev/bd}
52         \item If write-once blu-ray, use \\
53         \texttt{growisofs -dvd-compat -Z /dev/<bd>=./bd.udfs}
54         \item If any DVD media,    use \\
55         \texttt{growisofs -dvd-compat -Z /dev/<dvd> -dvd-video ./iso}
56     \end{itemize}
57 \end{enumerate}
58
59 Any problems encountered will require that you read more information in this section to include specific details, helpful hints, and problem resolution.
60
61 \paragraph{Details and specific explanations} to create blu-ray or regular DVD are provided here.  It is very advantageous to startup \CGG{} from the command line prompt instead of the icon.  Also, please be root or your hard work will be lost when the automount is issued and fails for bluray udfs mounting.
62
63 The general design of the DVD/blu-ray generation operations is to first render media using batch rendering and then terminate \CGG{} to start a script which creates the target device filesystem data.  These scripts are the \texttt{dvd.sh} and \texttt{bd.sh} scripts written into the target directory.  For DVD, the general plan is to write a directory \texttt{<target>/iso} with the dvd filesystem via \textit{dvdauthor} and then generate an iso9660 filesystem and write it to a dvd via \textit{growisofs}.  
64
65 For blu-ray, the filesystem generation is slightly harder.  First, it creates an empty filesystem image \texttt{<target>/bd.udfs} using \textit{mkudffs} which makes a big hole for the filesystem data. The hole is made just a little bigger than the data written by \textit{bdwrite} so that you don't have to write an entire $25GB$ or $50GB$ disc even if no data exists.
66 The actual calculation for the mkudffs size is yourfile.m2ts size-in-bytes/2048 + 4096.
67 This empty filesystem is loopback mounted to make it writable, and the linux kernel manages the filesystem image. The bdwrite program applies the blu-ray structure to the UDF filesystem by creating the needed BDMV blu-ray filesystem, which the kernel stores onto the image file \texttt{bd.udfs}.  When udfs is unmounted, the kernel finalizes the disk image on bd.udfs.  The bd.udfs image can be written directly to a blu-ray disk via \textit{dd} or \textit{growisofs}. 
68
69 NOTE of IMPORTANCE: there is a serious situation with the interaction between the Operating System (OS) and bdwrite when creating blu-ray, that requires automount to be turned off.  The blu-ray automatic script unmounts the blu-ray/UDF filesystem but the system has not finalized the directories so the OS creates a new loop file device and the data is loaded and cached for use by the new loop but it is stale.  Consequences is that not all of the data is written where it should be.  The solution is for the OS not to mount this second mount so we have to make sure it doesn't.  There are 2 methods to fix this.  The first and easiest is by using the following command to disable automount:
70
71 \begin{lstlisting}[style=sh]
72 gsettings set org.gnome.desktop.media-handling automount false
73 \end{lstlisting}
74
75 This can be reversed when you have completed the blu-ray generation via:
76
77 \begin{lstlisting}[style=sh]
78 gsettings set org.gnome.desktop.media-handling automount true
79 \end{lstlisting}
80
81 A different and more complicated method you can use to turn off automount is to download and install the \textit{dconf-editor}.  Automount is a system parameter and only needs to be done once unless you do not want automounts to always be disabled.
82
83 \begin{enumerate}
84     \item run: \textit{dconf-editor}
85     \item select: \texttt{org $\rightarrow$ gnome $\rightarrow$ desktop $\rightarrow$ applications $\rightarrow$ media-handling}
86     \item uncheck: \textit{automount}
87     \item close \textit{dconf-editor} window
88 \end{enumerate}
89
90 Immediately below are the detailed steps with explanations for creating SD or BD media.
91
92 \textit{Step 1}: Construct a session with the desired presentation:
93
94 \begin{itemize}
95     \item Format frame rates choices are $29.97$ or $25$ for SD, based on the user's timezone, with NTSC 29.97/US or PAL 25 /EU.  For BD, the media input will be analyzed to automatically pick the default format or if unknown, the user's timezone will be used to default to $1920/29.97i$ for US or $1920/25i$ for EU.  Be sure to set the rendering parameters in the \texttt{settings $\rightarrow$ format} menu.
96     \item Choose audio stereo or 5.1, again depending on your media.
97     \item Target Geometry will be $720\times480$ (US) or $720\times576$ (EU) for SD.
98 \end{itemize}
99
100 \textit{Step 2}: From the main window, select  \texttt{file $\rightarrow$ BD Render}   or    select  \texttt{file $\rightarrow$ DVD Render} (figure~\ref{fig:bluray_dvd}).  Then:
101
102 \begin{figure}[htpb]
103     \centering
104     \begin{minipage}[h]{0.49\linewidth}
105         \center{\includegraphics[width=0.99\linewidth]{bluray01.png}} \\ BluRay (scale pulldown)
106     \end{minipage}
107     \begin{minipage}[h]{0.49\linewidth}
108         \center{\includegraphics[width=0.99\linewidth]{dvd01.png}} \\ DVD (format pulldown)
109     \end{minipage}
110     \caption{BD Render and DVD Render}
111     \label{fig:bluray_dvd}
112 \end{figure}
113
114 (Note: both the BD and the DVD windows above, show insufficient space, \textit{disk space:} in red)
115
116 \begin{itemize}
117     \item Select desired features, check/un-check as appropriate.
118     \item Click OK check button.  It is very important to realize that when you check OK, the EDL will be saved and that will be used for batch job rendering.  If you bring up the Batch Render and then change some parameters, they will not take effect UNLESS you remember to either check \textit{Save to EDL Path} or \textit{Use Current EDL} in the Batch Render window.  You will get a reminder automatically if \textit{warn if jobs/session mismatched} is checked.
119 \end{itemize}
120
121 Explanation of the choice boxes as seen in figure~\ref{fig:bluray_dvd} for both SD and BD menus is given below.  Many of them are plugins which allow you to further manipulate the settings for best results.  They are just suggestions set by the program automatically based on your input media, and can be reset to suit your needs.  These are listed in the next 4 points.
122
123 \begin{enumerate}
124     \item If the media does not match the DVD target geometry, and the scale plugin is not already in use, then the \textit{scale} plugin is applied with scaling set to fit the media dimensions to the DVD format target geometry.
125     \item If the video height is at least twice the DVD height and the input media is interlaced, then the \textit{deinterlace} plugin is applied with odd line sampling.
126     \item \textit{Audio 5.1} will automatically be set to the wide-audio if you have 6 tracks of audio.
127     \item To allow video data to be accessible and overlay properly, the track buffers are \textit{resized} to the largest track frame size in use (\textit{Resize Tracks}). The theory behind this is to make sure to have enough memory to cover the entire presentation for transcoding.
128 \end{enumerate}
129
130 \noindent All of the current choice boxes are further defined immediately following.
131
132 \begin{description}
133     \item[Deinterlace] remove the interlace.  Interlacing is a video scanning system in which alternating lines are transmitted so that half a picture is displayed each time the scanning beam moves down the screen.  You lose a lot and the quality is bad when you view interlacing on a progressive TV.  You might not really want to use deinterlace, because if you deinterlace non-interlaced media, it will look awful.
134 In the case of DVD only, for interlaced media when you do not check the Deinterlace option, it will always be done as Top Field First.  
135 To get DVD media to be Bottom Field First, you MUST set the "Interlace Mode" in \texttt{Settings $\rightarrow$ Format}.
136     \item[Scale] alter the spatial mapping of an image to increase or reduce the size; modifies the picture.  When some programs scale from $4:3$ to $16:9$ they will automatically cut off the appropriate section of the image for you.  It is necessary to keep in mind, that \textit{square pixels} is the true end goal of scaling, not the aspect ratio which could result in squished or stretched output.  More information about scaling will be provided on a subsequent page with usage of the \textit{Scale Ratio} plugin.
137     \item[Profile] for bluray only, use the default bluray.m2ts or choose bluray\_lpcm.m2ts for linear pulse code modulation for digitally encoding uncompressed audio information.
138     \item[use tsmuxer] for bluray only, to use tsMuxer as a transport stream muxer for remuxing/muxing elementary streams, check this box.  Usage of tsmuxer requires that your computer have the tsmuxer software installed along with any of its prerequisites. The default is do not use tsmuxer.
139     \item[Histogram] remaps the color space.  The color space ranges from $0-255$ for 8-bit color values.  You can use this tool to remap the color space to use the entire space or for stretching the contrast.  Also, it lets you perform global color-correction on the image.  You can use this to correct for color screens that are \textit{too blue}, or for color Televisions that produce \textit{brownish} output, or whatever.  In addition to color-correction, you can use the RGB modification tool to add color to images that didn't have color to begin with.  For instance, you can \textit{pseudo-color} greyscale media.
140     \item[Inverse Telecine] the reverse of $3:2$ pulldown where frames, which were duplicated to create 60-fields/second video from 24-frames/second film, are removed.  MPEG-2 video encoders usually apply an inverse Telecine process to convert 60-fields/second video into 24-frames/second encoded video. The encoder adds information enabling the decoder to recreate the 60-fields/second display rate. \textit{Telecine}, i.e. $3:2$ pulldown, is used to transfer film to video. That's where the $3:2$ ratio comes in. To ensure that there will consistently be 60 frames per second, the first frame is displayed on the TV screen 3 times and the second frame is displayed 2 times. The following frame is repeated 3 times, the next one 2 times, etc. throughout the film.  For inverse telecine, you show 2 of the film frames for 3 of output frames.  Only check \textit{Inverse Telecine} if you have film or something that is $24fps$ and want to project to $30fps$ (most likely this will never be necessary).
141     \item[Audio 5.1] 6 channel surround sound.  For most home systems, uses five full bandwidth channels and one low-frequency effects channel.  Could automatically get set as explained previously.
142     \item[Aspect Ratio] aspect ratio may be automatically set to $4:3$ or $16:9$.  Aspect ratio would better be defined as the size of the display, monitor, or TV which will be used to view the output.  If you measure your old TV, which supposedly is $4:3$ and your latest digital TV, which is supposedly $16:9$, you will see that those ratios aren't always correct anyway.  Then measure your laptop monitor, your desktop monitor, and your neighbor's, and lo and behold, the ratios don't fit either of the purported \textit{standard} aspect ratio.  Maintaining square pixels via scaling is more important in the long run.
143     \item[Use FFMPEG] this is user's choice; it is recommended and faster but more difficult to modify due to numerous options. For blu-ray, ffmpeg must be used and is not an available option.
144     \item[Resize Tracks] change track width and height as explained previously.  The size is adjusted to the largest frame size needed.
145     \item[Chapters at Labels] for DVDs without this checked, chapter markers are automatically inserted every 5 minutes.  The chapter labels can then be \textit{skipped to} when playing the DVD.  If instead, you want to put labels in at opportune times, you will have to run dvdauthor outside of \CGG{} and mark the chapter labels yourself by hand.  In that case, you should check the box \textit{Chapters at Labels} so that the automatic 5-minute labels are not created.  This checkbox is not currently available for blu-ray, but you can easily create
146 chapters on blu-ray by adding '-c timeinterval in ticks' as the first argument to bdwrite in the bd.sh job
147 generated by “BD Render” and then executing that job manually.  On 1 test computer 100 ticks equalled 20 seconds.  When "use tsmuxer" option is included, there is by default a chapter every 5 minutes.  This
148 can be customized by modifying the bd.meta file associated with your current
149 job, changing the '--auto-chapters=5' to your choice in minutes instead of 5, and then rerunning the 
150 pertinent lines seen in your window.
151 \end{description}
152
153 \begin{figure}[htpb]
154     \centering
155     \includegraphics[width=1.0\linewidth]{dvd02.png}
156     \caption{check Deinterlace; Histogram and Resize Tracks}
157     \label{fig:dvd02}
158 \end{figure}
159
160 Figure~\ref{fig:dvd02} shows on the upper right side the \textit{Create DVD} window with Deinterlace, Histogram and Resize Tracks checked.  Also Scale is set to Scaled.  Once the green checkmark is clicked, the \textit{Batch Render} window comes up and in the main window you will see the 3 plugins below the video track on the main window.  By clicking on the magnifying glass that appears on the rightmost side, the controls for each will popup and you can make any necessary adjustments.  Note the numerous choices for Deinterlace; the Value, Red, Green, and Blue for color adjustments in the Histogram window; and Scale Ratio popup menu for numerical settings control.
161
162 The \texttt{Scale} parameter gives you a lot of flexibility.  A default based on your input media is provided for you but possible choices are None, Scaled, Cropped, Filled, Horiz Edge, and Vert Edge.  You will have the opportunity to manipulate the desired results in the \textit{Scale Ratio} window.  Values for W (width), H (height), and X/Y coordinates are the number of pixels.  For example, if video is $720\times432$, that is obviously 720 pixels by 432 pixels and this would be the values for Dst W and for Dst H.  So if you have some media that is off center you can crop by changing the SRC Y value AND then change DST X/Y to non-zero. It will become the output origin.  To see what it does, change them from $0.0$ to $400.0$ and you will see big changes in the compositor window.
163
164 For example, if you have the Cropped choice for the Scale, you will want to manipulate the \textit{ScaleRatio} plugin (the magnifying glass on the main window video track) which brings up the Scale window.  For cropped top instead of crop both top and bottom, modify the \textit{Src Y}.   As you change the Y scale, you will see the cropping take place in the Compositor. 
165
166 Scaling options are provided in order to preserve image aspect ratio.  To determine which scaling option to use, it is important to correctly identify your source/destination video aspect ratios.  Next is a short explanation of possible options.
167
168 \begin{description}
169     \item[None] do not do any scaling.  The destination output matches the source input.  There is no resizing.
170     \item[Scaled] do not use uniform scaling on X and Y.  Just make it fit and you will might end up with squishing/stretching in one direction or the other in order to do that.  This happens when the input aspect ratio is different than that displayed on the output.
171     \item[Cropped] removes outer edges of a source image in order to fit the image on the output display.  This is done in order to maintain uniform geometry scale on the destination display without being affected by the particular factor of original media aspect ratio.  Since cropping omits image area, and the areas which you wish to view may not be viewed when the image is centered, you can pan the image source using the Src X/Y to modify which area is in view.  You can also think of this as \textit{scaled up}.
172     \item[Filled] the entire output display will be filled with image content but in order to do so, some of the image may have had to be cut.  Any mismatch between the two will be filled with black.  Centering of the image can be modified by using the Dest X/Y variables in the Scale Ratio controls.  You can also think of this as \textit{scaled down}.
173     \item[Horiz Edge] this indicates preserving of the Horizontal edge.
174     \item[Vert Edge] this option preserves the Vertical edge.
175 \end{description}
176
177 Horizontal and Vertical are duplicates or restatement of same functionality as Cropped or Filled but are provided as options to accommodate different ways of thinking.  In any case, you can choose which outer edges of the image to crop by using the \textit{Show Controls} of the Scale Ratio plugin.  For example, you can ensure that no \textit{action} is lost by displaying the center of the screen only or making sure that any textual information on the bottom is not lost by cutting only the top off.
178
179 \textit{Step 3}: Batch render menu appears with \texttt{m2ts} format selected for blu-ray or \texttt{dvd} format selected for regular/standard DVD when File Format selected is ffmpeg in the previous \textit{Create DVD} menu. It will work just fine without selecting ffmpeg for DVD and may be advantageous not to.  Using the audio/video wrench tools (you will have to have the video batch job highlighted to manipulate the video or audio batch job for audio).
180
181 \begin{itemize}
182     \item Setup the audio bitrate ($192000$ recommended).  Data rate is $192K$ default.
183     \item Setup the video bitrate ($6000000 - 12000000$ recommended).  $10Mb/sec$ is the current default.
184     \item Click OK check button.
185 \end{itemize}
186
187 The default bitrate is the largest value possible.  The actual \textit{target} bitrate is calculated based on a formula from the blu-ray/DVD code.  It divides the media size (in bits)  by the video time (in seconds) to find the bitrate that will \textit{just fit} on the target media.  This could create a weird bitrate if the media is large, and the video time is small, so the default/target bitrate is limited to $10Mb/s$.Batch jobs are then built and appended to the job list.  Once these batch jobs are built, if you make any changes, you have to start over.  You will see listed the batch jobs that are created to perform the rendering/tasks -- 2 jobs for blu-ray, one for audio/video processing and one for the scripts.  There will be 3 batch jobs created for DVD when not using ffmpeg to include one each for audio and video and then one more for the scripts.  When you click on \texttt{start}, it fires off those jobs and you will see the rendering main window progress bar in the bottom corner reflecting the fact that it is currently processing.  Be aware that the \CGG{} program will be totally shutdown AFTER the batch jobs finish.
188
189 Figure~\ref{fig:dvd-batch01} for DVD and Figure~\ref{fig:dvd-batch02} for BD show creation renders with batch jobs queued up and ready to be started.  Note that because it is not ffmpeg, the processing of video is done separately from audio.  If you need to modify the video tracks, which you can see is ghosted out, you need to highlight the first batch job listed.  Be sure to highlight the first batch job before pressing Start so it runs all of the jobs and be sure the X for job enabled is set.
190
191 \begin{figure}[htpb]
192     \centering
193     \includegraphics[width=1.0\linewidth]{dvd-batch01.png}
194     \caption{Batch render for DVD creation}
195     \label{fig:dvd-batch01}
196 \end{figure}
197
198 % \vspace{-4ex}
199 \begin{figure}[htpb]
200     \centering
201     \includegraphics[width=1.0\linewidth]{dvd-batch02.png}
202     \caption{Batch render for BD creation}
203     \label{fig:dvd-batch02}
204 \end{figure}
205
206 When you click on \textit{start}, it fires off those jobs and you will see the rendering main window progress bar in the bottom corner reflecting the fact that it is currently processing.  Be aware that the \CGG{} program will be \textbf{totally shutdown after the batch jobs finish} and you will be at the command line prompt.
207
208 This will produce a new directory in your target path which contains a filesystem image file.
209 For example: \\
210 \texttt{/<target directory>/bd\_(or dvd\_)<date-time>/} \\
211 Directory and file names should not be changed at this time because the scripts and programs rely on the given names in order to proceed.  You can change them later for your own purposes.
212
213 If bluray to test the filesystem you just created, use the command line interface; loopback mount the filesystem image which was generated in the target directory.  For example if blu-ray:
214
215 \begin{lstlisting}[style=sh]
216 cd /<target directory>/bd_(or dvd_)<date-time>/
217 mount -o loop,ro ./bd.udfs ./udfs
218 #check the media using a compatible media rendering tool like ffplay
219 umount ./udfs...
220 \end{lstlisting}
221
222 To burn blu-ray media you will need to run from the command line interface.  In the examples below, \texttt{/dev/bd} represents your blu-ray writer device (for example: \texttt{/dev/sr1}) and \texttt{/dev/dvd} represents your dvd writer device (for example: \texttt{/dev/sr0}).
223
224 \subsubsection*{Blu-ray Media}
225 \label{ssub:bluray_media}
226 \index{BluRay}
227
228 For rewritable blu-ray (recommended) (BD-RE):
229
230 Note: new or previously unwritten media must be formatted first using:
231
232 \begin{lstlisting}[style=sh]
233 dvd+rw-format /dev/bd   #only done once and does not take very long
234 \end{lstlisting}
235
236 To write or rewrite rewritable blu-ray media:
237
238 \begin{lstlisting}[style=sh]
239 cd /<target directory>/bd_(or dvd_)<date-time>/
240 dd if=./bd.udfs of=/dev/bd bs=2048000    #the growisofs command below also works
241 \end{lstlisting}
242
243 To write blu-ray write-once media: (BD-R)  (no pre-formatting needed):
244
245 \begin{lstlisting}[style=sh]
246 cd /<target directory>/bd_(or dvd_)<date-time>/
247 growisofs -dvd-compat -Z /dev/bd=./bd.udfs
248 \end{lstlisting}
249
250 \subsubsection*{DVD Media}
251 \label{ssub:dvd_media}
252 \index{DVD}
253
254 For rewritable DVD (DVD+RW):
255
256 Note: unwritten media must be formatted first using:
257
258 \begin{lstlisting}[style=sh]
259 dvd+rw-format /dev/dvd   #only done once and does not take very long
260 \end{lstlisting}
261
262 To write a DVD, load blank media and run the following from the command line (requires dvdauthor):
263
264 \begin{lstlisting}[style=sh]
265 cd /<target directory>/bd_(or dvd_)<date-time>/
266 growisofs -dvd-compat -Z /dev/dvd -dvd-video ./iso
267 \end{lstlisting}
268
269 Figure~\ref{fig:dvd-batch03} shows the availability of 4:2 :2 for a Batch Render seen by clicking on wrench icon.
270
271 \begin{figure}[htpb]
272     \centering
273     \includegraphics[width=0.99\linewidth]{dvd-batch03.png}
274     \caption{Video options for bluray yuv422p}
275     \label{fig:dvd-batch03}
276 \end{figure}
277
278 Figure~\ref{fig:dvd-batch04} shows the availability of 10-bit high quality 4:2 :2 for a Batch Render seen by clicking on wrench icon.  You need specially compiled \CGG{} in order to use the x265 10-bit as opposed to 8-bit.
279
280 \begin{figure}[htpb]
281     \centering
282     \includegraphics[width=0.99\linewidth]{dvd-batch04.png}
283     \caption{Video options for bluray yuv422p10}
284     \label{fig:dvd-batch04}
285 \end{figure}
286
287 \section{Output Terminal Messages from Creating DVDs}%
288 \label{sec:output_terminal_messages_dvd}
289
290 Below are examples of what the batch jobs generate and you will see on the terminal screen if you started the \CGG{} program in the recommended manner from a terminal window.  It is just informational but will let you know if errors.  In looking at any of the output, you can safely ignore the errors that read \textit{Unsupported codec with id 100357 for input stream 0} -- this comes from \textit{nav-data} (navigation data).  The first 2 examples are seen from running the batch jobs; the last 2 are from the single line execution which records the media output to the DVD hardware.
291
292 \subsubsection*{SD Example: Partial Output during \CGG{} run}
293 \label{ssub:sd_example_partial_output}
294 \index{DVD!partial output messages run}
295
296 \begin{lstlisting}[style=sh]
297 ...
298 FFMPEG::open_decoder: some stream times estimated
299 Render::render_single: Session finished.
300 FFMPEG::open_decoder: some stream times estimated
301 Render::render_single: Session finished.
302 running /tmp/dvd_20160407-113530/dvd.sh 1 /tmp/dvd_20160407-113530
303 INFO: [mplex] mplex version 2.1.0 (2.2.7 $Date: 2012/11/17 01:55:16 $)
304 INFO: [mplex] File /tmp/dvd_20160407-113530/dvd.m2v looks like an MPEG Video stream.
305 . . .
306 INFO: [mplex] MUX STATUS: no under-runs detected.
307 DVDAuthor::dvdauthor, version 0.7.1. 
308 Build options: gnugetopt graphicsmagick iconv freetype fribidi fontconfig
309 Send bug reports to <dvdauthor-users@lists.sourceforge.net>
310
311 INFO: default video format is NTSC
312 INFO: dvdauthor creating VTS
313 STAT: Picking VTS 01
314
315 STAT: Processing /tmp/dvd_20160407-113530/dvd.mpg...
316 STAT: VOBU 32 at 15MB, 1 PGCs
317 INFO: Video pts = 0.133 .. 22.789
318 INFO: Audio[0] pts = 0.133 .. 22.789
319 STAT: VOBU 46 at 21MB, 1 PGCs
320 CHAPTERS: VTS[1/1] 0.000
321 INFO: Generating VTS with the following video attributes:
322 INFO: MPEG version: mpeg2
323 INFO: TV standard: ntsc
324 INFO: Aspect ratio: 16:9
325 INFO: Resolution: 720x480
326 INFO: Audio ch 0 format: ac3/6ch,  48khz drc, 'en'
327
328 STAT: fixed 46 VOBUs                         
329 INFO: dvdauthor creating table of contents
330 INFO: Scanning /tmp/dvd_20160407-113530/iso/VIDEO_TS/VTS_01_0.IFO
331 To burn dvd, load blank media and run:
332 growisofs -dvd-compat -Z /dev/dvd -dvd-video /tmp/dvd_20160407-113530/iso
333 \end{lstlisting}
334
335 \subsubsection*{BD Example: Partial Output during \CGG{} run}
336 \label{ssub:bd_example_partial_output}
337 \index{BluRay!partial output messages run}
338
339 \begin{lstlisting}[style=sh]
340 ...
341 FFMPEG::open_decoder: some stream times estimated
342 Render::render_single: Session finished.
343 + PATH=/usr/lib64/ccache:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/mnt0/build5/cinelerra-5.1/bin
344 + mkdir -p /tmp/bd_20161224-162059/udfs
345 ++ du -sb /tmp/bd_20161224-162059/bd.m2ts
346 ++ sed -e 's/[  ].*//'
347 + sz=19811904
348 + blks=13769
349 + mkudffs /tmp/bd_20161224-162059/bd.udfs 13769
350 start=0, blocks=16, type=RESERVED 
351 start=16, blocks=3, type=VRS 
352 start=19, blocks=237, type=USPACE 
353 start=256, blocks=1, type=ANCHOR 
354 start=257, blocks=16, type=PVDS 
355 start=273, blocks=1, type=LVID 
356 start=274, blocks=13238, type=PSPACE 
357 start=13512, blocks=1, type=ANCHOR 
358 start=13513, blocks=239, type=USPACE 
359 start=13752, blocks=16, type=RVDS 
360 start=13768, blocks=1, type=ANCHOR 
361 + mount -o loop /tmp/bd_20161224-162059/bd.udfs /tmp/bd_20161224-162059/udfs
362 + bdwrite /tmp/bd_20161224-162059/udfs /tmp/bd_20161224-162059/bd.m2ts
363 + umount /tmp/bd_20161224-162059/udfs
364 + echo To burn bluray, load writable media and run:
365 To burn bluray, load writable media and run:
366 + echo for WORM: growisofs -dvd-compat -Z /dev/bd=/tmp/bd_20161224-162059/bd.udfs
367 for WORM: growisofs -dvd-compat -Z /dev/bd=/tmp/bd_20161224-162059/bd.udfs
368 + echo for RW: dd if=/tmp/bd_20161224-162059/bd.udfs of=/dev/bd bs=2048000
369 for RW: dd if=/tmp/bd_20161224-162059/bd.udfs of=/dev/bd bs=2048000
370 \end{lstlisting}
371
372 \subsubsection*{SD Example – Partial Output during writing disc media}
373 \label{ssub:sd_example_partial_output_writing}
374 \index{DVD!partial output messages writing}
375
376 \begin{lstlisting}[style=sh]
377 growisofs -dvd-compat -Z /dev/sr0 -dvd-video /tmp/dvd_20161224-160756/iso
378 WARNING: /dev/sr0 already carries isofs!
379 About to execute 'mkisofs -dvd-video /tmp/dvd_20161224-160756/iso | builtin_dd of=/dev/sr0 obs=32k seek=0'
380 I: -input-charset not specified, using utf-8 (detected in locale settings)
381 75.62% done, estimate finish Sat Dec 24 16:09:51 2016
382 Total translation table size: 0
383 Total rockridge attributes bytes: 0
384 Total directory bytes: 4096
385 Path table size(bytes): 42
386 Max brk space used 1a000
387 6624 extents written (12 MB)
388 /dev/sr0: "Current Write Speed" is 4.1x1352KBps.
389 builtin_dd: 6624*2KB out @ average 0.7x1352KBps
390 /dev/sr0: flushing cache
391 #
392 \end{lstlisting}
393
394 \subsubsection*{BD Example – Partial Output during writing disc media}
395 \label{ssub:bd_example_partial_output_writing}
396 \index{BluRay!partial output messages writing}
397
398 \begin{lstlisting}[style=sh]
399 growisofs -dvd-compat -Z /dev/sr0=/tmp/bd_20161224-155658/bd.udfs
400 Executing 'builtin_dd if=/tmp/bd_20161224-155658/bd.udfs of=/dev/sr0 obs=32k seek=0'
401 /dev/sr0: "Current Write Speed" is 2.0x4390KBps.
402 1605632/24524800 ( 6.5%) @0.0x, remaining 1:39 RBU 100.0% UBU   0.0%
403 1605632/24524800 ( 6.5%) @0.0x, remaining 2:22 RBU 100.0% UBU 100.0%
404 1605632/24524800 ( 6.5%) @0.0x, remaining 3:05 RBU 100.0% UBU 100.0%
405 5865472/24524800 (23.9%) @0.3x, remaining 0:54 RBU 100.0% UBU  33.3%
406 11829248/24524800 (48.2%) @0.4x, remaining 0:21 RBU  75.8% UBU  37.5%
407 17858560/24524800 (72.8%) @0.4x, remaining 0:08 RBU  39.8% UBU  79.2%
408 23789568/24524800 (97.0%) @0.4x, remaining 0:00 RBU   4.5% UBU   4.2%
409 builtin_dd: 11984*2KB out @ average 0.2x4390KBps
410 /dev/sr0: flushing cache
411 \end{lstlisting}
412
413 \section{Debugging DVDs Creation}%
414 \label{sec:debugging_dvd_creation}
415 \index{DVD!debugging}
416 \index{BluRay!debugging}
417
418 This section contains helpful hints, how to initially check the results, and some information on determining what might have gone wrong and how to address it.
419
420 \begin{enumerate}
421     \item For first time users, taking the defaults seem to work very well when running as root.
422     \item You may want to use rewritable media to see how it goes before using permanent media.
423     \item Until you are familiar with the procedure, start with shorter input in order not to waste time.
424     \item Test the generated output with a compatible media rendering tool before burning DVDs.
425     \item Check the list of files and file sizes after the batch jobs are complete before burning DVDs.
426 \end{enumerate}
427
428 For blu-ray creation, \texttt{cd /workpath/bd\_date-time} directory and look for similar files:
429
430 \texttt{bd.jobs \quad   bd.m2ts \quad   bd.sh   \quad   bd.udfs \quad    bd.xml}
431
432 \texttt{udfs} directory which is used as a loopback mount point
433
434 Note that the size of \textit{bd.udfs} should be larger than \texttt{bd.m2ts} because this is the final file which is actually going to be written to the disc media. It contains contents of \texttt{bd.m2ts} and all of the required disc structure.
435
436 For DVD creation, \texttt{cd /workpath/dvd\_date-time} directory and look for similar files:
437
438 \texttt{dvd.ac3 \quad   dvd.jobs \quad  dvd.m2v \quad dvd.mpg \quad     dvd.sh  \quad   dvd.xml}\\
439 \texttt{iso} directory with VIDEO\_TS and AUDIO\_TS subdirectories of non-zero size.
440
441 Note that there will be no files in the actual AUDIO\_TS directory.
442
443 \begin{enumerate}[start=6]
444     \item The \texttt{bd.sh} and \texttt{dvd.sh} files are script files that you can carefully run manually from some start point to determine where the failure occurred.  You must BE CAREFUL and know what you are doing and what directory you are in because dvd.sh contains an \texttt{rm} command and will delete files.  The script takes a command line parameter of the directory where the file was rendered to and which is usually the directory where dvd.sh or bd.sh was created.
445     \item There is also a file in the same directory, called bd.jobs.  It was the information that was used in creating the batch jobs and may be helpful in determining what parameters were actually used if there are any resulting problems.  With enough background knowledge, you can make changes and rerun.
446     \item For blu-ray check to make sure you do not have any spurious loopback disks mounted that may interfere with the correct generation.  Use the df command to check this and then the umount command to unmount these.  Also, check to make sure you have used the gsettings command to disable automount.
447     \item For blu-ray loopback mount the \texttt{<target>/bd.udfs} image, and see if it has the BDMV filesystem written to it, and in particular a subdirectory named STREAM.  Look at the results in \texttt{./udfs} and check for  the stream file which should exist in \texttt{./udfs/BDMV/STREAM/00000.m2ts} and should have the same size as \texttt{./bd.m2ts}.
448     \begin{lstlisting}[style=sh]
449     mount -o loop <target>/bd.udfs <target>/udfs
450     ls -lR <target>/udfs
451     du -sc <target>/udfs
452     umount <target>/udfs
453     \end{lstlisting}
454 \end{enumerate}
455
456 \subsubsection*{Checklist for Troubleshooting}
457 \label{ssub:checklist_troubleshooting}
458 \index{DVD!troubleshooting}
459 \index{BluRay!troubleshooting}
460
461 \begin{itemize}
462     \item Are you logged in as root?  This is required in order to loopback mount files for bluray and to write media on \texttt{/dev/hardware}.  See section \hyperref[sec:bluray_workaround_mount_umount]{13.7} for a workaround for normal user mode.
463     \item Did you startup \CGG{} from a terminal window so you can see informative messages?
464     \item Is udftools installed for BD and dvdauthor installed for SD?
465     \item Do you have loopback not enabled for bluray?  At least temporarily, disable automount via:
466     \begin{lstlisting}[style=sh]
467     gsettings set org.gnome.desktop.media-handling automount false
468     \end{lstlisting}
469     \item Did you have sufficient disk space for working/writing files?  In the \textit{Create} window, the \textit{disk space} will be displayed in green if sufficient, but in red if less than what fits on the disc media.
470     \item Did you use \texttt{/tmp} as the work device, then rebooted the computer, which deleted files on \texttt{/tmp}?
471     \item If the input media is interlaced, did you check the Deinterlace option to eliminate interlacing?
472     \item Did you change the output name in the \textit{Batch Render} window after the batch jobs were already created? These filenames have already been written to disk. If you want to change either the Title or the \textit{Work\_path}, you have to start over.
473     \item Have you selected a Title in the Create window that is a directory that already exists? The program attempts to create that directory and will give you an error message if it exists.
474     \item Did you replace the \texttt{/dev/bd} or \texttt{/dev/dvd} on the command line with your hardware device name?
475     \item If a warning was issued in the Create BD/SD window of \textit{* non-standard format} and your bluray reader could not play the disc, did you change to a standard format instead?
476     \item Did you correctly interpret the frame rate if using interlaced format to be $\frac{1}{2}$ due to interlacing?
477 \end{itemize}
478
479 \section{DVD-Subtitles}%
480 \label{sec:dvd_subtitles}
481 \index{DVD!subtitles}
482
483 \CGG{} supports the .udvd format of DVDs, so you can create subtitles on the timeline and then save them as .udvd files.
484 For how the subtitle tool works see: \nameref{sec:subtitles}
485 The subtitle format for Blu-Ray is PGS with a .sup extension which CinGG does not support. It is an image format (also 3D) so it can be created, converted and extracted only via specific OCR. You can use external programs like ffmpeg; SubTitle Editor; MKVToolNix; etc.
486
487 \section{Dvd Interlaced Chroma}%
488 \label{sec:dvd_interlaced_chroma}
489 \index{DVD!yuv420p interlace mode}
490
491 \CGG{} uses 4:4:4 colorspace to edit, so it is necessary to convert interlaced 4:2:0 video to 4:4:4.
492 But you can run into problems, referred to as the \textit{chroma bug}, which you see in DVD media displayed on higher resolution monitors -- streaks or spiky horizontal lines are visible in the chroma channel, especially on diagonal edges. The Chroma Bug is specific to MPEG and 4:2:0 encoding.
493
494 Now you can use the \textit{YUV420P DVD Interlace Mode} when rendering DV directly to mpeg2 through a yuv4mpeg stream and when using video effects on HDV video.
495
496 With this option enabled, improved chroma results will be obtained from your DV or HDV source.
497 Editing DV or HDV and rendering it back to the same format does not require any special handling.
498 In order to perform colorspace conversions correctly in \CGG{} and avoid Chroma errors for interlaced 4:2:0 video, check the box as follows:
499
500 \texttt{Settings $\rightarrow$ Preferences, Interface tab, Operation section, Use yuv420p dvd interlace format}
501
502 This option maintains the interlacing in Chroma sample addressing, which ordinarily would be deleted
503 because the upsampling of interlaced chroma fields is normally done using a progressive algorithm.
504 With this mode enabled, the MPEG decoder uses a different algorithm for interlaced frames so that the
505 4:2:0 format chroma interlacing is preserved.
506
507 \section{DVD with LPCM or MP2 audio}%
508 \label{sec:dvd_lpcm_audio}
509
510 By default, the audio when creating a DVD is always \textit{AC3}. However you can switch to \textit{PCM} (Pulse Code Modulator) or MP2 with just a few additional steps as outlined below.
511 Note that Audio must be $48Khz$ or $96Khz$, nothing else is supported, even by ffmpeg's dvd pcm encoder.
512
513 \begin{enumerate}
514         \item Start \CGG{} from a terminal window so you will be able to see what is happening. Only the final step when you actually want to write to a
515 DVD media writer, requires privileges of either root or the system has
516 granted the user this privilege.
517         \item Make sure you have your video with audio loaded and edited to your satisfaction and you are positioned at the start of the video.
518         \item Use the \texttt{File} pulldown and select the \textit{DVD Render} option.
519         \item In the\textit{Create DVD} window, accept the defaults or select different values and then click \texttt{OK}.  Do not check "Use FFMPEG" as that may not work.
520         \item When the \textit{Batch Render} window pops up, in the big box towards the bottom will be 2 lines with the first line for \textit{Video} already highlighted.  Instead, click on the second line, which is for \textit{Audio}, so that it is highlighted.
521         \item On the top left, you will see the \textit{File Format} set as AC3.  Use the down arrow next to    the box and change it to \textit{Raw PCM} or \textit{MPEG Audio} by clicking on it.
522         \item When you switch to Raw PCM or MPEG Audio, you see the extension in the \texttt{Output path} above change to pcm or mp3
523         instead of ac3.  Now just reset the extension from pcm to lpcm or mp2 as that is required. In most cases if you click on the \texttt{Audio} wrench to see the settings, you will find that the standard settings of 16 bit Linear / Signed / Hi Lo work for Raw PCM.  For mp2, you will have to click
524 on the Audio wrench and change the default Layer III to Layer II.
525         \item Now click on the \texttt{Start} box in the bottom left hand corner and \CGG{}     will process what it can of the job and put you back at your terminal startup window.
526         \item You will see a few lines of output, some of which are shown below, to include the ERROR:
527         \begin{lstlisting}[style=sh]
528                 running /dev/shm//dvd_20240116-182336/dvd.sh
529                 INFO: [mplex] mplex version 2.1.0 (2.2.7 $Date: 2012/11/17 01:55:16 $)
530                 **ERROR: [mplex] Unable to open file
531                 /dev/shm/dvd_20240116-182336/dvd.ac3 for reading.
532         \end{lstlisting}
533         \item Change directory to the location as shown on the terminal window of \texttt{dvd.sh}.
534         \item Using an editor, modify the line in dvd.sh to change \texttt{dvd.ac3} to \texttt{dvd.lpcm} or to \texttt{dvd.mp2} for mp2.  In addition ONLY for Raw PCM you have to change the mplex parameter to include:
535         \begin{lstlisting}[style=sh]
536                 -L  48000:2:16
537         \end{lstlisting}
538         The full line will look like this:
539         \begin{lstlisting}[style=sh]
540                 mplex -f 8 -L 48000:2:16 -o $dir/dvd.mpg $dir/dvd.m2v $dir/dvd.lpcm
541         \end{lstlisting}
542         \item Now the script is ready to run in the same manner it would have had it been ac3. That is just run via:
543         \begin{lstlisting}[style=sh]
544                 ./dvd.sh
545         \end{lstlisting}
546         \item Check to make sure there are no errors in the output shown on the window and proceed as usual.
547 \end{enumerate}
548
549
550 \section{MPEG utility programs}%
551 \label{sec:mpeg_utility_programs}
552
553 There are 2 utility programs that come in handy when dealing with DVD media for creating or reading previously written DVDs.
554
555 \paragraph{zmpeg3cc2txt} convert closed captioning data to subtitle data.
556
557 This program can be used to scan captured broadcast data streams and convert the closed captioning text data into subtitle track data.  The result can be used to add subtitles to DVDs created from the captured media using the text collected from the closed captioning.
558
559 usage:
560
561 \begin{lstlisting}[style=sh]
562 ./zmpeg3cc2txt  [-c cc_service ]  [-s start:length, ...]  [ -t track ]  [-v verbose ] [-w wdw mask ]  [-x file.xml ]  [-o file.udvd ]  file.ts
563 \end{lstlisting}
564
565 \begin{center}
566         \begin{tabular}{lcl}
567     cc\_service&=&closed caption service id\\
568     
569     start:length&=&start:length frames (comma separated list)\\
570     
571     track&=&video track number\\
572     
573     verbose&=&verbose level\\
574     
575     wdw mask&=&bit mask for windows (-1 = all)\\
576     
577     file.xml&=&filename for edl xml format subtitle data\\
578     
579     file.udvd&=&filename for udvd format subtitle data\\
580     
581     file.ts&=&filename for transport stream\\    
582 \end{tabular}
583 \end{center}
584
585 To use this program, the input file must be a transport stream (broadcast video) which contains closed captioning services.  The service id defaults to one, and the default video track is zero.  Either \texttt{-o} or \texttt{-x} must be specified to indicate the output file format desired.  If the output file name is a '-' then stdout is selected as the output file. 
586 For example:
587
588 \begin{lstlisting}[style=sh]
589 zmpeg3cc2txt -o - /dvb_data/channel5.ts
590 \end{lstlisting}
591
592 \paragraph{zmpeg3ifochk} check DVD \texttt{ifo} file for usable features.
593
594 For some time, DVD manufacturers have been employing  a variety of measures to make reading a DVD difficult on a computer.  One technique which is widely deployed is to add a bunch of extra program data, so that correct playback is only likely if you can read the DVD virtual machine data and decode a maze of program data to find the undamaged stream definitions.  Only a few streams are created which are machine usable, and dozens are created as decoy streams.  The decoy streams fail or introduce errors.  This program scans the IFO (info file) playlists and verifies the contents of the stream that does not contain obvious damage.  The result is a list of program ids which can be entered into the playback preferences to select a program which qualifies.
595
596 \section{Creating Blu-ray Without Re-encoding}%
597 \label{sec:bluray_without_reencoding}
598 \index{BluRay!without re-encoding}
599 \index{BluRay!camcorders}
600 \index{BluRay!AVCHD}
601
602 If you have video that is already in Blu-ray format AND you do not want to use \CGG{} to do
603 any editing, you can create blu-ray video media using Cinelerra's \textit{bdwrite} program.  This
604 could be the case if you are working with media from a modern Digital Camcorder.  Camcorders
605 usually record in a legacy tape-based format or the current file-based format.  The most common
606 digital camcorder formats and whether or not they need to be re-encoded are:
607
608 \begin{itemize}
609         \item DV (1995) to SD-blu-ray video - process in \CGG{} using the File pulldown of
610 BD Render as previously described or use programs documented in their manuals to re-encode
611 video to mpeg2 and then re-encode DV LPCM audio to Blu-ray LPCM.
612         \item HDV (2004) to blu-ray video - process in \CGG{} using the File pulldown of
613 BD Render as previously described or use programs documented in their manuals to
614  copy mpeg2
615 video and then re-encode MP2 audio to Blu-ray LPCM or AC3.
616         \item AVCHD (2006-current) to blu-ray video; these are the types of videos that do
617 not have to be re-encoded if you do not want to edit anything.
618 \end{itemize}
619 For an explanation of the differences between HDV vs AVCHD see:
620   {\small \url{http://www.differencebetween.net/technology/difference-between-hdv-and-avchd}}
621
622 Besides digital camcorder file-based format of AVCHD, there are video files in MTS format
623 that are also candidates for burning to blu-ray video media without re-encoding.
624 An MTS file is a video file saved in the high-definition (HD) MPEG Transport Stream video format/H264, commonly called \textit{AVCHD}.  It contains HD video compatible with Blu-ray video disc format and is based on the MPEG-2 transport stream.   MTS files are often used by Sony, Panasonic, Canon and other HD camcorders.  Legal input for Video -- MPEG1VIDEO, MPEG2VIDEO, H264; Audio -- MP1, MP2, AC3, AC3PLUS, DTS, TRUHD.
625
626 For creating a blu-ray video disc, if you have these HD MPEG-2 media types that are in blu-ray video format, you can save the original quality of your work, rather than rendering it to another format.
627 Note that for older media or media which used MP1 or MP2 audio codecs which will not work on
628 blu-ray video discs, it may be necessary to first transcode the audio while leaving video intact.
629 An example of the transcode line to use if using ffmpeg version 5.1 or higher is shown next.
630 If using a lower ffmpeg version substitute ac3 for pcm\_bluray:
631
632 \begin{lstlisting}[numbers=none]
633 ffmpeg -i hdv -c:v copy -c:a pcm_bluray -mpegts_m2ts_mode 1 new_hdv.mts
634 \end{lstlisting}
635
636 Follow the next 2 sets of steps to create the  blu-ray video disc.
637 \begin{lstlisting}[style=sh]
638 du -sb /yourHDVfile.MTS         # Determine the size of your file in bytes.
639 blocks=((size-in-bytes/2048 + 4096))    # Convert bytes into blocks + a little more.
640 mkudffs -b 2048 /tmp/newfilename.udfs blocks    # Create a file with that \# of blocks + some extra.
641 mount -o loop /tmp/newfilename.udfs /mntX          # Use a mount point like mntX that is not in use.
642 \end{lstlisting}
643 In order to create the udfs file, you will need access to Cinelerra's \textit{bdwrite} program.
644 If you do not do your own build and compile, but use the AppImage instead, you will have to first
645 extract \textit{bdwrite} from the AppImage as described in the NOTE at \ref{sub:managing_appimage}.
646 \begin{lstlisting}[style=sh]
647 /<cinelerra_installed_path>/bin/bdwrite /mntX /tmp/yourHDVfile.MTS   # Substitute \CGG{} path.
648 umount /mntX                            # You must unmount the udfs filesystem
649 growisofs -Z /dev/bd=/tmp/newfilename.udfs   # Replace /dev/bd with your bluray hardware device.
650 OR  dd if=/tmp/newfilename.udfs of=/dev/bd bs=2048000   # if using rewritable blu-ray; replace bd.
651 \end{lstlisting}
652
653 \section{Blu-ray Workaround for Mount/Umount}%
654 \label{sec:bluray_workaround_mount_umount}
655
656 Creating BD images to be written to media requires usage of \textit{mount} and \textit{umount} which typically can only be done by the root user due to security.  If you want to avoid running \CGG{} as root, you can implement a workaround by adding a line in \texttt{/etc/fstab} (must be root to edit the file initially) and by creating a directory in your home area, called \textit{bluray}.  You only have to do this once unless you upgrade the Operating System and it wipes out the line in \texttt{/etc/fsta}b.  Now the \CGG{} program will automatically do the mount and umount for you each time you execute BD Render and you can run as an ordinary user.
657
658 The line to add to \texttt{/etc/fstab} will look something like the following, assuming your username is \textit{name} and your groupid may be \textit{users} or \textit{name}.  If you do an \texttt{ls -l} in your home directory, the $3^{rd}$ and $4^{th}$ fields shown will be your uid or name and gid or groupid which you must substitute in the line below.
659
660 \begin{lstlisting}[style=sh]
661 /home/name/image  /home/name/bluray  udf noauto,loop,rw,user,uid=name,gid=groupid 0 0
662 \end{lstlisting}
663
664 Also, be sure to do a \texttt{mkdir bluray} in your \texttt{/home/name} directory as this is a requirement (owned by you; uid=gid=name).  When the actual image to be written to disc media is created, it will first d any current \texttt{/home/name/image} file.  Warning – make sure you do not already have a file called \textit{image} that you want to save as it will be automatically deleted every time you initiate a BD Render.  So you will want to burn a bluray disc after \CGG{} creates the \textit{image} since it will written over on the next rendition.  The actual writing to your bluray burner (something like \texttt{/dev/sr0}) is done outside of \CGG{} at a terminal prompt and requires root privilege usually.  You can either use \textit{sudo} for 1 line or create user wheel group to get around this.
665
666 \section{Blu-ray from Multiple \CGG{} Output}%
667 \label{sec:bluray_multiple_cinelerra_output}
668 \index{BluRay!multiple output}
669
670 Writing prepared multiple \CGG{} output files, \texttt{bd.m2ts}, to a single bluray video disc is relatively easy to do but is not done automatically.  You can render all of the desired files via the Create BD menu, save each individual \texttt{bd.m2ts} file with a unique name, construct a Menu Title that reflects the contents of each of these files, then manually use a few commands to create a udfs file to be written to blu-ray video media. If using AppImage, you will have to first extract the \textit{bdwrite} program as explained in the NOTE at \ref{sub:managing_appimage}.  You can
671 use any other software program that works instead.
672
673 Usage of the final preparation taken from the bdwrite program comments:
674
675 \begin{lstlisting}[style=sh]
676 ./bdwrite <tgt_dir_path> <playlist-0> <sep> <playlistp1> <sep> ... <sep> <playlist-n>
677
678 <sep> == -<pgm_pid> | --<pgm_pid> | ---<pgm_pid>
679 <pgm_pid> may be empty string, or a numeric pgm_pid for current title clip
680 <pgm_pid> defaults to first pgm probed
681 <playlist-x> == <clip-0.m2ts> <clip-1.m2ts> ... <clip-n.m2ts>
682 \end{lstlisting}
683
684 One title is built for each playlist; playlist-0 is used as first-play item.  The separators (\texttt{<sep>} represented by the dash character) have unique roles.  The double “$--$” means stop after playing, and the triple “$---$” means pause.
685
686 For example:
687
688 \begin{lstlisting}[style=sh]
689 ./bdwrite /tmp/dir /path/menu_titles.m2ts --- /path/clip0.m2ts -- /path/clip1.m2ts -- /path/clip2.m2ts
690 \end{lstlisting}
691
692 The basic idea is to use playlist-0 as a menu or directions to use the bluray player remote control to select the desired Title and start the play, avoiding the need for a menu system.  Planning in advance to get the desired results is necessary.  The following steps provide an outline to get started.
693
694 \begin{enumerate}
695     \item Create all of the \texttt{bd.m2ts} files that you want to put on the Bluray.
696     \item Using \CGG{}, design your Title page using a few seconds of video and the \textit{Title} plugin.
697     \item Use BD Create to render your short Title video.
698     \item Next is the most complicated part which is to run \texttt{mkudffs} with a sufficient amount of disk space to hold all of the \texttt{bd.m2ts} files \textit{plus a little more!}  To calculate this, you can record the sizes from having run BD Create mkudffs.  This number is displayed on the terminal screen when using the command line interface each time and add them together.  Or recalculate the size of each \texttt{bd.m2ts} using the formula below and adding them all together.  This is the number of blocks used to make a bluray image space for bdwrite to use.  For many files, this could require a huge amount of space, so check first.
699     \begin{lstlisting}[style=sh]
700     Total size = File0 size in bytes / 2048 + 4094  "+"   File1 size in bytes / 2048 + 4094  "+" ...
701     \end{lstlisting}
702     Now create the image file via:   \texttt{mkudffs image <Total size>}  where image or udfs is the image name.
703     \item Loop mount the disk image (refer to Section \hyperref[sec:bluray_workaround_mount_umount]{13.7}).
704     \item Then actually write your multiple bd.m2ts type files onto the \textit{image} where \texttt{<cin\_path>} is the location of the \CGG{} binary \textit{bdwrite} file and \texttt{<path>} is your directory path.  Below is a single line that wrapped around with 4 Titles.
705     \begin{lstlisting}[style=sh]
706     <cin_path>/bin/bdwrite image /<path>menu_titles.m2ts --- /<path>/bd1.m2ts -- /<path>/bd2.m2ts -- /<path>/bd3.m2ts -- /<path>bd4.m2ts
707     \end{lstlisting}
708     Note that the 3 dashes after the \texttt{menu\_titles.m2ts} lets the bluray player know to \textit{pause} after playing the few seconds video which contains the index to the rest of the files.  The 2 dashes after each of the \texttt{bd.m2ts} signify \textit{stop}.  That is when you will have to use your remote to \textit{Search Titles} in order to play the next one you want to see.  In addition, if for some reason you just want to \textit{play all}, you will have to add another line to the Title menu as a choice and list all of the 4 files in a row at the end of your bdwrite line without any dashes in between.
709     \item Umount the loopback disk.
710     \item Use your favorite \textit{dd} or \textit{growisofs} tool to write to a formatted bluray disc.
711 \end{enumerate}
712
713 Figure~\ref{fig:dvd-title} demonstrates  an example of setting up a Title menu on a 5 second video.  There is a list of 4 menu title options that can be searched via remote control using the Title search option for your player.
714
715 \begin{figure}[htpb]
716     \centering
717     \includegraphics[width=0.9\linewidth]{dvd-title.png}
718     \caption{Title menu for DVD/BD}
719     \label{fig:dvd-title}
720 \end{figure}
721
722 \section{Use Case: DVD}%
723 \label{sec:use_case_dvd}
724
725 Example of Video Source with 4:3 Aspect Ratio, Being Transcribed to 16:9 and Creating a DVD to be Displayed on a Digital TV. Illustrated steps to take source input with 4:3 aspect ratio and convert to 16:9, with the bottom of the image being cropped in order to preserve top of video so nobody's head gets cut off are provided here.
726
727 \begin{enumerate}
728     \item In order to write to a DVD writer hardware device, you must be \textit{root}!!
729     \item Start \CGG{} to bring up the 4 usual screens with main track canvas in the lower left corner.
730     \item Load media via the pulldown \texttt{File $\rightarrow$ Load files}\dots by choosing the directory path with the desired file.
731     \item Bring up the \textit{Create DVD} window using \texttt{File $\rightarrow$ DVD Render}. 
732     \item Choose Format: PAL or NTSC with 16x9 aspect ratio for today's digital TV as in below screenshot. figure~\ref{fig:dvd-000}.
733 \end{enumerate}
734
735 \begin{figure}[htpb]
736     \centering
737     \includegraphics[width=0.7\linewidth]{dvd01.png}
738     \caption{Choose NTSC or PAL for DVD creation}
739     \label{fig:dvd-000}
740 \end{figure}
741
742 \begin{enumerate}[start=6]
743     \item Modify the \textit{Work path:} parameter to a disk that has sufficient disk space and you will see the
744     amount of disk space in green letters (\texttt{/tmp} is default, but is often deleted so may be a bad choice).
745     \item Note that in the following screenshot, Scale of \textit{Cropped} has been chosen (figure~\ref{fig:dvd03}).    
746 \end{enumerate}
747
748 \begin{figure}[htpb]
749     \centering
750     \includegraphics[width=0.8\linewidth]{dvd03.png}
751     \caption{Set Scale Ratio to Cropped}
752     \label{fig:dvd03}
753 \end{figure}
754
755 \begin{enumerate}[start=8]
756     \item Click the green checkmark on the bottom left side of the window to close it and proceed.
757     \item Now the \textit{Batch Render} window will appear along with the Scale Ratio brown-colored line below the video in the main track canvas as seen in the screenshot below. Note that in this screenshot the top right most corner of the shot displays the bottom portion of the Compositor window.
758     \item Next, right mouse click the gold-colored magnifying glass, which is on the right hand side of the brown-colored line. This will bring up the Scale Ratio window that you can see below.  Note in the Compositor window, the blue legs are only showing up to the knees.
759 \end{enumerate}
760
761 With the \textit{Scale Ratio} plugin you can manipulate your video so that it will look the way you want it on a different output Display device.  In this case we are going to create a DVD for playing on a Digital TV screen. 
762
763 In figure~\ref{fig:scaleratio}, the left side shows the Input Ratio, Width, and Height of input. The top right half shows desired output values.  In this particular case, the input was a YouTube video which was not quite $4:3$ aspect ratio.
764
765 \begin{figure}[htpb]
766     \centering
767     \includegraphics[width=0.6\linewidth]{scaleratio.png}
768     \caption{Scale Ratio plugin}
769     \label{fig:scaleratio1}
770 \end{figure}
771
772 Left and right sides of the bottom portion show the Source and the Destination X, Y, W, H values.  As you change the values on the left side, you can see how this will affect the output as you observe the results in the compositor window.  For example, as you change the values for SrcY in a \textit{cropped} Scale scenario, you see up/down movement.
773
774 Keep in mind that the monitor you are using is NOT the intended output display device -- your digital TV is, which most likely will have different looking aspect/pixels, etc.
775
776 \begin{enumerate}[start=11]
777     \item In order to \textit{crop} the bottom of the video in order to preserve all of the image on the top, modify the Src Y value on the bottom of  the left hand side in the Scale Ratio plugin.  Src Y which was $21$ has now been changed to $-18$.  You will see in the Compositor window how the bottom dark colored border is now gone so that none of the top portion which contains the Bunny's head will be chopped off. Compare figure~\ref{fig:dvd04} to figure~\ref{fig:dvd03} and note the Bunny's head.
778 \end{enumerate}
779
780 \begin{figure}[htpb]
781     \centering
782     \includegraphics[width=0.8\linewidth]{dvd04.png}
783     \caption{Better scale on compositor}
784     \label{fig:dvd04}
785 \end{figure}
786
787 \begin{enumerate}[start=12]
788     \item Click the \textit{Apply} box in the Scale Ratio window.
789     \item Click the \textit{Save to EDL Path} in the \textit{Batch Render} window for creating a DVD.  If you do NOT do this, you will get a Warning box as seen in figure~\ref{fig:dvd-batch05}, to remind you to Save because you have changed the EDL by modifying the scaling parameters in the Scale Ratio window.
790 \end{enumerate}
791
792 \begin{figure}[htpb]
793     \centering
794     \includegraphics[width=1.0\linewidth]{dvd-batch05.png}
795     \caption{Error in Batch Render}
796     \label{fig:dvd-batch05}
797 \end{figure}
798
799 \begin{enumerate}[start=13]
800     \item Next, make sure you have the Timeline set in the Main window at the beginning of where you want to start rendering.  Also, make sure the first line in the \textit{Batches to render} section is highlighted as you can see above by the blue highlighting.  Click on the \textit{Start} box in the Batch Render window and you will see the video playing in the Compositor window.
801     \item \CGG{} program will be stopped when done rendering; you will be at the terminal prompt where you will see it has printed out some informational messages (or errors if problems), the last 2 are:
802     \begin{lstlisting}[style=sh]
803     To burn dvd, load blank media and run:
804     growisofs -dvd-compat -Z /dev/dvd -dvd-video /mnt0/dvd_20161027-131723/iso
805     \end{lstlisting}
806     \item Load a blank or rewritable DVD into your DVD writer device, which will be similar to \texttt{/dev/dvd} as in the \textit{growisofs} line above -- something like \texttt{/dev/sr0} on your computer.
807     \item Keyin the \textit{growisofs} line, substituting your actual writer device name.  Again, you must be root.
808     \item When back at the terminal prompt, and if there are no errors, keyin \texttt{eject /dev/dvd} substituting.
809     \item Play it on your DVD player connected up to your Digital TV screen.
810 \end{enumerate}
811
812
813