FFmpeg: Difference between revisions

Jump to navigation Jump to search
 
(9 intermediate revisions by the same user not shown)
Line 15: Line 15:
}}
}}


FFmpeg is an open-source command-line tool to convert audio and video files.  
FFmpeg is an open-source command-line tool to convert audio and video files. <br/>
We know command-line tools can seem scary! But conversion software GUIs (graphical user interfaces) are often a more limiting, or will obfuscate what gets done to your video or audio file. For the highest level of control and transparency, we therefore highly recommend using FFmpeg for all your AV conversion needs.


<!-- Table of Contents will be generated here -->
<!-- Table of Contents will be generated here -->


==Installation==
==Installation==
===Windows 10===
===Windows 10/11===
#Download the latest ffmpeg-release-full build on https://ffmpeg.org/download.html
#Go to https://ffmpeg.org/download.html
#Unpack the 7z/zip file anywhere you like
#Under "Get packages & executable files", select the Windows logo and follow one of the links below (''gyan.dev'' is most common)
#Download the latest ''ffmpeg-release-essentials'' .7z or .zip file.<ref>The FFmpeg "essentials" version should be fine for most purposes; use "full" version for more obscure/obsolete/experimental formats</ref>
#Unpack the 7z/zip file anywhere you like.
#Add ffmpeg to Windows' Environment Variables:
#Add ffmpeg to Windows' Environment Variables:
## Open the start menu and start typing "Environment Variables"
## Open the start menu and start typing "Environment Variables"
Line 35: Line 38:
FFmpeg needs to be run from the command line, but you can create batch scripts to automate the process for multiple files. There is also a plugin for Python (https://pypi.org/project/ffmpeg-python/), but it is fairly limited so we recommend using subprocess instead (see example below).
FFmpeg needs to be run from the command line, but you can create batch scripts to automate the process for multiple files. There is also a plugin for Python (https://pypi.org/project/ffmpeg-python/), but it is fairly limited so we recommend using subprocess instead (see example below).


The following are examples of conversions that we commonly use.
The following are examples of conversions that we commonly use. For [[Psychopy]] applications, please follow the more strict instructions under [[Video Playback#FFmpeg]].


===Basic Format Conversion===
===Basic Format Conversion===
Line 72: Line 75:
{{cmdline|ffmpeg -i inputvideo.mp4 -i inputaudio.wav -vcodec copy -map 0:v -map 1:a output.mp4}}
{{cmdline|ffmpeg -i inputvideo.mp4 -i inputaudio.wav -vcodec copy -map 0:v -map 1:a output.mp4}}


<code>-i</code> is used twice here to add a seceond input file.
<code>-i</code> is used twice here to add a second input file.


<code>-map 0:v</code> tells FFmpeg to take video from the first input (count starts at 0)
<code>-map 0:v</code> tells FFmpeg to take video from the first input (count starts at 0)
Line 91: Line 94:
<code>-b:v 8M</code> specifies video bit rate, in this case 8Mbit/s, which determines video quality.
<code>-b:v 8M</code> specifies video bit rate, in this case 8Mbit/s, which determines video quality.


Note: you can use <code>-c copy</code> to trim without re-encoding, but in this case FFmpeg can only cut to the nearest keyframe, so the output may not be exactly the same length as specified.
⚠️If you use <code>-vcodec copy</code> to trim without re-encoding, FFmpeg can only cut to the nearest keyframe, so the output may not be exactly the same length as specified.


===Batching===
===Batching===
Line 121: Line 124:
</syntaxhighlight >
</syntaxhighlight >
The command within <code>subprocess.run()</code> is the same as you would type into the command line. You can use Python's [https://docs.python.org/3/tutorial/inputoutput.html#tut-f-strings string formatting] to insert variables.
The command within <code>subprocess.run()</code> is the same as you would type into the command line. You can use Python's [https://docs.python.org/3/tutorial/inputoutput.html#tut-f-strings string formatting] to insert variables.
==External Links==
*[https://github.com/rendi-api/ffmpeg-cheatsheet ffmpeg cheatsheet] - For more examples of helpful commands.


==See Also==  
==See Also==  
* [[Video Codecs]]
* [[Video Codecs]]
==References==
<references/>