
Last Update: February 24, 2025
BYeric
Keywords
Common Useful Video-Related Commands in Linux
Linux provides powerful command-line tools for working with videos. Whether you need to convert, edit, compress, or extract audio, these commands can be incredibly useful. Below is a list of common video-related commands that can help you manage and process videos efficiently.
Install Essential Video Tools on Linux
For Ubuntu / Debian
Before running any commands, you may need to install the necessary tools:
sudo apt update
sudo apt install ffmpeg vlc mencoder mpv
For Fedora / CentOS / RHEL
sudo dnf install ffmpeg vlc mencoder mpv
Working with Video Files Using FFmpeg
Convert Video Formats
Convert a video from MP4 to AVI:
ffmpeg -i input.mp4 output.avi
Convert to WebM (VP9 codec):
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 1M -c:a libopus output.webm
Extract Audio from a Video
Extract audio as an MP3 file:
ffmpeg -i input.mp4 -q:a 0 -map a output.mp3
Extract audio as a WAV file:
ffmpeg -i input.mp4 -vn -acodec pcm_s16le output.wav
Resize a Video
Resize a video to 1280x720 resolution:
ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4
Compress a Video
Reduce file size while maintaining quality:
ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4
Trim a Video (Without Re-encoding)
Trim the first 30 seconds:
ffmpeg -i input.mp4 -ss 00:00:00 -to 00:00:30 -c copy output.mp4
Trim from 10 seconds to 50 seconds:
ffmpeg -i input.mp4 -ss 00:00:10 -to 00:00:50 -c copy output.mp4
Add Subtitles to a Video
ffmpeg -i input.mp4 -vf subtitles=subtitles.srt output.mp4
Loop a Video
ffmpeg -i input.mp4 -stream_loop <loop_count> -c copy output.mp4
-c copy
: Copy the video stream without re-encoding-stream_loop <loop_count>
: Number of times the video should be looped
Play Videos from the Terminal
Using VLC
Play a video:
vlc input.mp4
Play a video in fullscreen:
vlc --fullscreen input.mp4
Using MPV
mpv input.mp4
Play a YouTube video directly:
mpv https://www.youtube.com/watch?v=example
Using MPlayer
mplayer input.mp4
Play in fullscreen:
mplayer -fs input.mp4
Download Videos Using YouTube-DL (or yt-dlp)
Install yt-dlp
sudo apt install yt-dlp
Download a YouTube Video
yt-dlp "https://www.youtube.com/watch?v=example"
Download as MP3 (Audio Only)
yt-dlp -x --audio-format mp3 "https://www.youtube.com/watch?v=example"
Screen Recording with FFmpeg
Record the screen at 30fps:
ffmpeg -video_size 1920x1080 -framerate 30 -f x11grab -i :0.0 output.mp4
Record with audio from the microphone:
ffmpeg -f pulse -i default -f x11grab -r 30 -s 1920x1080 -i :0.0 output.mp4
Extract Frames from a Video
Extract one frame per second:
ffmpeg -i input.mp4 -vf fps=1 frame_%04d.png
Extract a single frame at 5 seconds:
ffmpeg -i input.mp4 -ss 00:00:05 -vframes 1 output.png
Merge Multiple Videos
Merge videos of the same format:
- Create a text file listing videos:
echo "file 'video1.mp4'" > list.txt
echo "file 'video2.mp4'" >> list.txt
- Merge them:
ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4
Conclusion
These are some of the most useful video-related commands in Linux. By mastering ffmpeg
, vlc
, mplayer
, and other tools, you can efficiently manipulate videos right from the command line. If you need more functionality, check each tool's documentation using:
ffmpeg -h
man vlc
man mplayer
Happy video processing!
Previous Article

Feb 25, 2025
Finding the Right Document Processing Tool for Your Workflow
Choosing the right document processing tool depends on your specific workflow needs. Here's a guide to help you find the right tool for your needs.
Next Article

Feb 20, 2025
Exploring AI Video Generation: What KlingAI, Runway, Pika Labs, Luma, Sora, and HailuoAI Offer
In this post, I will show you what KlingAI, Runway, Pika Labs, Luma, Sora, and HailuoAI offer in the field of AI video generation.