Concatenating videos with FFmpeg
The
FFmpeg video handling
utility can be used to join videos together into one larger video. If the video
files are
MPEG-1,
MPEG-2, MPEG
Program Stream (PS)
, or
Digital Video
(DV) files, you can use a Direct Stream copy method, by issuing a command in
the form
ffmpeg -i "concat:input1.mpg|input2.mpg" -c copy
output.mpg. Using ffmpeg for the concatenation operation ensures that
file headers and timestamps are handled correctly, whereas using operating
system commands such as
cat on a Linux system or
copy /b on a Microsoft Windows system may produce payback issues.
This method can not be used for
MPEG-4 files, however.
Another method that can be used for MP4 files, as well as the above
file types is the Concat Demuxer method,
if the files use the same
codecs and parameters, such as
resolution,
framerate, etc.
If the files have the same characteristics, you can use a command of the form:
ffmpeg -f concat -safe 0 -i inputFileList.txt
-c copy output.mp4
[ More Info ]
[/video/ffmpeg]
permanent link
Trimming a video with FFmpeg
FFmpeg provides a
suite of
command-line
interface tools for working with audio and video files. It is
free and
open-source software that is available for a variety of
operating systems,
including
Microsoft Windows,
Linux, and
macOS. If you wish to
use it on a Microsoft Windows system, you can install it with the
Windows
Package Manager known as winget by
opening a command prompt window
and issuing the command winget install "FFmpeg (Essentials Build)".
Microsoft Windows [Version 10.0.26100.7623]
(c) Microsoft Corporation. All rights reserved.
C:\Windows\System32>winget install "FFmpeg (Essentials Build)"
Found FFmpeg (Essentials Build) [Gyan.FFmpeg.Essentials] Version 8.0.1
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://github.com/GyanD/codexffmpeg/releases/download/8.0.1/ffmpeg-8.0.1-essentials_build.zip
██████████████████████████████ 101 MB / 101 MB
Successfully verified installer hash
Extracting archive...
Successfully extracted archive
Starting package install...
Command line alias added: "ffmpeg"
Command line alias added: "ffplay"
Command line alias added: "ffprobe"
Path environment variable modified; restart your shell to use the new value.
Successfully installed
C:\Windows\System32>
If you need to trim the beginning of a video file, such as a .mp4 file,
you can do so using a command of the form
ffmpeg -ss hh:mm:ss -i input.mp4 -c copy output.mp4 where
you specify the point you wish the video to start in the form hh:mm:ss
for hours, minutes, and seconds with -ss and
input.mp4 is the file you wish to trim and output.mp4
is the name you wish to give to the trimmed file. E.g., if I have a video
file, REC-0001-A.mp4, where I wish to discard audio and video up to the 3
minutes and 34 seconds mark in the file, I can use ffmpeg -ss 00:03:34 -i REC-0001-A.mp4 -c copy output1.mp4 to create a new file, output1.mp4,
that omits the first 3 minutes and 33 seconds from the input file. Using the
-c copy option copies the video/audio streams directly,
which is fast but can be less accurate on
keyframes.
[ More Info ]
[/video/ffmpeg]
permanent link