Changes

Jump to navigation Jump to search
m
Line 38: Line 38:  
===Basic Format Conversion===
 
===Basic Format Conversion===
 
{{cmdline|ffmpeg -i input.mp4 output.avi}}
 
{{cmdline|ffmpeg -i input.mp4 output.avi}}
 +
 +
<code>-i</code> specifies input file
 +
 +
The last argument is always the output file. Without specifying any codec or bit rate (see examples below), FFmpeg will encode the video using some arbitrary default settings.
    
===Remove audio from video file===
 
===Remove audio from video file===
Line 52: Line 56:     
===Add audio to video===
 
===Add audio to video===
{{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>-map 0:v</code> tells FFmpeg to take video from the first input (count starts at 0)
 +
 
 +
<code>-map 1:a</code> tells FFmpeg to take audio from the second input (1)
 +
 
 +
===Trimming video===
 +
{{cmdline|ffmpeg -i input.mp4 -ss 00:00:04 -to 00:00:06 -vcodec h264 -b:v 8M output.mp4}}
 +
 
 +
<code>-ss 00:00:04</code> specifies the starting time, in this case 4 seconds (use format HH:MM:SS, or HH:MM:SS.MS)
 +
 
 +
<code>-to 00:00:06</code> specifies end point, in this case 6 seconds (same formatting as above)
 +
 
 +
Alternatively, instead of <code>-to</code>, you can use <code>-t 00:00:02</code> to cut exactly 2 seconds from the starting time.
 +
 
 +
<code>-vcodec h264</code> specifies video codec.
 +
 
 +
<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 FFmpeg can only cut to the nearest keyframe, so the output may not be exactly the same length as specified.
 +
 
 +
===Batching===
 +
The following is a batch script (text file with .bat file extension) that converts all .mp4 files in the specified folder to .avi:
 +
<pre>@echo off
 +
setlocal enabledelayedexpansion
 +
 
 +
:: Set source video folder, as absolute path or relative to this script
 +
set src="videos"
 +
 
 +
:: Set destination folder
 +
set dst="videos/converted"
 +
 
 +
for /R %src% %%F in (*.mp4) do (
 +
    :: Put your FFmpeg command here
 +
    ffmpeg -i "%%F" -vcodec copy "%dst%\%%~nF.avi
 +
)
 +
 
 +
pause
 +
</pre>

Navigation menu