<p>The main difference is small but significant: the <code>-i</code> flag is required for FFmpeg but not required for FFplay. Additionally, the FFmpeg script needs to have <code>-t 5</code> and <code>output.mkv</code> added to specify the length of time to record and the place to save the video.</p>
<pclass="link"></p>
</div>
@@ -113,16 +115,17 @@
<p>It is also possible to apply multiple filters to an input, which are sequenced together in the filtergraph. A chained set of filters is called a filter chain, and a filtergraph may include multiple filter chains. Filters in a filterchain are separated from each other by commas (<code>,</code>), and filterchains are separated from each other by semicolons (<code>;</code>). For example, take the <ahref="#inverse-telecine">inverse telecine</a> command:</p>
<p>Here we have a filtergraph including one filter chain, which is made up of three video filters.</p>
<p>It is often prudent to enclose your filtergraph in quotation marks; this means that you can use spaces within the filtergraph. Using the inverse telecine example again, the following filter commands are all valid and equivalent:
but <code>-vf fieldmatch, yadif, decimate</code> is not valid.</p>
<p>It is often prudent to enclose your filtergraph in quotation marks; this means that you can use spaces within the filtergraph. Using the inverse telecine example again, the following filter commands are all valid and equivalent:</p>
<p>but <code>-vf fieldmatch, yadif, decimate</code> is not valid.</p>
<p>The ordering of the filters is significant. Video filters are applied in the order given, with the output of one filter being passed along as the input to the next filter in the chain. In the example above, <code>fieldmatch</code> reconstructs the original frames from the inverse telecined video, <code>yadif</code> deinterlaces (this is a failsafe in case any combed frames remain, for example if the source mixes telecined and real interlaced content), and <code>decimate</code> deletes duplicated frames. Clearly, it is not possible to delete duplicated frames before those frames are reconstructed.</p>
<h4>Notes</h4>
<ul>
<li><code>-vf</code> is an alias for <code>-filter:v</code></li>
<li>If the command involves more than one input or output, you must use the flag <code>-filter_complex</code> instead of <code>-vf</code>.</li>
<li>Straight quotation marks ("like this") rather than curved quotation marks (“like this”) should be used.</li>
<p>This command takes an input file and transcodes it to H.264 with an .mp4 wrapper, keeping the audio the same codec as the original. The libx264 codec defaults to a “medium” preset for compression quality and a CRF of 23. CRF stands for constant rate factor and determines the quality and file size of the resulting H.264 video. A low CRF means high quality and large file size; a high CRF means the opposite.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <i>input_file</i></dt><dd>path, name and extension of the input file</dd>
<dt>-c:v libx264</dt><dd>tells FFmpeg to encode the video stream as H.264</dd>
<dt>-pix_fmt yuv420p</dt><dd>libx264 will use a chroma subsampling scheme that is the closest match to that of the input. This can result in Y′C<sub>B</sub>C<sub>R</sub> 4:2:0, 4:2:2, or 4:4:4 chroma subsampling. QuickTime and most other non-FFmpeg based players can’t decode H.264 files that are not 4:2:0. In order to allow the video to play in all players, you can specify 4:2:0 chroma subsampling.</dd>
<dt>-c:a copy</dt><dd>tells FFmpeg to copy the audio stream without re-encoding it</dd>
<dt>-c:a aac</dt><dd>encode audio as AAC.<br>
AAC is the codec most often used for audio streams within an .mp4 container.</dd>
<dt><i>output_file</i></dt><dd>path, name and extension of the output file</dd>
</dl>
<p>In order to use the same basic command to make a higher quality file, you can add some of these presets:</p>
<p>This command allows you to create an H.264 file from a DVD source that is not copy-protected.</p>
<p>Before encoding, you’ll need to establish which of the .VOB files on the DVD or .iso contain the content that you wish to encode. Inside the VIDEO_TS directory, you will see a series of files with names like VTS_01_0.VOB, VTS_01_1.VOB, etc. Some of the .VOB files will contain menus, special features, etc, so locate the ones that contain target content by playing them back in VLC.</p>
<dt>-crf 18</dt><dd>sets the constant rate factor to a visually lossless value. Libx264 defaults to a <ahref="https://trac.ffmpeg.org/wiki/Encode/H.264#crf"target="_blank">crf of 23</a>, considered medium quality; a smaller CRF value produces a larger and higher quality video.</dd>
<dt>-preset veryslow</dt><dd>A slower preset will result in better compression and therefore a higher-quality file. The default is <b>medium</b>; slower presets are <b>slow</b>, <b>slower</b>, and <b>veryslow</b>.</dd>
</dl>
<p>Bear in mind that by default, libx264 will only encode a single video stream and a single audio stream, picking the ‘best’ of the options available. To preserve all video and audio streams, add <b>-map</b> parameters:</p>
<p>This script allows you to generate two derivative audio files from a master while appending audio from a separate file (for example a copyright or institutional notice) to one of them.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
@@ -880,8 +885,8 @@
<divclass="well">
<h2id="join-trim">Join, trim, or excerpt a video</h2>
<!-- Join files together -->
<labelclass="recipe"for="join_files">Join (concatenate) two or more files into a single file</label>
<!-- Join files of the same type together -->
<labelclass="recipe"for="join_files">Join (concatenate) two or more files of the same type</label>
<inputtype="checkbox"id="join_files">
<divclass="hiding">
<h3>Join files together</h3>
@@ -905,7 +910,66 @@
<p>For more information, see the <ahref="https://trac.ffmpeg.org/wiki/Concatenate"target="_blank">FFmpeg wiki page on concatenating files</a>.</p>
<pclass="link"></p>
</div>
<!-- ends Join files together -->
<!-- ends Join files of the same type together -->
<!-- Join files of different types together -->
<labelclass="recipe"for="join_different_files">Join (concatenate) two or more files of different types</label>
<p>This command takes two or more files of the different file types and joins them together to make a single file.</p>
<p>The input files may differ in many respects - container, codec, chroma subsampling scheme, framerate, etc. However, the above command only works properly if the files to be combined have the same dimensions (e.g., 720x576). Also note that if the input files have different framerates, then the output file will be of variable framerate.</p>
<p>Some aspects of the input files will be normalised: for example, if an input file contains a video track and an audio track that do not have exactly the same duration, the shorter one will be padded. In the case of a shorter video track, the last frame will be repeated in order to cover the missing video; in the case of a shorter audio track, the audio stream will be padded with silence.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <i>input_1.ext</i></dt><dd>path, name and extension of the first input file</dd>
<dt>-i <i>input_2.ext</i></dt><dd>path, name and extension of the second input file</dd>
<dt>-filter_complex</dt><dd>states that a complex filtergraph will be used</dd>
<dt>"</dt><dd>quotation mark to start filtergraph</dd>
<dt>[0:v:0][0:a:0]</dt><dd>selects the first video stream and first audio stream from the first input.<br>
Each reference to a specific stream is enclosed in square brackets. In the first stream reference, <code>0:v:0</code>, the first zero refers to the first input file, <code>v</code> means video stream, and the second zero indicates that it is the <i>first</i> video stream in the file that should be selected. Likewise, <code>0:a:0</code> means the first audio stream in the first input file.<br>
As demonstrated above, ffmpeg uses zero-indexing: <code>0</code> means the first input/stream/etc, <code>1</code> means the second input/stream/etc, and <code>4</code> would mean the fifth input/stream/etc.</dd>
<dt>[1:v:0][1:a:0]</dt><dd>As described above, this means select the first video and audio streams from the second input file.</dd>
<dt>concat=</dt><dd>starts the <code>concat</code> filter</dd>
<dt>n=2</dt><dd>states that there are two input files</dd>
<dt>:</dt><dd>separator</dd>
<dt>v=1</dt><dd>sets the number of output video streams.<br>
Note that this must be equal to the number of video streams selected from each segment.</dd>
<dt>:</dt><dd>separator</dd>
<dt>a=1</dt><dd>sets the number of output audio streams.<br>
Note that this must be equal to the number of audio streams selected from each segment.</dd>
<dt>[video_out]</dt><dd>name of the concatenated output video stream. This is a variable name which you define, so you could call it something different, like “vOut”, “outv”, or “banana”.</dd>
<dt>[audio_out]</dt><dd>name of the concatenated output audio stream. Again, this is a variable name which you define.</dd>
<dt>"</dt><dd>quotation mark to end filtergraph</dd>
<dt>-map "[video_out]"</dt><dd>map the concatenated video stream into the output file by referencing the variable defined above</dd>
<dt>-map "[audio_out]"</dt><dd>map the concatenated audio stream into the output file by referencing the variable defined above</dd>
<dt><i>output_file</i></dt><dd>path, name and extension of the output file</dd>
</dl>
<p>If no characteristics of the output files are specified, ffmpeg will use the default encodings associated with the given output file type. To specify the characteristics of the output stream(s), add flags after each <code>-map "[out]"</code> part of the command.</p>
<p>For example, to ensure that the video stream of the output file is visually lossless H.264 with a 4:2:0 chroma subsampling scheme, the command above could be amended to include the following:<br>
<h4>Variation: concatenating files of different resolutions</h4>
<p>To concatenate files of different resolutions, you need to resize the videos to have matching resolutions prior to concatenation. The most basic way to do this is by using a scale filter and giving the dimensions of the file you wish to match:</p>
<p>(The Lanczos scaling algorithm is recommended, as it is slower but better than the default bilinear algorithm).</p>
<p>The rescaling should be applied just before the point where the streams to be used in the output file are listed. Select the stream you want to rescale, apply the filter, and assign that to a variable name (<code>rescaled_video</code> in the below example). Then you use this variable name in the list of streams to be concatenated.</p>
<p>However, this will only have the desired visual output if the inputs have the same aspect ratio. If you wish to concatenate an SD and an HD file, you will also wish to pillarbox the SD file while upscaling. (See the <ahref="https://amiaopensource.github.io/ffmprovisr/#SD_HD_2">Convert 4:3 to pillarboxed HD</a> command). The full command would look like this:</p>
<p>Here, the first input is an SD file which needs to be upscaled to match the second input, which is 1920x1080. The scale filter enlarges the SD input to the height of the HD frame, keeping the 4:3 aspect ratio; then, the video is pillarboxed within a 1920x1080 frame.</p>
<h4>Variation: concatenating files of different framerates</h4>
<p>If the input files have different framerates, then the output file may be of variable framerate. To explicitly obtain an output file of constant framerate, you may wish convert an input (or multiple inputs) to a different framerate prior to concatenation.</p>
<p>You can speed up or slow down a file using the <code>fps</code> and <code>atempo</code> filters (see also the <ahref="https://amiaopensource.github.io/ffmprovisr/#modify_speed">Modify speed</a> command).</p>
<p>Here's an example of the full command, in which input_1 is 30fps, input_2 is 25fps, and 25fps is the desired output speed.</p>
<p>Note that the <code>fps</code> filter will drop or repeat frames as necessary in order to achieve the desired frame rate - see the FFmpeg <ahref="https://ffmpeg.org/ffmpeg-filters.html#fps-1">fps docs</a> for more details.</p>
<p>For more information, see the <ahref="https://trac.ffmpeg.org/wiki/Concatenate#differentcodec"target="_blank">FFmpeg wiki page on concatenating files of different types</a>.</p>
<pclass="link"></p>
</div>
<!-- ends Join files of the different types together -->
<!-- Split file into segments -->
<labelclass="recipe"for="segment_file">Split one file into several smaller segments</label>
@@ -951,7 +1015,7 @@
<dt>-ss 00:02:00</dt><dd>sets in point at 00:02:00</dd>
<dt>-to 00:55:00</dt><dd>sets out point at 00:55:00</dd>
<dt>-c copy</dt><dd>use stream copy mode (no re-encoding)<br>
<dt>-map 0</dt><dd>tells FFmpeg to map all streams of the input to the output.</dd>
<dt>-map 0</dt><dd>tells FFmpeg to map all streams of the input to the output.<br>
<b>Note:</b> watch out when using <code>-ss</code> with <code>-c copy</code> if the source is encoded with an interframe codec (e.g., H.264). Since FFmpeg must split on i-frames, it will seek to the nearest i-frame to begin the stream copy.</dd>
<dt><i>output_file</i></dt><dd>path, name and extension of the output file</dd>
</dl>
@@ -1036,6 +1100,7 @@
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <i>input_file</i></dt><dd>path, name and extension of the input file</dd>
<dt>-c:v libx264</dt><dd>encodes video stream with libx264 (h264)</dd>
<dt>-filter:v</dt><dd>a video filter will be used</dd>
<dt>"</dt><dd>quotation mark to start filtergraph</dd>
<dt>yadif</dt><dd>deinterlacing filter (‘yet another deinterlacing filter’)<br>
By default, <ahref="https://ffmpeg.org/ffmpeg-filters.html#yadif-1"target="_blank">yadif</a> will output one frame for each frame. Outputting one frame for each <i>field</i> (thereby doubling the frame rate) with <code>yadif=1</code> may produce visually better results.</dd>
@@ -1071,7 +1136,7 @@
<dt>"</dt><dd>end of filtergraph</dd>
<dt><i>output file</i></dt><dd>path, name and extension of the output file</dd>
</dl>
<p><code>"yadif,format=yuv420p"</code> is an FFmpeg <ahref="https://trac.ffmpeg.org/wiki/FilteringGuide#FiltergraphChainFilterrelationship"target="_blank">filtergraph</a>. Here the filtergraph is made up of one filter chain, which is itself made up of the two filters (separated by the comma).<br>
<p><code>"yadif,format=yuv420p"</code> is an FFmpeg <ahref="https://trac.ffmpeg.org/wiki/FilteringGuide#FiltergraphChainFilterrelationship"target="_blank">filtergraph</a>. Here the filtergraph is made up of one filter chain, which is itself made up of the two filters (separated by the comma).<br>
The enclosing quote marks are necessary when you use spaces within the filtergraph, e.g. <code>-vf "yadif, format=yuv420p"</code>, and are included above as an example of good practice.</p>
<p><b>Note:</b> FFmpeg includes several deinterlacers apart from <ahref="https://ffmpeg.org/ffmpeg-filters.html#yadif-1"target="_blank">yadif</a>: <ahref="https://ffmpeg.org/ffmpeg-filters.html#bwdif"target="_blank">bwdif</a>, <ahref="https://ffmpeg.org/ffmpeg-filters.html#w3fdif"target="_blank">w3fdif</a>, <ahref="https://ffmpeg.org/ffmpeg-filters.html#kerndeint"target="_blank">kerndeint</a>, and <ahref="https://ffmpeg.org/ffmpeg-filters.html#nnedi"target="_blank">nnedi</a>.</p>
<p>For more H.264 encoding options, see the latter section of the <ahref="./index.html#transcode_h264">encode H.264 command</a>.</p>
@@ -2246,6 +2311,86 @@
</div>
<!-- ends View Subprogram info -->
</div>
<divclass="well">
<h2id="similar-tools">Similar tools: tips & tricks 🎩🐰</h2>
<divclass="well">
<p>This section introduces and explains the usage of some additional command line tools similar to FFmpeg for use in digital preservation workflows (and beyond!).</p>
<p>ImageMagick is a free and open-source software suite for displaying, converting, and editing raster image and vector image files.</p>
<p>It's official website can be found <ahref="https://www.imagemagick.org/script/index.php">here</a>.</p>
<p>Another great resource with lots of supplemental explanations of filters is available at <ahref="http://www.fmwconcepts.com/imagemagick/index.php">Fred's ImageMagick Scripts</a>.</p>
<p>Unlike many other command line tools, ImageMagick isn't summoned by calling its name. Rather, ImageMagick installs links to several more specific commands: <code>convert</code>, <code>montage</code>, and <code>mogrify</code>, to name a few.</p>
<pclass="link"></p>
</div>
<!-- End About ImageMagick -->
<!-- Resize to width -->
<labelclass="recipe"for="im_resize">Resizes image to specific pixel width</label>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.