Expand batch processing command

This commit is contained in:
kfrn 2016-10-31 21:00:56 +13:00
parent 2750448bea
commit cc972d94b6

View File

@ -671,17 +671,28 @@
<div class="modal-dialog modal-lg"> <div class="modal-dialog modal-lg">
<div class="modal-content"> <div class="modal-content">
<div class="well"> <div class="well">
<h3>Create Bash Script named “Rewrap-MXF.sh” to do Batch FFmpeg Processing</h3> <h3>Create Bash script to batch process with ffmpeg</h3>
<p><code>for f in *.MXF; do ffmpeg -i "$f" -map 0 -c copy "${f%.MXF}.mov"; done</code></p> <p>Bash scripts are plain texts files saved with a .sh extension. This entry explains how they work with the example of a bash script named “Rewrap-MXF.sh”, which rewraps .MXF files in a given directory to .MOV files.</p>
<p>Re-wrap <code>.MFX</code> files in a specified directory to <code>.mov</code> files by using this code within a <code>.sh</code> file. The shell script (.sh file) and all MXF files must be contained in the same directory, and the script must be run from the directory itself (cd ~/Desktop/MXF_file_directory). Execute <code>.sh</code> file with the command <code>sh Rewrap-MXF.sh</code></p> <p>“Rewrap-MXF.sh” contains the following text:</p>
<p><code>for file in *.MXF; do ffmpeg -i "$file" -map 0 -c copy "${file%.MXF}.mov"; done</code></p>
<dl> <dl>
<dt>-map 0</dt><dd>select all input streams to map to output</dd> <dt>for file in *.MXF</dt><dd>starts the loop, and states what the input files will be. Here, the ffmpeg command within the loop will be applied to all files with an extension of .MXF.<br/>
<dt>-c copy</dt><dd>enable stream copy. This will re-mux wihout re-encoding, so quality is preserved</dd> The word file is an arbitrary variable which will represent each .MXF file in turn as it is looped over.<br/>
Per Bash syntax, within the command this variable is referenced with a dollar sign, e.g. as $file</dd>
<dt>do ffmpeg -i "$file"</dt><dd>carry out the following ffmpeg command for each input file</dd>
<dt>-map 0</dt><dd>retain all streams</dd>
<dt>-c copy</dt><dd>enable stream copy (no re-encode)</dd>
<dt>"${file%.MXF}.mov";</dt><dd>retaining the original file name, set the output file wrapper as Quicktime (.mov)</dd>
<dt>done</dt><dd>complete; all items have been processed.</dd>
</dl> </dl>
<p><strong>Note</strong>: the shell script (.sh file) and all .MXF files to be processed must be contained within the same directory, and the script must be run from that directory.<br/>
Execute the .sh file with the command <code>sh Rewrap-MXF.sh</code>.</p>
<p>Modify the ffmpeg script as needed to perform different transcodes :)</p> <p>Modify the ffmpeg script as needed to perform different transcodes :)</p>
<p>The basic pattern will look similar to this:<br/>
<code>for item in *.ext; do ffmpeg -i $item <ffmpeg options> "${file%.ext}_suffix.ext"</code></p>
<p>e.g., if an input file is bestmovie002.avi, its output will be bestmovie002_suffix.avi.</p>
<p class="link"></p> <p class="link"></p>
</div> </div>
</div> </div>
</div> </div>
</div> </div>