-
Notifications
You must be signed in to change notification settings - Fork 66
/
index.html
2952 lines (2810 loc) · 237 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<title>ffmprovisr</title>
<meta name="viewport" content="text/html, width=device-width, initial-scale=1">
<meta charset="utf-8">
<link rel="stylesheet" href="css/css.css">
<link rel="icon" href="img/vhs.ico">
</head>
<body>
<div class="grid">
<div class="header">
<h1>➺ ffmprovisr ❥</h1>
</div>
<nav class="sidebar well">
<h2 class="heading">Table of Contents</h2>
<a href="#about"><div class="contents-list">About this resource</div></a>
<div id="toggle-expand-collapse-all" class="contents-list">Expand/collapse all recipes</div>
<a href="#basics"><div class="contents-list">FFmpeg basics</div></a>
<a href="#concepts"><div class="contents-list">Advanced FFmpeg concepts</div></a>
<a href="#rewrap"><div class="contents-list">Change container (rewrap)</div></a>
<a href="#transcode"><div class="contents-list">Change codec (transcode)</div></a>
<a href="#video-properties"><div class="contents-list">Change video properties</div></a>
<a href="#audio-files"><div class="contents-list">Change/view audio properties</div></a>
<a href="#join-trim"><div class="contents-list">Join/trim/create an excerpt</div></a>
<a href="#interlacing"><div class="contents-list">Work with interlaced video</div></a>
<a href="#overlay"><div class="contents-list">Overlay timecode or text on a video</div></a>
<a href="#create-images"><div class="contents-list">Create thumbnails or GIFs</div></a>
<a href="#create-video"><div class="contents-list">Create a video from image(s) and audio</div></a>
<a href="#filters-scopes"><div class="contents-list">Use filters or scopes</div></a>
<a href="#metadata"><div class="contents-list">View or strip metadata</div></a>
<a href="#preservation"><div class="contents-list">Preservation tasks</div></a>
<a href="#test-files"><div class="contents-list">Generate test files</div></a>
<a href="#ocr"><div class="contents-list">Use OCR</div></a>
<a href="#perceptual-similarity"><div class="contents-list">Compare similarity of videos</div></a>
<a href="#other"><div class="contents-list">Something else</div></a>
<a href="#similar-tools"><div class="contents-list">Similar tools: tips & tricks</div></a>
<a href="#cdda"><div class="contents-list">CDDA (Audio CD) Ripping Tools</div></a>
<a href="#imagemagick"><div class="contents-list">ImageMagick</div></a>
<a href="#flac-tool"><div class="contents-list">flac tool</div></a>
</nav>
<div class="content">
<div class="well">
<h2 class="heading" id="about">About ffmprovisr</h2>
<h3>Making FFmpeg Easier</h3>
<p>FFmpeg is a powerful tool for manipulating audiovisual files. Unfortunately, it also has a steep learning curve, especially for users unfamiliar with a command line interface. This app helps users through the command generation process so that more people can reap the benefits of FFmpeg.</p>
<p>Each button displays helpful information about how to perform a wide variety of tasks using FFmpeg. To use this site, click on the task you would like to perform. You will jump to a single command or a list of related commands. Click on a command description, and the site will display a sample command as well as an explanation of how that command works with a breakdown of each of its flags (or options).</p>
<p>This page does not have search functionality, but you can open all recipes (second option in the sidebar) and use your browser's search tool (often ctrl+f or cmd+f) to perform a keyword search through all recipes.</p>
<h3>Tutorials</h3>
<p>For FFmpeg basics, check out the program’s <a href="https://ffmpeg.org/" target="_blank">official website</a>.</p>
<p>For instructions on how to install FFmpeg on macOS, Linux, and Windows, refer to Reto Kromer’s <a href="https://avpres.net/FFmpeg/#ch1" target="_blank">installation instructions</a>.</p>
<p>For Bash and command line basics, try the <a href="https://learnpythonthehardway.org/book/appendixa.html" target="_blank">Command Line Crash Course</a>. For a little more context presented in an ffmprovisr style, try <a href="https://explainshell.com/" target="_blank">explainshell.com</a>!</p>
<h3>License</h3>
<p class="license">
<a href="https://creativecommons.org/licenses/by/4.0/" target="_blank"><img alt="Creative Commons License" src="img/cc.png"></a><br>
This work is licensed under a <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank">Creative Commons Attribution 4.0 International License</a>.
</p>
<h3>Sibling projects</h3>
<p><a href="https://dd388.github.io/crals/" target="_blank">Script Ahoy</a>: Community Resource for Archivists and Librarians Scripting</p>
<p><a href="https://datapraxis.github.io/sourcecaster/" target="_blank">The Sourcecaster</a>: an app that helps you use the command line to work through common challenges that come up when working with digital primary sources.</p>
<p><a href="https://pugetsoundandvision.github.io/micropops/" target="_blank">Micropops</a>: One liners and automation tools from Moving Image Preservation of Puget Sound</p>
<p><a href="https://amiaopensource.github.io/cable-bible/" target="_blank">Cable Bible</a>: A Guide to Cables and Connectors Used for Audiovisual Tech</p>
<p><a href="https://eaasi.gitlab.io/program_docs/qemu-qed/" target="_blank">QEMU QED</a>: instructions for using QEMU (Quick EMUlator), a command line application for computer emulation and virtualization</p>
<p><a href="https://amiaopensource.github.io/ffmpeg-artschool/" target="_blank">ffmpeg-artschool</a>: An AMIA workshop featuring scripts, exercises, and activities to make art using FFmpeg</p>
</div>
<div class="well">
<h2 id="basics">Learn about FFmpeg basics</h2>
<!-- Basic structure of an FFmpeg command -->
<label class="recipe" for="basic-structure">Basic structure of an FFmpeg command</label>
<input type="checkbox" id="basic-structure">
<div class="hiding">
<h5>Basic structure of an FFmpeg command</h5>
<p>At its basis, an FFmpeg command is relatively simple. After you have installed FFmpeg (see instructions <a href="https://avpres.net/FFmpeg/#ch1" target="_blank">here</a>), the program is invoked simply by typing <code>ffmpeg</code> at the command prompt.</p>
<p>Subsequently, each instruction that you supply to FFmpeg is actually a pair: a flag, which designates the <em>type</em> of action you want to carry out; and then the specifics of that action. Flags are always prepended with a hyphen.</p>
<p>For example, in the instruction <code>-i <em>input_file.ext</em></code>, the <code>-i</code> flag tells FFmpeg that you are supplying an input file, and <code>input_file.ext</code> states which file it is.</p>
<p>Likewise, in the instruction <code>-c:v prores</code>, the flag <code>-c:v</code> tells FFmpeg that you want to encode the video stream, and <code>prores</code> specifies which codec is to be used. (<code>-c:v</code> is shorthand for <code>-codec:v</code>/<code>-codec:video</code>).</p>
<p>A very basic FFmpeg command looks like this:</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file.ext</em></dt><dd>path and name of the input file</dd>
<dt><em>-flag some_action</em></dt><dd>tell FFmpeg to do something, by supplying a valid flag and action</dd>
<dt><em>output_file.ext</em></dt><dd>path and name of the output file.<br>
Because this is the last part of the command, the filename you type here does not have a flag designating it as the output file.</dd>
</dl>
<p class="link"></p>
</div>
<!-- End Basic structure of an FFmpeg command -->
<!-- Streaming vs. Saving -->
<label class="recipe" for="streaming-saving">Streaming vs. Saving</label>
<input type="checkbox" id="streaming-saving">
<div class="hiding">
<h5>Streaming vs. Saving</h5>
<p>FFplay allows you to stream created video and FFmpeg allows you to save video.</p>
<p>The following command creates and saves a 10-second video of SMPTE bars:</p>
<p><code>ffmpeg -f lavfi -i smptebars=size=640x480 -t 5 output_file</code></p>
<p>This command plays and streams SMPTE bars but does not save them on the computer:</p>
<p><code>ffplay -f lavfi smptebars=size=640x480</code></p>
<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>
<p class="link"></p>
</div>
<!-- End Streaming vs. Saving -->
</div>
<div class="well">
<h2 id="concepts">Learn about more advanced FFmpeg concepts</h2>
<!-- Loop usage explanation -->
<label class="recipe" for="batch-loop">Batch and Loop script usage</label>
<input type="checkbox" id="batch-loop">
<div class="hiding">
<h5>Batch and Loop script usage</h5>
<p><code>ffmpeg -nostdin -i <em>input_file</em> ...</code></p>
<p>One of the frequent uses of FFmpeg is to run batch commands within loops to, for example, generate access files for an entire collection at once.</p>
<p>When running an FFmpeg command within a loop it is often necessary to use the <code>-nostdin</code> flag prior to the input in order to ensure successful execution of the commands. This is needed to override FFmpeg's default behavior of enabling interaction on standard input which can result in errors as loop inputs are fed to the ongoing command.</p>
<p class="link"></p>
</div>
<!-- End loop usage explanation -->
<!-- Codec Defaults explanation -->
<label class="recipe" for="codec-defaults">Codec defaults</label>
<input type="checkbox" id="codec-defaults">
<div class="hiding">
<h5>Codec Defaults</h5>
<p>Unless specified, FFmpeg will automatically set codec choices and codec parameters based off of internal defaults. These defaults are applied based on the file type used in the output (for example <code>.mov</code> or <code>.wav</code>).</p>
<p>When creating or transcoding files with FFmpeg, it is important to consider codec settings for both audio and video, as the default options may not be desirable in your particular context. The following is a brief list of codec defaults for some common file types:</p>
<ul>
<li><code>.avi</code>: Audio Codec: mp3, Video Codec: mpeg4</li>
<li><code>.mkv</code>: Audio Codec: ac3, Video Codec: H.264</li>
<li><code>.mov</code>: Audio Codec: AAC, Video Codec: H.264</li>
<li><code>.mp4</code>: Audio Codec: AAC, Video Codec: H.264</li>
<li><code>.mpg</code>: Audio Codec: mp2, Video Codec: mpeg1video</li>
<li><code>.mxf</code>: Audio Codec: pcm_s16le, Video Codec: mpeg2video</li>
<li><code>.wav</code>: Audio Codec: pcm_s16le (16 bit PCM)</li>
</ul>
<p class="link"></p>
</div>
<!-- End Codec Defaults -->
<!-- Filtergraph explanation -->
<label class="recipe" for="filtergraphs">Filtergraphs</label>
<input type="checkbox" id="filtergraphs">
<div class="hiding">
<h5>Filtergraphs</h5>
<p>Many FFmpeg commands use filters that manipulate the video or audio stream in some way: for example, <a href="https://ffmpeg.org/ffmpeg-filters.html#hflip" target="_blank">hflip</a> to horizontally flip a video, or <a href="https://ffmpeg.org/ffmpeg-filters.html#amerge-1" target="_blank">amerge</a> to merge two or more audio tracks into a single stream.</p>
<p>The use of a filter is signaled by the flag <code>-vf</code> (video filter) or <code>-af</code> (audio filter), followed by the name and options of the filter itself. For example, take the <a href="#convert-colorspace">convert colorspace</a> command:</p>
<p><code>ffmpeg -i <em>input_file</em> -c:v libx264 -vf colormatrix=<em>src</em>:<em>dst</em> <em>output_file</em></code>
<p>Here, <a href="https://ffmpeg.org/ffmpeg-filters.html#colormatrix" target="_blank">colormatrix</a> is the filter used, with <em>src</em> and <em>dst</em> representing the source and destination colorspaces. This part following the <code>-vf</code> is a <strong>filtergraph</strong>.</p>
<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 <a href="#inverse-telecine">inverse telecine</a> command:</p>
<p><code>ffmpeg -i <em>input_file</em> -c:v libx264 -vf "fieldmatch,yadif,decimate" <em>output_file</em></code></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:</p>
<ul>
<li><code>-vf fieldmatch,yadif,decimate</code></li>
<li><code>-vf "fieldmatch,yadif,decimate"</code></li>
<li><code>-vf "fieldmatch, yadif, decimate"</code></li>
</ul>
<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>
</ul>
<p>For more information, check out the FFmpeg wiki <a href="https://trac.ffmpeg.org/wiki/FilteringGuide" target="_blank">Filtering Guide</a>.</p>
<p class="link"></p>
</div>
<!-- End Filtergraph explanation -->
<!-- Stream mapping explanation -->
<label class="recipe" for="stream-mapping">Stream mapping</label>
<input type="checkbox" id="stream-mapping">
<div class="hiding">
<h5>Stream mapping</h5>
<p>Stream mapping is the practice of defining which of the streams (e.g., video or audio tracks) present in an input file will be present in the output file. FFmpeg recognizes five stream types:</p>
<ul>
<li><code>a</code> - audio</li>
<li><code>v</code> - video</li>
<li><code>s</code> - subtitle</li>
<li><code>d</code> - data (including timecode tracks)</li>
<li><code>t</code> - attachment</li>
</ul>
<p>Mapping is achieved by use of the <code>-map</code> flag, followed by an action of the type <code>file_number:stream_type[:stream_number]</code>. Numbering is zero-indexed, and it's possible to map by stream type and/or overall stream order within the input file. For example:</p>
<ul>
<li><code>-map 0:v</code> means ‘take all video streams from the first input file’.</li>
<li><code>-map 0:3</code> means ‘take the fourth stream from the first input file’.</li>
<li><code>-map 0:a:2</code> means ‘take the third audio stream from the first input file’.</li>
<li><code>-map 0:0 -map 0:2</code> means ‘take the first and third streams from the first input file’.</li>
<li><code>-map 0:1 -map 1:0</code> means ‘take the second stream from the first input file and the first stream from the second input file’.</li>
</ul>
<p>When no mapping is specified in an ffmpeg command, the default for video files is to take just one video and one audio stream for the output: other stream types, such as timecode or subtitles, will not be copied to the output file by default. If multiple video or audio streams are present, the best quality one is automatically selected by FFmpeg.</p>
<p>To map <em>all</em> streams in the input file to the output file, use <code>-map 0</code>. However, note that not all container formats can include all stream types: for example, .mp4 cannot contain timecode.</p>
<h4>Mapping with a failsafe</h4>
<p>To safely process files that may or may not contain given a type of stream, you can add a trailing <code>?</code> to your map commands: for example, <code>-map 0:a?</code> instead of <code>-map 0:a</code>.</p>
<p>This makes the map optional: audio streams will be mapped over if they are present in the file—but if the file contains no audio streams, the transcode will proceed as usual, minus the audio stream mapping. Without adding the trailing <code>?</code>, FFmpeg will exit with an error on that file.</p>
<p>This is especially recommended when batch processing video files: it ensures that all files in your batch will be transcoded, whether or not they contain audio streams.</p>
<p>For more information, check out the FFmpeg wiki <a href="https://trac.ffmpeg.org/wiki/Map" target="_blank">Map</a> page, and the official FFmpeg <a href="https://ffmpeg.org/ffmpeg.html#Advanced-options" target="_blank">documentation on <code>-map</code></a>.</p>
<p class="link"></p>
</div>
<!-- End Stream Mapping explanation -->
</div>
<div class="well">
<h2 id="rewrap">Change container (rewrap)</h2>
<!-- Basic rewrap command -->
<label class="recipe" for="basic-rewrap">Basic rewrap command</label>
<input type="checkbox" id="basic-rewrap">
<div class="hiding">
<h5>Rewrap a file</h5>
<p><code>ffmpeg -i <em>input_file.ext</em> -c copy -map 0 <em>output_file.ext</em></code></p>
<p>This script will rewrap a video file. It will create a new video video file where the inner content (the video, audio, and subtitle data) of the original file is unchanged, but these streams are rehoused within a different container format.</p>
<p><strong>Note:</strong> rewrapping is also known as remuxing, short for re-multiplexing.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file.ext</em></dt><dd>path and name of the input file</dd>
<dt>-c copy</dt><dd>copy the streams directly, without re-encoding.</dd>
<dt>-map 0</dt><dd>map all streams of the input to the output.<br>
By default, FFmpeg will only map one stream of each type (video, audio, subtitles) to the output file. However, files may have multiple streams of a given type - for example, a video may have several audio tracks for different languages. Therefore, if you want to preserve all the streams in the original, it's necessary to use this option.</dd>
<dt><em>output_file.ext</em></dt><dd>path and name of the output file.<br>
The new container you are rewrapping to is defined by the filename extension used here, e.g. .mkv, .mp4, .mov.</dd>
</dl>
<h4>Important caveat</h4>
<p>It may not be possible to rewrap a file's contents to a new container without re-encoding one or more of the streams within (that is, the video, audio, and subtitle tracks). Some containers can only contain streams of a certain encoding type: for example, the .mp4 container does not support uncompressed audio tracks. (In practice .mp4 goes hand-in-hand with a H.264-encoded video stream and an AAC-encoded video stream, although other types of video and audio streams are possible). Another example is that the Matroska container does not allow data tracks.</p>
<p>In such cases, FFmpeg will throw an error. If you encounter errors of this kind, you may wish to consult the <a href="#transcode">list of transcoding recipes</a>.</p>
<p class="link"></p>
</div>
<!-- End Basic rewrap command -->
<!-- BWF -->
<label class="recipe" for="bwf">Convert to (or create) Broadcast WAV</label>
<input type="checkbox" id="bwf">
<div class="hiding">
<h5>Generate Broadcast WAV</h5>
<p><code>ffmpeg -i <em>input_file.wav</em> -c copy -write_bext 1 -metadata field_name='Content' <em>output_file.wav</em></code></p>
<p>This command will write a file in the Broadcast Wave Format (BWF) containing a BEXT chunk with related metadata.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file.wav</em></dt><dd>path and name of the input file</dd>
<dt>-c copy</dt><dd>this will copy the encoding/sample rate etc from the input. If not using a WAV as the input file you will have to specify codec settings in place of this.</dd>
<dt>-write_bext 1</dt><dd>tells FFmpeg to write a BEXT chunk, the part of the file where BWF metadata is stored.</dd>
<dt>-metadata field_name='Content'</dt><dd>This is where you can specify which BEXT fields to write, and what information to fill them with by replacing <code>field_name</code> and <code>'Content'</code> respectively. See below for additional details.</dd>
</dl>
<p>Notes: You can choose which fields to write by repeating <code>-metadata field_name='Content'</code> for each desired field. Flags for commonly used fields (such as those recommended by the <a href="http://www.digitizationguidelines.gov/audio-visual/documents/Embed_Guideline_20120423.pdf">FADGI guidelines</a>) are as follows:</p>
<ul>
<li>description</li>
<li>originator</li>
<li>originator_reference</li>
<li>origination_date</li>
<li>origination_time</li>
<li>coding_history</li>
<li>IARL</li>
</ul>
<p>Example: <code>-metadata originator='US, UW Libraries'</code></p>
<p>Additionally, users should be aware that BWF metadata fields are limited by characters, with some such as OriginatorReference maxing out at 32. Specific information can be found in the <a href="https://tech.ebu.ch/docs/tech/tech3285.pdf">Broadcast Wave Format specification</a>. Additional examples of BWF metadata usage can be found in the <a href="http://www.dlib.indiana.edu/projects/sounddirections/papersPresent/sd_bp_07.pdf">Sound Directions report</a> by Indiana University and Harvard.</p>
<p class="link"></p>
</div>
<!-- ends BWF -->
<!-- Rewrap DV -->
<label class="recipe" for="rewrap-dv">Rewrap DV video to .dv file</label>
<input type="checkbox" id="rewrap-dv">
<div class="hiding">
<h5>Rewrap DV video to .dv file</h5>
<p><code>ffmpeg -i <em>input_file</em> -f rawvideo -c:v copy <em>output_file.dv</em></code></p>
<p>This script will take a video that is encoded in the <a href="https://en.wikipedia.org/wiki/DV" target="_blank">DV Codec</a> but wrapped in a different container (such as MOV) and rewrap it into a raw DV file (with the .dv extension). Since DV files potentially contain a great deal of provenance metadata within the DV stream, it is necessary to rewrap files in this method to avoid unintentional stripping of this metadata.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path and name of the input file</dd>
<dt>-f rawvideo</dt><dd>this tells FFmpeg to pass the video stream as raw video data without remuxing. This step is what ensures the survival of embedded metadata versus a standard rewrap.</dd>
<dt>-c:v copy</dt><dd>copy the DV stream directly, without re-encoding.</dd>
<dt><em>output_file.dv</em></dt><dd>tells FFmpeg to use the DV wrapper for the output.</dd>
</dl>
<p class="link"></p>
</div>
<!-- Rewrap DV -->
</div>
<div class="well">
<h2 id="transcode">Change codec (transcode)</h2>
<!-- Transcode to ProRes -->
<label class="recipe" for="to_prores">Transcode to deinterlaced Apple ProRes LT</label>
<input type="checkbox" id="to_prores">
<div class="hiding">
<h5>Transcode into a deinterlaced Apple ProRes LT</h5>
<p><code>ffmpeg -i <em>input_file</em> -c:v prores -profile:v 1 -vf yadif -c:a pcm_s16le <em>output_file</em></code></p>
<p>This command transcodes an input file into a deinterlaced Apple ProRes 422 LT file with 16-bit linear PCM encoded audio. The file is deinterlaced using the yadif filter (Yet Another De-Interlacing Filter).</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-c:v prores</dt><dd>tells FFmpeg to transcode the video stream into Apple ProRes 422</dd>
<dt>-profile:v <em>1</em></dt><dd>Declares profile of ProRes you want to use. The profiles are explained below:
<ul>
<li>0 = ProRes 422 (Proxy)</li>
<li>1 = ProRes 422 (LT)</li>
<li>2 = ProRes 422 (Standard)</li>
<li>3 = ProRes 422 (HQ)</li>
</ul></dd>
<dt>-vf yadif</dt><dd>Runs a deinterlacing video filter (yet another deinterlacing filter) on the new file. <code>-vf</code> is an alias for <code>-filter:v</code>.</dd>
<dt>-c:a pcm_s16le</dt><dd>tells FFmpeg to encode the audio stream in 16-bit linear PCM</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output file<br>
There are currently three possible containers for ProRes 422 and 4444 which are all supported by FFmpeg: QuickTime (<code>.mov</code>), Matroska (<code>.mkv</code>) and Material eXchange Format (<code>.mxf</code>).</dd>
</dl>
<p>FFmpeg comes with more than one ProRes encoder:</p>
<ul>
<li><code>prores</code> is much faster, can be used for progressive video only, and seems to be better for video according to Rec. 601 (Recommendation ITU-R BT.601).</li>
<li><code>prores_ks</code> generates a better file, can also be used for interlaced video, allows also encoding of ProRes 4444 (<code>-c:v prores_ks -profile:v 4</code>) and ProRes 4444 XQ (<code>-c:v prores_ks -profile:v 5</code>), and seems to be better for video according to Rec. 709 (Recommendation ITU-R BT.709).</li>
</ul>
<p class="link"></p>
</div>
<!-- ends Transcode to ProRes -->
<!-- Transcode to H.264 -->
<label class="recipe" for="transcode_h264">Transcode to an H.264 access file</label>
<input type="checkbox" id="transcode_h264">
<div class="hiding">
<h5>Transcode to H.264</h5>
<p><code>ffmpeg -i <em>input_file</em> -c:v libx264 -pix_fmt yuv420p -c:a aac <em>output_file</em></code></p>
<p>This command takes an input file and transcodes it to H.264 with an .mp4 wrapper, audio is transcoded to AAC. 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 <em>input_file</em></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 aac</dt><dd>encode audio as AAC.<br>
AAC is the codec most often used for audio streams within an .mp4 container.</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<p>In order to optimize the file for streaming, you can add this preset:</p>
<p><code>ffmpeg -i <em>input_file</em> -c:v libx264 -pix_fmt yuv420p -c:a aac -movflags +faststart <em>output_file</em></code></p>
<dl>
<dt>-movflags +faststart</dt><dd>This tells FFmpeg to move some of the essential metadata to the start of the file, which permits starting viewing before the file finishes downloading (an ideal characteristic for streaming).</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><code>ffmpeg -i <em>input_file</em> -c:v libx264 -pix_fmt yuv420p -preset veryslow -crf 18 -c:a aac <em>output_file</em></code></p>
<dl>
<dt>-preset <em>veryslow</em></dt><dd>This option tells FFmpeg to use the slowest preset possible for the best compression quality.<br>
Available presets, from slowest to fastest, are: <code>veryslow</code>, <code>slower</code>, <code>slow</code>, <code>medium</code>, <code>fast</code>, <code>faster</code>, <code>veryfast</code>, <code>superfast</code>, <code>ultrafast</code>.</dd>
<dt>-crf <em>18</em></dt><dd>Specifying a lower CRF will make a larger file with better visual quality. For H.264 files being encoded with a 4:2:0 chroma subsampling scheme (i.e., using <code>-pix_fmt yuv420p</code>), the scale ranges between 0-51 for 8-bit content, with 0 being lossless and 51 the worst possible quality.<br>
If no crf is specified, <code>libx264</code> will use a default value of 23. 18 is often considered a “visually lossless” compression.</dd>
</dl>
<p>By default, this recipe will include one track of each type (e.g. audio, video) in the output file. If you wish to include more tracks, consult the <a href="#stream-mapping">entry on stream mapping</a>.</p>
<p>For more information, see the <a href="https://trac.ffmpeg.org/wiki/Encode/H.264" target="_blank">FFmpeg and H.264 Encoding Guide</a> on the FFmpeg wiki.</p>
<p class="link"></p>
</div>
<!-- ends Transcode to H.264 -->
<!-- Transcode to H.264 or H.265 using the GPU -->
<label class="recipe" for="transcode_gpu">Transcode to H.264/H.265 using the GPU</label>
<input type="checkbox" id="transcode_gpu">
<div class="hiding">
<h5>Transcode to H.264/H.265 using the GPU</h5>
<p><code>ffmpeg -i <em>input_file</em> -c:v h264_nvenc -preset llhq -rc:v vbr_hq -cq:v 19 -b:v 8000k -maxrate:v 12000k -profile:v high -c:a copy <em>output_file</em></code></p>
<p>This command takes an input file and transcodes it to H.264 using the encoding functionality of an Nvidia GPU (without transcoding the audio). If you're using H.264 with AAC or AC3 audio, you can output to an .mp4 file; if you're using HEVC and/or more exotic audio, you should output to .mkv. While Nvidia's fixed-function hardware can be 10x as performant as encoding on the CPU, it requires a few more parameters in order to optimize quality at lower bitrates.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-c:v <em>h264_nvenc</em></dt><dd>tells FFmpeg to encode the video stream as H.264 using Nvidia's encoder.</dd>
<dt>-preset <em>llhq</em></dt><dd>uses the "low latency, high quality" encoding preset, a good default when working with nvenc.</dd>
<dt>-rc:v <em>vbr_hq</em></dt><dd>means "variable bitrate, high quality," allowing you to set a minimum and maximum bitrate for the encode.</dd>
<dt>-cq:v <em>19</em></dt><dd>is the same as the CRF quality level specified using x264 or other CPU-based encoders, where 0 is lossless, 51 is the worst possible quality, and values from 18-23 are typical.</dd>
<dt>-b:v <em>8000k -maxrate:v 12000k</em></dt><dd>corresponds to a minimum bitrate of 8 megabits (8000k) per second, and a maximum of 12 megabits per second. nvenc is not as good at estimating bitrates as CPU-based encoders, and without this data, will occasionally choose a visibly lower bitrate. The 8-12 mbit range is generally a good one for high-quality 1080p h264.</dd>
<dt>-profile:v <em>high</em></dt><dd>uses the "high quality" profile of h264, something that's been baked in to the spec for a long time so that older players can declare compatibility; almost all h264 video now uses high.</dd>
<dt>-c:a <em>copy</em></dt><dd>will skip reencoding the audio stream, and copy the audio from the source file.</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<p>In order to encode to HEVC instead, and optionally transcode the audio, you can try changing the command like this:</p>
<p><code>ffmpeg -i <em>input_file</em> -c:v hevc_nvenc -preset llhq -rc:v vbr_hq -cq:v 19 -b:v 5000k -maxrate:v 8000k -profile:v main10 -c:a aac <em>output_file</em></code></p>
<dl>
<dt>-c:v <em>hevc_nvenc</em></dt><dd>encodes to HEVC (also called H.265), a more efficient codec supported on GPUs from approximately 2015 and newer.</dd>
<dt>-b:v <em>5000k -maxrate:v 8000k</em></dt><dd>specifies a slightly lower bitrate than when using h264, per HEVC's greater efficiency.</dd>
<dt>-profile:v <em>main10</em></dt><dd>declares the "main10" profile for working with HEVC; one of the primary advantages of this codec is better support for 10-bit video, enabling consumer HDR.</dd>
<dt>-c:a <em>aac</em></dt><dd>reencodes the audio to AAC with default parameters, a very common and widely supported format for access copies.</dd>
</dl>
<p>Much of the information in this entry was taken from <a href="https://superuser.com/a/1236387" target="_blank">this superuser.com post</a> provided by an Nvidia developer, one of the best sources of information on the ffmpeg Nvidia encoders.</p>
<p class="link"></p>
</div>
<!-- ends Transcode to H.264 or H.265 using the GPU -->
<!-- H.264 from DCP -->
<label class="recipe" for="dcp_to_h264">Transcode from DCP to an H.264 access file</label>
<input type="checkbox" id="dcp_to_h264">
<div class="hiding">
<h5>H.264 from DCP</h5>
<p><code>ffmpeg -i <em>input_video_file</em>.mxf -i <em>input_audio_file</em>.mxf -c:v libx264 -pix_fmt yuv420p -c:a aac <em>output_file.mp4</em></code></p>
<p>This will transcode MXF wrapped video and audio files to an H.264 encoded MP4 file. Please note this only works for unencrypted, single reel DCPs.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_video_file</em></dt><dd>path and name of the video input file. This extension must be <code>.mxf</code></dd>
<dt>-i <em>input_audio_file</em></dt><dd>path and name of the audio input file. This extension must be <code>.mxf</code></dd>
<dt>-c:v libx264</dt><dd>transcodes video to H.264</dd>
<dt>-pix_fmt yuv420p</dt><dd>sets pixel format to yuv420p for greater compatibility with media players</dd>
<dt>-c:a aac</dt><dd>re-encodes using the AAC audio codec<br>
Note that sadly MP4 cannot contain sound encoded by a PCM (Pulse-Code Modulation) audio codec</dd>
<dt><em>output_file.mp4</em></dt><dd>path, name and .mp4 extension of the output file</dd>
</dl>
<p>Variation: Copy PCM audio streams by using Matroska instead of the MP4 container</p>
<p><code>ffmpeg -i <em>input_video_file</em>.mxf -i <em>input_audio_file</em>.mxf -c:v libx264 -pix_fmt yuv420p -c:a copy <em>output_file.mkv</em></code></p>
<dl>
<dt>-c:a copy</dt><dd>re-encodes using the same audio codec</dd>
<dt><em>output_file.mkv</em></dt><dd>path, name and .mkv extension of the output file</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends H.264 from DCP -->
<!-- Transcode to FFV1.mkv -->
<label class="recipe" for="create_FFV1_mkv">Transcode your file with the FFV1 Version 3 Codec in a Matroska container</label>
<input type="checkbox" id="create_FFV1_mkv">
<div class="hiding">
<h5>Create FFV1 Version 3 video in a Matroska container with framemd5 of input</h5>
<p><code>ffmpeg -i <em>input_file</em> -map 0 -dn -c:v ffv1 -level 3 -g 1 -slicecrc 1 -slices 16 -c:a copy <em>output_file</em>.mkv -f framemd5 -an <em>framemd5_output_file</em></code></p>
<p>This will losslessly transcode your video with the FFV1 Version 3 codec in a Matroska container. In order to verify losslessness, a framemd5 of the source video is also generated. For more information on FFV1 encoding, <a href="https://trac.ffmpeg.org/wiki/Encode/FFV1" target="_blank">try the FFmpeg wiki</a>.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command.</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file.</dd>
<dt>-map 0</dt><dd>Map all streams that are present in the input file. This is important as FFmpeg will map only one stream of each type (video, audio, subtitles) by default to the output video.</dd>
<dt>-dn</dt><dd>ignore data streams (data no). The Matroska container does not allow data tracks.</dd>
<dt>-c:v ffv1</dt><dd>specifies the FFV1 video codec.</dd>
<dt>-level 3</dt><dd>specifies Version 3 of the FFV1 codec.</dd>
<dt>-g 1</dt><dd>specifies intra-frame encoding, or GOP=1.</dd>
<dt>-slicecrc 1</dt><dd>Adds CRC information for each slice. This makes it possible for a decoder to detect errors in the bitstream, rather than blindly decoding a broken slice. (Read more <a href="http://ndsr.nycdigital.org/diving-in-head-first/" target="_blank">here</a>).</dd>
<dt>-slices 16</dt><dd>Each frame is split into 16 slices. 16 is a good trade-off between filesize and encoding time.</dd>
<dt>-c:a copy</dt><dd>copies all mapped audio streams.</dd>
<dt><em>output_file</em>.mkv</dt><dd>path and name of the output file. Use the <code>.mkv</code> extension to save your file in a Matroska container.</dd>
<dt>-f framemd5</dt><dd>Decodes video with the framemd5 muxer in order to generate MD5 checksums for every frame of your input file. This allows you to verify losslessness when compared against the framemd5s of the output file.</dd>
<dt>-an</dt><dd>ignores the audio stream when creating framemd5 (audio no)</dd>
<dt><em>framemd5_output_file</em></dt><dd>path, name and extension of the framemd5 file.</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends Transcode to FFV1.mkv-->
<!-- Rip DVD -->
<label class="recipe" for="dvd_to_file">Convert DVD to H.264</label>
<input type="checkbox" id="dvd_to_file">
<div class="hiding">
<h5>Convert DVD to H.264</h5>
<p><code>ffmpeg -i concat:<em>input_file_1</em>\|<em>input_file_2</em>\|<em>input_file_3</em> -c:v libx264 -c:a aac <em>output_file</em>.mp4</code></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>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i concat:<em>input files</em></dt><dd>lists the input VOB files and directs FFmpeg to concatenate them. Each input file should be separated by a backslash and a pipe, like so:<br>
<code>-i concat:VTS_01_1.VOB\|VTS_01_2.VOB\|VTS_01_3.VOB</code><br>
The backslash is simply an escape character for the pipe (<strong>|</strong>).</dd>
<dt>-c:v libx264</dt><dd>sets the video codec as H.264</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><em>output_file.mp4</em></dt><dd>path and name of the output file</dd>
</dl>
<p>It’s also possible to adjust the quality of your output by setting the <strong>-crf</strong> and <strong>-preset</strong> values:</p>
<p><code>ffmpeg -i concat:<em>input_file_1</em>\|<em>input_file_2</em>\|<em>input_file_3</em> -c:v libx264 -crf 18 -preset veryslow -c:a aac <em>output_file</em>.mp4</code></p>
<dl>
<dt>-crf 18</dt><dd>sets the constant rate factor to a visually lossless value. Libx264 defaults to a <a href="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 <strong>medium</strong>; slower presets are <strong>slow</strong>, <strong>slower</strong>, and <strong>veryslow</strong>.</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 <strong>-map</strong> parameters:</p>
<p><code>ffmpeg -i concat:<em>input_file_1</em>\|<em>input_file_2</em> -map 0:v -map 0:a -c:v libx264 -c:a aac <em>output_file</em>.mp4</code></p>
<dl>
<dt>-map 0:v</dt><dd>encodes all video streams</dd>
<dt>-map 0:a</dt><dd>encodes all audio streams</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends rip DVD -->
<!-- Transcode to H.265 -->
<label class="recipe" for="transcode_h265">Transcode to an H.265/HEVC MP4</label>
<input type="checkbox" id="transcode_h265">
<div class="hiding">
<h5>Transcode to H.265/HEVC</h5>
<p><code>ffmpeg -i <em>input_file</em> -c:v libx265 -pix_fmt yuv420p -c:a copy <em>output_file</em></code></p>
<p>This command takes an input file and transcodes it to H.265/HEVC in an .mp4 wrapper, keeping the audio codec the same as in the original file.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-c:v libx265</dt><dd>tells FFmpeg to encode the video as H.265</dd>
<dt>-pix_fmt yuv420p</dt><dd>libx265 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. For widest accessibility, it’s a good idea to specify 4:2:0 chroma subsampling.</dd>
<dt>-c:a copy</dt><dd>tells FFmpeg not to change the audio codec</dd>
<dt><em>output file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<p>The libx265 encoding library defaults to a ‘medium’ preset for compression quality and a CRF of 28. CRF stands for ‘constant rate factor’ and determines the quality and file size of the resulting H.265 video. The CRF scale ranges from 0 (best quality [lossless]; largest file size) to 51 (worst quality; smallest file size).</p>
<p>A CRF of 28 for H.265 can be considered a medium setting, <a href="https://trac.ffmpeg.org/wiki/Encode/H.265#ConstantRateFactorCRF" target="_blank">corresponding</a> to a CRF of 23 in <a href="#transcode_h264">encoding H.264</a>, but should result in about half the file size.</p>
<p>To create a higher quality file, you can add these presets:</p>
<p><code>ffmpeg -i <em>input_file</em> -c:v libx265 -pix_fmt yuv420p -preset veryslow -crf 18 -c:a copy <em>output_file</em></code></p>
<dl>
<dt>-preset <em>veryslow</em></dt><dd>This option tells FFmpeg to use the slowest preset possible for the best compression quality.</dd>
<dt>-crf <em>18</em></dt><dd>Specifying a lower CRF will make a larger file with better visual quality. 18 is often considered a ‘visually lossless’ compression.</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends Transcode to H.265 -->
<!-- Transcode to Ogg/Theora -->
<label class="recipe" for="transcode_ogg">Transcode to an Ogg Theora</label>
<input type="checkbox" id="transcode_ogg">
<div class="hiding">
<h5>Transcode to Ogg/Theora</h5>
<p><code>ffmpeg -i <em>input_file</em> -acodec libvorbis -b:v 690k <em>output_file</em></code></p>
<p>This command takes an input file and transcodes it to Ogg/Theora in an .ogv wrapper with 690k video bitrate.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-acodec libvorbis</dt><dd>tells FFmpeg to encode the audio using libvorbis</dd>
<dt>-b:v 690k</dt><dd>specifies the 690k video bitrate</dd>
<dt><em>output file</em></dt><dd>path, name and extension of the output file (make sure to include the <code>.ogv</code> filename suffix)</dd>
</dl>
<p>This recipe is based on <a href="http://paulrouget.com/e/converttohtml5video" target="_blank">Paul Rouget's recipes</a>.</p>
<p class="link"></p>
</div>
<!-- ends Transcode to Ogg/Theora -->
<p> </p>
<!-- Here comes audio-only transcoding -->
<!-- WAV to MP3 -->
<label class="recipe" for="wav_to_mp3">Convert WAV to MP3</label>
<input type="checkbox" id="wav_to_mp3">
<div class="hiding">
<h5>WAV to MP3</h5>
<p><code>ffmpeg -i <em>input_file</em>.wav -write_id3v1 1 -id3v2_version 3 -dither_method triangular -out_sample_rate 48k -qscale:a 1 <em>output_file</em>.mp3</code></p>
<p>This will convert your WAV files to MP3s.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path and name of the input file</dd>
<dt>-write_id3v1 1</dt><dd>This will write metadata to an ID3v1 tag at the head of the file, assuming you’ve embedded metadata into the WAV file.</dd>
<dt>-id3v2_version 3</dt><dd>This will write metadata to an ID3v2.3 tag at the tail of the file, assuming you’ve embedded metadata into the WAV file.</dd>
<dt>-dither_method triangular</dt><dd>Dither makes sure you don’t unnecessarily truncate the dynamic range of your audio.</dd>
<dt>-out_sample_rate 48k</dt><dd>Sets the audio sampling frequency to 48 kHz. This can be omitted to use the same sampling frequency as the input.</dd>
<dt>-qscale:a 1</dt><dd>This sets the encoder to use a constant quality with a variable bitrate of between 190-250kbit/s. If you would prefer to use a constant bitrate, this could be replaced with <code>-b:a 320k</code> to set to the maximum bitrate allowed by the MP3 format. For more detailed discussion on variable vs constant bitrates see <a href="https://trac.ffmpeg.org/wiki/Encode/MP3" target="_blank">here.</a></dd>
<dt><em>output_file</em></dt><dd>path and name of the output file</dd>
</dl>
<p>A couple notes</p>
<ul>
<li>About ID3v2.3 tag: ID3v2.3 is better supported than ID3v2.4, FFmpeg's default ID3v2 setting.</li>
<li>About dither methods: FFmpeg comes with a variety of dither algorithms, outlined in the <a href="https://ffmpeg.org/ffmpeg-resampler.html" target="_blank">official docs</a>, though some may lead to unintended, drastic digital clipping on some systems.</li>
</ul>
<p class="link"></p>
</div>
<!-- ends WAV to MP3 -->
<!-- append notice to access mp3 -->
<label class="recipe" for="append_mp3">Generate two access MP3s (with and without copyright)</label>
<input type="checkbox" id="append_mp3">
<div class="hiding">
<h5>Generate two access MP3s from input. One with appended audio (such as a copyright notice) and one unmodified.</h5>
<p><code>ffmpeg -i <em>input_file</em> -i <em>input_file_to_append</em> -filter_complex "[0:a:0]asplit=2[a][b];[b]afifo[bb];[1:a:0][bb]concat=n=2:v=0:a=1[concatout]" -map "[a]" -codec:a libmp3lame -dither_method triangular -qscale:a 2 <em>output_file.mp3</em> -map "[concatout]" -codec:a libmp3lame -dither_method triangular -qscale:a 2 <em>output_file_appended.mp3</em></code></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>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file (the master file)</dd>
<dt>-i <em>input_file_to_append</em></dt><dd>path, name and extension of the input file (the file to be appended to access file)</dd>
<dt>-filter_complex</dt><dd>enables the complex filtering to manage splitting the input to two audio streams</dd>
<dt>[0:a:0]asplit=2[a][b];</dt><dd><code>asplit</code> allows audio streams to be split up for separate manipulation. This command splits the audio from the first input (the master file) into two streams "a" and "b"</dd>
<dt>[b]afifo[bb];</dt><dd>this buffers the stream "b" to help prevent dropped samples and renames stream to "bb"</dd>
<dt>[1:a:0][bb]concat=n=2:v=0:a=1[concatout]</dt><dd><code>concat</code> is used to join files. <code>n=2</code> tells the filter there are two inputs. <code>v=0:a=1</code> Tells the filter there are 0 video outputs and 1 audio output. This command appends the audio from the second input to the beginning of stream "bb" and names the output "concatout"</dd>
<dt>-map "[a]"</dt><dd>this maps the unmodified audio stream to the first output</dd>
<dt>-codec:a libmp3lame -dither_method triangular -qscale:a 2</dt><dd>sets up MP3 options (using constant quality)</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output file (unmodified)</dd>
<dt>-map "[concatout]"</dt><dd>this maps the modified stream to the second output</dd>
<dt>-codec:a libmp3lame -dither_method triangular -qscale:a 2</dt><dd>sets up MP3 options (using constant quality)</dd>
<dt><em>output_file_appended</em></dt><dd>path, name and extension of the output file (with appended notice)</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends append notice to access mp3 -->
<!-- WAV to AAC/MP4 -->
<label class="recipe" for="wav_to_mp4">Convert WAV to AAC/MP4</label>
<input type="checkbox" id="wav_to_mp4">
<div class="hiding">
<h5>WAV to AAC/MP4</h5>
<p><code>ffmpeg -i <em>input_file</em>.wav -c:a aac -b:a 128k -dither_method triangular -ar 44100 <em>output_file</em>.mp4</code></p>
<p>This will convert your WAV file to AAC/MP4.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path and name of the input file</dd>
<dt>-c:a aac</dt><dd>sets the audio codec to AAC</dd>
<dt>-b:a 128k</dt><dd>sets the bitrate of the audio to 128k</dd>
<dt>-dither_method triangular</dt><dd>Dither makes sure you don’t unnecessarily truncate the dynamic range of your audio.</dd>
<dt>-ar 44100</dt><dd>sets the audio sampling frequency to 44100 Hz, or 44.1 kHz, or “CD quality”</dd>
<dt><em>output_file</em></dt><dd>path and name of the output file</dd>
</dl>
<p>A note about dither methods. FFmpeg comes with a variety of dither algorithms, outlined in the <a href="https://ffmpeg.org/ffmpeg-resampler.html" target="_blank">official docs</a>, though some may lead to unintended, not-subtle digital clipping on some systems.</p>
<p class="link"></p>
</div>
<!-- ends WAV to AAC/MP4 -->
</div>
<div class="well">
<h2 id="video-properties">Change video properties</h2>
<!-- 4:3 to 16:9 -->
<label class="recipe" for="SD_HD">Transform 4:3 aspect ratio into 16:9 with pillarbox</label>
<input type="checkbox" id="SD_HD">
<div class="hiding">
<h5>Transform 4:3 aspect ratio into 16:9 with pillarbox</h5>
<p>Transform a video file with 4:3 aspect ratio into a video file with 16:9 aspect ratio by correct pillarboxing.</p>
<p><code>ffmpeg -i <em>input_file</em> -filter:v "pad=ih*16/9:ih:(ow-iw)/2:(oh-ih)/2" -c:a copy <em>output_file</em></code></p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-filter:v "pad=ih*16/9:ih:(ow-iw)/2:(oh-ih)/2"</dt><dd>video padding<br>This resolution independent formula is actually padding any aspect ratio into 16:9 by pillarboxing, because the video filter uses relative values for input width (iw), input height (ih), output width (ow) and output height (oh).</dd>
<dt>-c:a copy</dt><dd>re-encodes using the same audio codec<br>
For silent videos you can replace <code>-c:a copy</code> by <code>-an</code>.</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends 4:3 to 16:9 -->
<!-- 16:9 to 4:3 -->
<label class="recipe" for="HD_SD">Transform 16:9 aspect ratio video into 4:3 with letterbox</label>
<input type="checkbox" id="HD_SD">
<div class="hiding">
<h5>Transform 16:9 aspect ratio video into 4:3 with letterbox</h5>
<p>Transform a video file with 16:9 aspect ratio into a video file with 4:3 aspect ratio by correct letterboxing.</p>
<p><code>ffmpeg -i <em>input_file</em> -filter:v "pad=iw:iw*3/4:(ow-iw)/2:(oh-ih)/2" -c:a copy <em>output_file</em></code></p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-filter:v "pad=iw:iw*3/4:(ow-iw)/2:(oh-ih)/2"</dt><dd>video padding<br>
This resolution independent formula is actually padding any aspect ratio into 4:3 by letterboxing, because the video filter uses relative values for input width (iw), input height (ih), output width (ow) and output height (oh).</dd>
<dt>-c:a copy</dt><dd>re-encodes using the same audio codec<br>
For silent videos you can replace <code>-c:a copy</code> by <code>-an</code>.</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends 16:9 to 4:3 -->
<!-- Flip image -->
<label class="recipe" for="flip_image">Flip video image</label>
<input type="checkbox" id="flip_image">
<div class="hiding">
<h5>Flip the video image horizontally and/or vertically</h5>
<p><code>ffmpeg -i <em>input_file</em> -filter:v "hflip,vflip" -c:a copy <em>output_file</em></code></p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-filter:v "hflip,vflip"</dt><dd>flips the image horizontally and vertically<br>By using only one of the parameters hflip or vflip for filtering the image is flipped on that axis only. The quote marks are not mandatory.</dd>
<dt>-c:a copy</dt><dd>re-encodes using the same audio codec<br>
For silent videos you can replace <code>-c:a copy</code> by <code>-an</code>.</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends Flip image -->
<!-- SD to HD -->
<label class="recipe" for="SD_HD_2">Transform SD to HD with pillarbox</label>
<input type="checkbox" id="SD_HD_2">
<div class="hiding">
<h5>Transform SD into HD with pillarbox</h5>
<p>Transform a SD video file with 4:3 aspect ratio into an HD video file with 16:9 aspect ratio by correct pillarboxing.</p>
<p><code>ffmpeg -i <em>input_file</em> -filter:v "colormatrix=bt601:bt709, scale=1440:1080:flags=lanczos, pad=1920:1080:240:0" -c:a copy <em>output_file</em></code></p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-filter:v "colormatrix=bt601:bt709, scale=1440:1080:flags=lanczos, pad=1920:1080:240:0"</dt><dd>set colour matrix, video scaling and padding<br>Three filters are applied:
<ol>
<li>The luma coefficients are modified from SD video (according to Rec. 601) to HD video (according to Rec. 709) by a color matrix. Note that today Rec. 709 is often used also for SD and therefore you may cancel this parameter.</li>
<li>The scaling filter (<code>scale=1440:1080</code>) works for both upscaling and downscaling. We use the Lanczos scaling algorithm (<code>flags=lanczos</code>), which is slower but gives better results than the default bilinear algorithm.</li>
<li>The padding filter (<code>pad=1920:1080:240:0</code>) completes the transformation from SD to HD.</li>
</ol></dd>
<dt>-c:a copy</dt><dd>re-encodes using the same audio codec<br>
For silent videos you can replace <code>-c:a copy</code> with <code>-an</code>.</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<p>If your source is interlaced, you will want to deinterlace prior to scaling. In that case, your command would look like this:</p>
<p><code>ffmpeg -i <em>input_file</em> -c:v libx264 -filter:v "yadif, colormatrix=bt601:bt709, scale=1440:1080:flags=lanczos, pad=1920:1080:240:0" -c:a copy <em>output_file</em></code></p>
<p>See the <a href="#ntsc_to_h264">Interlaced NTSC to MP4 recipe</a> for a fuller explanation of the deinterlacing step.</p>
<p class="link"></p>
</div>
<!-- ends SD to HD -->
<!-- Change display aspect ratio without re-encoding -->
<label class="recipe" for="change_DAR">Change display aspect ratio without re-encoding</label>
<input type="checkbox" id="change_DAR">
<div class="hiding">
<h5>Change Display Aspect Ratio without re-encoding</h5>
<p><code>ffmpeg -i <em>input_file</em> -c:a copy -c:v copy -aspect 4:3 <em>output_file</em></code></p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-c:a copy</dt><dd>Copy all mapped audio streams.</dd>
<dt>-c:v copy</dt><dd>Copy all mapped video streams.</dd>
<dt>-aspect 4:3</dt><dd>Change Display Aspect Ratio to <code>4:3</code>. Experiment with other aspect ratios such as <code>16:9</code>. If used together with <code>-c:v copy</code>, it will affect the aspect ratio stored at container level, but not the aspect ratio stored in encoded frames, if it exists.</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends Change display aspect ratio without re-encoding -->
<!-- Convert colorspace -->
<label class="recipe" for="convert-colorspace">Convert colorspace of video</label>
<input type="checkbox" id="convert-colorspace">
<div class="hiding">
<h5>Transcode video to a different colorspace</h5>
<p>This command uses a filter to convert the video to a different colorspace.</p>
<p><code>ffmpeg -i <em>input_file</em> -c:v libx264 -vf colormatrix=src:dst <em>output_file</em></code></p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input file</em></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>-vf colormatrix=<em>src</em>:<em>dst</em></dt><dd>the video filter <strong>colormatrix</strong> will be applied, with the given source and destination colorspaces.<br>
Accepted values include <code>bt601</code> (Rec.601), <code>smpte170m</code> (Rec.601, 525-line/<a href="https://en.wikipedia.org/wiki/NTSC#NTSC-M" target="_blank">NTSC</a> version), <code>bt470bg</code> (Rec.601, 625-line/<a href="https://en.wikipedia.org/wiki/PAL#PAL-B.2FG.2FD.2FK.2FI" target="_blank">PAL</a> version), <code>bt709</code> (Rec.709), and <code>bt2020</code> (Rec.2020).<br>
For example, to convert from Rec.601 to Rec.709, you would use <code>-vf colormatrix=bt601:bt709</code>.</dd>
<dt><em>output file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<p><strong>Note:</strong> Converting between colorspaces with FFmpeg can be done via either the <strong>colormatrix</strong> or <strong>colorspace</strong> filters, with colorspace allowing finer control (individual setting of colorspace, transfer characteristics, primaries, range, pixel format, etc). See <a href="https://trac.ffmpeg.org/wiki/colorspace" target="_blank">this</a> entry on the FFmpeg wiki, and the FFmpeg documentation for <a href="https://ffmpeg.org/ffmpeg-filters.html#colormatrix" target="_blank">colormatrix</a> and <a href="https://ffmpeg.org/ffmpeg-filters.html#colorspace" target="_blank">colorspace</a>.</p>
<hr>
<h4>Convert colorspace and embed colorspace metadata</h4>
<p><code>ffmpeg -i <em>input_file</em> -c:v libx264 -vf colormatrix=src:dst -color_primaries <em>val</em> -color_trc <em>val</em> -colorspace <em>val</em> <em>output_file</em></code></p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-c:v libx264</dt><dd>encode video as H.264</dd>
<dt>-vf colormatrix=<em>src</em>:<em>dst</em></dt><dd>the video filter <strong>colormatrix</strong> will be applied, with the given source and destination colorspaces.</dd>
<dt>-color_primaries <em>val</em></dt><dd>tags video with the given color primaries.<br>
Accepted values include <code>smpte170m</code> (Rec.601, 525-line/NTSC version), <code>bt470bg</code> (Rec.601, 625-line/PAL version), <code>bt709</code> (Rec.709), and <code>bt2020</code> (Rec.2020).
<dt>-color_trc <em>val</em></dt><dd>tags video with the given transfer characteristics (gamma).<br>
Accepted values include <code>smpte170m</code> (Rec.601, 525-line/NTSC version), <code>gamma28</code> (Rec.601, 625-line/PAL version)<sup><a href="#fn1" id="ref1">1</a></sup>, <code>bt709</code> (Rec.709), <code>bt2020_10</code> (Rec.2020 10-bit), and <code>bt2020_12</code> (Rec.2020 12-bit).</dd>
<dt>-colorspace <em>val</em></dt><dd>tags video as being in the given colourspace.<br>
Accepted values include <code>smpte170m</code> (Rec.601, 525-line/NTSC version), <code>bt470bg</code> (Rec.601, 625-line/PAL version), <code>bt709</code> (Rec.709), <code>bt2020_cl</code> (Rec.2020 constant luminance), and <code>bt2020_ncl</code> (Rec.2020 non-constant luminance).</dd>
<dt><em>output file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<h4>Examples</h4>
<p>To Rec.601 (525-line/NTSC):</p>
<p><code>ffmpeg -i <em>input_file</em> -c:v libx264 -vf colormatrix=bt709:smpte170m -color_primaries smpte170m -color_trc smpte170m -colorspace smpte170m <em>output_file</em></code></p>
<p>To Rec.601 (625-line/PAL):</p>
<p><code>ffmpeg -i <em>input_file</em> -c:v libx264 -vf colormatrix=bt709:bt470bg -color_primaries bt470bg -color_trc gamma28 -colorspace bt470bg <em>output_file</em></code></p>
<p>To Rec.709:</p>
<p><code>ffmpeg -i <em>input_file</em> -c:v libx264 -vf colormatrix=bt601:bt709 -color_primaries bt709 -color_trc bt709 -colorspace bt709 <em>output_file</em></code></p>
<p>MediaInfo output examples:</p>
<img src="./img/colourspace_metadata_mediainfo.png" alt="MediaInfo screenshots of colorspace metadata"><br>
<p><span class="beware">⚠</span> Using this command it is possible to add Rec.709 tags to a file that is actually Rec.601 (etc), so apply with caution!</p>
<p>These commands are relevant for H.264 and H.265 videos, encoded with <code>libx264</code> and <code>libx265</code> respectively.</p>
<p><strong>Note:</strong> If you wish to embed colorspace metadata <em>without</em> changing to another colorspace, omit <code>-vf colormatrix=src:dst</code>. However, since it is <code>libx264</code>/<code>libx265</code> that writes the metadata, it’s not possible to add these tags without re-encoding the video stream.</p>
<p>For all possible values for <code>-color_primaries</code>, <code>-color_trc</code>, and <code>-colorspace</code>, see the FFmpeg documentation on <a href="https://ffmpeg.org/ffmpeg-codecs.html#Codec-Options" target="_blank">codec options</a>.</p>
<hr>
<p id="fn1" class="footnote">1. Out of step with the regular pattern, <code>-color_trc</code> doesn’t accept <code>bt470bg</code>; it is instead here referred to directly as gamma.<br>
In the Rec.601 standard, 525-line/NTSC and 625-line/PAL video have assumed gammas of 2.2 and 2.8 respectively. <a href="#ref1" title="Jump back.">↩</a></p>
<p class="link"></p>
</div>
<!-- ends Convert colorspace -->
<!-- Modify speed -->
<label class="recipe" for="modify_speed">Modify image and sound speed</label>
<input type="checkbox" id="modify_speed">
<div class="hiding">
<h5>Modify image and sound speed</h5>
<p>E.g. for converting 24fps to 25fps with audio pitch compensation for PAL access copies. (Thanks @kieranjol!)</p>
<p><code>ffmpeg -i <em>input_file</em> -r <em>output_fps</em> -filter_complex "[0:v]setpts=<em>input_fps</em>/<em>output_fps</em>*PTS[v]; [0:a]atempo=<em>output_fps</em>/<em>input_fps</em>[a]" -map "[v]" -map "[a]" <em>output_file</em></code></p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-r <em>output_fps</em></dt><dd>sets the frame rate of the <em>output_file</em></dd>
<dt>-filter_complex "[0:v]setpts=<em>input_fps</em>/<em>output_fps</em>*PTS[v]; [0:a]atempo=<em>output_fps</em>/<em>input_fps</em>[a]"</dt><dd>A complex filter is needed here, in order to handle video stream and the audio stream separately. The <code>setpts</code> video filter modifies the PTS (presentation time stamp) of the video stream, and the <code>atempo</code> audio filter modifies the speed of the audio stream while keeping the same sound pitch. Note that the parameter order for the image and for the sound are inverted:
<ul>
<li>In the video filter <code>setpts</code> the numerator <code>input_fps</code> sets the input speed and the denominator <code>output_fps</code> sets the output speed; both values are given in frames per second.</li>
<li>In the sound filter <code>atempo</code> the numerator <code>output_fps</code> sets the output speed and the denominator <code>input_fps</code> sets the input speed; both values are given in frames per second.</li>
</ul>
The different filters in a complex filter can be divided either by comma or semicolon. The quotation marks allow to insert a space between the filters for readability.</dd>
<dt>-map "[v]"</dt><dd>maps the video stream and</dd>
<dt>-map "[a]"</dt><dd>maps the audio stream together into:</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends Modify speed -->
<!-- Fade both video and audio streams -->
<label class="recipe" for="fade_streams">Fade both video and audio streams</label>
<input type="checkbox" id="fade_streams">
<div class="hiding">
<h5>Fade both video and audio streams</h5>
<p><code>ffmpeg -i <em>input_file</em> -filter:v "fade=in:st=IN_POINT:d=DURATION, fade=out:st=OUT_POINT:d=DURATION" -filter:a "afade=in:st=OUT_POINT:d=DURATION, afade=out:st=IN_POINT:d=DURATION" -c:v libx264 -c:a aac <em>output_file</em></code></p>
<p>This command fades your video in and out. Change IN_POINT, OUT_POINT, and DURATION to the time in seconds (expressed as integers).</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-filter:v "fade=in:st=IN_POINT:d=DURATION, fade=out:st=OUT_POINT:d=DURATION"</dt><dd>applies a video filter that fades your video in and out. <code>st</code> sets the start and <code>d</code> sets the duration.</dd>
<dt>-filter:a "afade=in:st=IN_POINT:d=DURATION, afade=out:st=OUT_POINT:d=DURATION"</dt><dd>applies an audio filter that fades your video in and out. <code>st</code> sets the start and <code>d</code> sets the duration.</dd>
<dt>-c:v <em>video_codec</em></dt><dd>as a video filter is used, it is not possible to use <code>-c copy</code>. The video must be re-encoded with whatever video codec is chosen, e.g. <code>ffv1</code>, <code>v210</code> or <code>prores</code>.</dd>
<dt>-c:a <em>audio_codec</em></dt><dd>as an audio filter is used, it is not possible to use <code>-c copy</code>. The audio must be re-encoded with whatever audio codec is chosen, e.g. <code>aac</code>.</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output_file</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends Fade both video and audio streams -->
<!-- Synchronize video and audio streams -->
<label class="recipe" for="sync_streams">Synchronize video and audio streams</label>
<input type="checkbox" id="sync_streams">
<div class="hiding">
<h5>Synchronize video and audio streams</h5>
<p><code>ffmpeg -i <em>input_file</em> -itsoffset 0.125 -i <em>input_file</em> -map 1:v -map 0:a -c copy <em>output_file</em></code></p>
<p>A command to slip the video channel approximate 2 frames (0.125 for a 25fps timeline) to align video and audio drift, if generated during video tape capture for example.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-itsoffset 0.125</dt><dd>uses itsoffset command to set offset to 0.125 of a second. The offset time must be a time duration specification, see <a href="https://ffmpeg.org/ffmpeg-utils.html#time-duration-syntax" target="_blank">FFMPEG Utils Time Duration Syntax</a>.</dd>
<dt>-i <em>input_file</em></dt><dd>repeat path, name and extension of the input file</dd>
<dt>-map 1:v -map 0:a</dt><dd>selects the video channel for itsoffset command. To slip the audio channel reverse the selection to -map 0:v -map 1:a.</dd>
<dt>-c copy</dt><dd>copies the encode settings of the input_file to the output_file</dd>
<dt><em>output_file_resync</em></dt><dd>path, name and extension of the output_file</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends Synchronize video and audio streams -->
<!-- Make stream properties explicate -->
<label class="recipe" for="clarify_stream">Clarify stream properties</label>
<input type="checkbox" id="clarify_stream">
<div class="hiding">
<h5>Set stream properties</h5>
<h2>Find undetermined or unknown stream properties</h2>
<p>These examples use QuickTime inputs and outputs. The strategy will vary or may not be possible in other file formats. In the case of these examples it is the intention to make a lossless copy while clarifying an unknown characteristic of the stream.</p>
<p><code>ffprobe <em>input_file</em> -show_streams</code></p>
<dl>
<dt>ffprobe</dt><dd>starts the command</dd>
<dt><em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-show_streams</dt><dd>Shows metadata of stream properties</dd>
</dl>
<p>Values that are set to 'unknown' and 'undetermined' may be unspecified within the stream. An unknown aspect ratio would be expressed as '0:1'. Streams with many unknown properties may have interoperability issues or not play as intended. In many cases, an unknown or undetermined value may be accurate because the information about the source is unclear, but often the value is intended to be known. In many cases the stream will played with an assumed value if undetermined (for instance a display_aspect_ratio of '0:1' may be played as 'WIDTH:HEIGHT'), but this may or may not be what is intended. Use carefully.</p>
<h2>Set aspect ratio</h2>
<p>If the display_aspect_ratio is set to '0:1' it may be clarified with the <em>-aspect</em> option and stream copy.</p>
<p><code>ffmpeg -i <em>input_file</em> -c copy -map 0 -aspect DAR_NUM:DAR_DEN <em>output_file</em></code></p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-c copy</dt><dd>Using stream copy for all streams</dd>
<dt>-map 0</dt><dd>tells FFmpeg to map all streams of the input to the output.</dd>
<dt>-aspect DAR_NUM:DAR_DEN</dt><dd>Replace DAR_NUM with the display aspect ratio numerator and DAR_DEN with the display aspect ratio denominator, such as <em>-aspect 4:3</em> or <em>-aspect 16:9</em>.</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<h2>Adding other stream properties.</h2>
<p>Other properties may be clarified in a similar way. Replace <em>-aspect</em> and its value with other properties such as shown in the options below. Note that setting color values in QuickTime requires that <em>-movflags write_colr</em> is set.</p>
<dl>
<dt>-color_primaries <em>VALUE</em> -movflags write_colr</dt><dd>Set a new color_primaries value.</dd>
<dt>-color_trc <em>VALUE</em> -movflags write_colr</dt><dd>Set a new color_transfer value.</dd>
<dt>-field_order <em>VALUE</em></dt><dd>Set interlacement values.</dd>
</dl>
<p>The possible values for <code>-color_primaries</code>, <code>-color_trc</code>, and <code>-field_order</code> are given in the <a href="https://ffmpeg.org/ffmpeg-all.html#toc-Codec-Options" target="_blank">Codec Options</a> section of the FFmpeg docs - scroll down to near the bottom of the section.</p>
<p class="link"></p>
</div>
<!-- ends Make stream properties explicate -->
<!-- Crop video -->
<label class="recipe" for="crop_video">Crop video</label>
<input type="checkbox" id="crop_video">
<div class="hiding">
<h5>Crop video</h5>
<p><code>ffmpeg -i <em>input_file</em> -vf "crop=<em>width</em>:<em>height</em>" <em>output_file</em></code></p>
<p>This command crops the input video to the dimensions defined</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-vf "<em>width</em>:<em>height</em>"</dt><dd>Crops the video to the given width and height (in pixels).<br>
By default, the crop area is centered: that is, the position of the top left of the cropped area is set to x = (<em>input_width</em> - <em>output_width</em>) / 2, y = <em>input_height</em> - <em>output_height</em>) / 2.
</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<p>It's also possible to specify the crop position by adding the x and y coordinates representing the top left of your cropped area to your crop filter, as such:</p>
<p><code>ffmpeg -i <em>input_file</em> -vf "crop=<em>width</em>:<em>height</em>[:<em>x_position</em>:<em>y_position</em>]" <em>output_file</em></code></p>
<h5>Examples</h5>
<p>The original frame, a screenshot of Maggie Cheung in the film <i>Hero</i>:</p>
<img class="sample-image" src="img/crop_example_orig.png" alt="VLC screenshot of Maggie Cheung">
<p>Result of the command <code>ffmpeg -i <em>maggie.mov</em> -vf "crop=500:500" <em>output_file</em></code>:</p>
<img class="sample-image-small" src="img/crop_example_aftercrop1.png" alt="VLC screenshot of Maggie Cheung, cropped from original">
<p>Result of the command <code>ffmpeg -i <em>maggie.mov</em> -vf "crop=500:500:0:0" <em>output_file</em></code>, appending <code>:0:0</code> to crop from the top left corner:</p>
<img class="sample-image-small" src="img/crop_example_aftercrop2.png" alt="VLC screenshot of Maggie Cheung, cropped from original">
<p>Result of the command <code>ffmpeg -i <em>maggie.mov</em> -vf "crop=500:300:500:30" <em>output_file</em></code>:</p>
<img class="sample-image-small" src="img/crop_example_aftercrop3.png" alt="VLC screenshot of Maggie Cheung, cropped from original">
<p class="link"></p>
</div>
<!-- ends Crop video -->
<!-- Change video color to black and white -->
<label class="recipe" for="col_change">Change video color to black and white</label>
<input type="checkbox" id="col_change">
<div class="hiding">
<h5>Change video color to black and white</h5>
<p><code>ffmpeg -i <em>input_file</em> -filter_complex hue=s=0 -c:a copy <em>output_file</em></code></p>
<p>A basic command to alter color hue to black and white using filter_complex (credit @FFMPEG via Twitter).</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-filter_complex hue=s=0</dt><dd>uses filter_complex command to set the hue to black and white</dd>
<dt>-c:a copy</dt><dd>copies the encode settings of the input_file to the output_file</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output_file</dd>
</dl>
<p>An alternative that preserves interlacing information for a ProRes 422 HQ file generated, for example, from a tape master (credit Dave Rice):</p>
<p><code>ffmpeg -i <em>input_file</em> -c:v prores_ks -flags +ildct -map 0 -c:a copy -profile:v 3 -vf hue=s=0 <em>output_file</em></code></p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-c:v prores_ks</dt><dd>encodes the video to ProRes (prores_ks marks the stream as interlaced, unlike prores)</dd>
<dt>-flags +ildct</dt><dd>ensures that the output_file has interlaced field encoding, using interlace aware discrete cosine transform</dd>
<dt>-map 0</dt><dd>ensures ffmpeg maps all streams of the input_file to the output_file</dd>
<dt>-c:a copy</dt><dd>copies the encode settings of the input_file to the output_file</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends Change video color to black and white -->
</div>
<div class="well">
<h2 id="audio-files">Change or view audio properties</h2>
<!-- Extract audio from an AV file -->
<label class="recipe" for="extract_audio">Extract audio without loss from an AV file</label>
<input type="checkbox" id="extract_audio">
<div class="hiding">
<h5>Extract audio from an AV file</h5>
<p><code>ffmpeg -i <em>input_file</em> -c:a copy -vn <em>output_file</em></code></p>
<p>This command extracts the audio stream without loss from an audiovisual file.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-c:a copy</dt><dd>re-encodes using the same audio codec</dd>
<dt>-vn</dt><dd>no video stream</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends Extract audio from am AV file -->
<!-- Combine audio tracks -->
<label class="recipe" for="combine_audio">Combine audio tracks</label>
<input type="checkbox" id="combine_audio">
<div class="hiding">
<h5>Combine audio tracks into one in a video file</h5>
<p><code>ffmpeg -i <em>input_file</em> -filter_complex "[0:a:0][0:a:1]amerge[out]" -map 0:v -map "[out]" -c:v copy -shortest <em>output_file</em></code></p>
<p>This command combines two audio tracks present in a video file into one stream. It can be useful in situations where a downstream process, like YouTube’s automatic captioning, expect one audio track. To ensure that you’re mapping the right audio tracks run ffprobe before writing the script to identify which tracks are desired. More than two audio streams can be combined by extending the pattern present in the -filter_complex option.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-filter_complex</dt><dd>tells ffmpeg that we will be using a complex filter</dd>
<dt>"</dt><dd>quotation mark to start filtergraph</dd>
<dt>[0:a:0][0:a:1]amerge[out]</dt><dd>combines the two audio tracks into one</dd>
<dt>"</dt><dd>quotation mark to end filtergraph</dd>
<dt>-map 0:v</dt><dd>map the video</dd>
<dt>-map "[out]"</dt><dd>map the combined audio defined by the filter</dd>
<dt>-c:v copy</dt><dd>copy the video</dd>
<dt>-shortest</dt><dd>limit to the shortest stream</dd>
<dt><em>output_file</em></dt><dd>path, name and extension of the video output file</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends Combine audio tracks -->
<!-- phase shift -->
<label class="recipe" for="phase_shift">Inverses the audio phase of the second channel</label>
<input type="checkbox" id="phase_shift">
<div class="hiding">
<h5>Flip audio phase shift</h5>
<p><code>ffmpeg -i <em>input_file</em> -af pan="stereo|c0=c0|c1=-1*c1" <em>output_file</em></code></p>
<p>This command inverses the audio phase of the second channel by rotating it 180°.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <em>input file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-af</dt><dd>specifies that the next section should be interpreted as an audio filter</dd>
<dt>pan=</dt><dd>tell the quoted text below to use the <a href="https://ffmpeg.org/ffmpeg-filters.html#pan-1" target="_blank">pan filter</a></dd>
<dt>"stereo|c0=c0|c1=-1*c1"</dt><dd>maps the output's first channel (c0) to the input's first channel and the output's second channel (c1) to the inverse of the input's second channel</dd>
<dt><em>output file</em></dt><dd>path, name and extension of the output file</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends phase shift -->
<!-- loudnorm metadata -->
<label class="recipe" for="loudnorm_metadata">Calculate Loudness Levels</label>
<input type="checkbox" id="loudnorm_metadata">
<div class="hiding">
<h5>Calculate Loudness Levels</h5>
<p><code>ffmpeg -i <em>input_file</em> -af loudnorm=print_format=json -f null -</code></p>
<p>This filter calculates and outputs loudness information in json about an input file (labeled input) as well as what the levels would be if loudnorm were applied in its one pass mode (labeled output). The values generated can be used as inputs for a 'second pass' of the loudnorm filter allowing more accurate loudness normalization than if it is used in a single pass.</p>
<p>These instructions use the loudnorm defaults, which align well with PBS recommendations for target loudness. More information can be found at the <a href="https://ffmpeg.org/ffmpeg-filters.html#loudnorm" target="_blank">loudnorm documentation</a>.</p>
<p>Information about PBS loudness standards can be found in the <a href="http://bento.cdn.pbs.org/hostedbento-prod/filer_public/PBS_About/Producing/Red%20Book/TOS%20Pt%201%20Submission%202016.pdf" target="_blank">PBS Technical Operating Specifications</a> document. Information about EBU loudness standards can be found in the <a href="https://tech.ebu.ch/docs/r/r128-2014.pdf" target="_blank">EBU R 128</a> recommendation document.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt><em>input_file</em></dt><dd>path, name and extension of the input file</dd>
<dt>-af loudnorm</dt><dd>activates the loudnorm filter</dd>
<dt>print_format=json</dt><dd>sets the output format for loudness information to json. This format makes it easy to use in a second pass. For a more human readable output, this can be set to <code>print_format=summary</code></dd>
<dt><em>-f null -</em></dt><dd>sets the file output to null (since we are only interested in the metadata generated)</dd>
</dl>
<p class="link"></p>
</div>
<!-- ends loudnorm metadata -->
<!-- RIAA equalization -->