Suppose you have a file called concat.txt
with the following content:
# This is a comment
file 'video.webm'
inpoint 00:03:02.57
outpoint 00:10:37.44
# This is another comment
file 'video.webm'
inpoint 00:14:53.89
outpoint 00:23:29.26
# This is another comment
file 'video.webm'
inpoint 00:25:32.67
outpoint 00:32:21.28
This file specifies video segments, based on their filenames, start-point and end-points, to be concatenated in a final video with the following command.
$ ffmpeg -f concat -i concat.txt -c copy out.webm
mpv-concat helps the creation of such a file. With mpv-concat you can interactively select segments of videos from your mpv video player.
If a file named concat.txt
exists in the current working directory, it
is read by this script and video segments are get from it, as specified
by ffmpeg-formats(1).
After opening a video file with mpv, you can create more video segments
in addition to the ones read from concat.txt
. Then, after writing the
segments to disk, a new concat.txt
file is created in the directory
the mpv command was ran.
Set time.
In the video screen, press Ctrl + T
to grab the first timestamp and
then press Ctrl + T
again to get the second timestamp. This process
will generate a time range, which represents a video segment. Repeat
this process to create more segments.
Show segments.
To see all the segments made so far, press Ctrl + P
. All segments will
appear in the terminal in order of creation, with their corresponding
timestamps. Incomplete segments will show up as “Segment N in progress”,
where N is the segment number.
Reset segment.
To reset an incomplet segment, press Ctrl + R
. If the first part of
a segment was created at the wrong time, this will reset the current
segment.
Delete segment.
To delete a whole segment, start the segment deletion mode by pressing
Ctrl + D
. When in this mode, it's possible to press Ctrl + NUM
,
where NUM is any number between 0 inclusive and 9 inclusive. For each
Ctrl + NUM
pressed, a number will be concatenated to make the final
number referring to the segment to be removed, then press Ctrl + D
again to stop the segment deletion mode and delete the segment
corresponding to the formed number.
Example 1: Deleting segment number 3
Ctrl + D # Start segment deletion mode
Ctrl + 3 # Concatenate number 3
Ctrl + D # Exit segment deletion mode
Example 2: Deleting segment number 76
Ctrl + D # Start segment deletion mode
Ctrl + 7 # Concatenate number 7
Ctrl + 6 # Concatenate number 6
Ctrl + D # Exit segment deletion mode
Preview concatenation.
To preview how the segment concatenation will look like, press Ctrl + V
to enter the preview mode. In this mode, the player will jump between
segments. To exit from the preview mode, press Ctrl + V
again.
Write concat file.
To write the concat.txt
file, to be used by ffmpeg, press Ctrl + W
.
It's important that there are at least one segment, otherwise a blank
file will be created.
-
This script prevents the mpv player from closing when the video ends, so that the segments don't get lost. Keep this in mind if there's the option
keep-open=no
in the current config file. -
This script will also silence the terminal, so the script messages can be seen more clearly.
-
The
concat.txt
file generated by this script is slightly different from the one illustrated at the beginning of thisREADME
. In special, the timestamps are in seconds rather in theHH:MM:SS.ss
form. Both forms are supported though (but using seconds is more precise).
Everytime a timestamp is grabbed, a text will appear on the screen
showing the selected time. When Ctrl + P
is pressed, besides showing
the segments in the terminal, it will also show on the screen the total
number of cuts (or segments) that were made. When pressing Ctrl + W
,
a message will be shown on the screen and the terminal telling that the
concat.txt
file was written.
Note: Every message that appears on the terminal has the log level of 'info'.
-
Thanks to pvpscript for writing mpv-video-splice, on which this script and this README are based.
-
Thanks to unusualpepe for writing mpv-multiloop, on which the preview functions are based.