Video manipulating from the command line
There are several applications and online tools that can be used to convert, extract, resize, etc video content under GNU/Linux desktops. The following post focuses on some command line utilities aka CLI tools.
Download video from the web (ytdl)
The ytdl
CLI tool is part of the pafy
python package. Install with pip install pafy
command from a terminal. With ytdl
one can download a video from Youtube. Checkout available options with ytdl -h
(help).
- Search for available formats with
-s
option:
λ pepin ~ → ytdl https://youtu.be/tlgBgZGDmYs -s
Stream Type Format Quality Size
------ ---- ------ ------- ----
1 normal mp4 [640x360] 12 MB
2 normal mp4 [1280x720] 25 MB
3 audio webm [160k] 3 MB
4 audio m4a [128k] 3 MB
5 audio webm [70k] 2 MB
6 audio webm [50k] 1 MB
- Download the chosen format (
-n N
) to folder of your choice (-o O
).O
is a path string like~/Downloads
or whatever. In the example below I have downloaded a video mp4 (640x360) stream tojimmy.mp4
file that is located in~/Downloads/jimmy/
directory.
λ pepin ~ → ytdl https://youtu.be/tlgBgZGDmYs -n 1 -o ~/Downloads/jimmy/jimmy.mp4
-Downloading 'Jimmy Takes a Wild Ride | Yellowstone Season 1 | Paramount Network.mp4' [13,001,347 Bytes]
-Quality: 640x360; Format: mp4
Done
youtube-dl
, the Big Gun
youtube-dl
is a more general and much more complex tool compared to ytdl
. It is available from package managers of major Linux distros. On Arch based systems you can use sudo pacman -S youtube-dl
command to install. Visit project page for alternative install methods and detailed documentation.
Download subtitles from Youtube with youtube-dl
There is a --list-subs
option that is used to list available languages and formats. After you found your preferred language with youtube-dl --list-subs URL
command, you can proceed like this.
youtube-dl --write-sub --sub-lang en --skip-download https://youtu.be/tlgBgZGDmYs
The above command downloads an (English) plain text file in vtt format and skipping the video download. You can add this vtt file to video players (such as mpv) to show subtitles or edit/analyse the text itself.
Cut out part of a video
You have to download the whole video (either with ytdl or youtube-dl) and use ffmpeg.
However, there is an easy to use bash script based on ffmpeg
. The script was written by a reddit user. Download it from Dropbox to a folder at your $PATH
(e.g. ~/.local/bin) and give executable permission with chmod +x
.
usage: vcp [ --scale WIDTH:HEIGHT ] [ --aspect X:Y ] START END INFILE OUTFILE
Copies part of video file INFILE to OUTFILE, starting at time START, and ending
at time END. Only one video and one audio stream is copied (see the ffmpeg
docs for how it chooses the streams, but ffmpeg defaults to the highest quality
streams).
START/END have the format [HH:][MM:]SS[.s...], where HH is hours, MM is
minutes, SS is seconds, and s is a decimal fraction of a second. If
STARTTIME/ENDTIME is '-', the actual start/end (respectively) time of the
video is used.
--aspect => Sets the aspect ratio at the container level. Does not
transcode video.
--scale => Scales video to new WIDTH and HEIGHT (in pixels) without
changing the aspect ratio. NOTE: This transcodes the video!
The next example cut out 7 seconds from jimmy.mp4 that I have downloaded previously.
vcp 1:03 1:10 jimmy.mp4 jimmy-out1.mp4
However, for some reasons I couldn’t use aspect
and scale
options.
Create a slideshow-like video
This is how Luke Smith does with imagemagick
and ffmpeg
.
Related CLI projects
- you-get - a python based command-line utility to download media contents (videos, audios, images) from the Web.
- ytdl-npm - is a youtube downloader written in Javascript. Browse source at Github. Naming is somewhat confusing. This is different from aforementioned python’s pafy library, that also provides a command line tool (ytdl) for downloading Youtube content.
GUI video recording apps
- OBS
- simplescreenrecorder (lightweight qt app)