preloader
post-thumb

Last Update: February 24, 2025


BYauthor-thumberic


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:

bash
sudo apt update
sudo apt install ffmpeg vlc mencoder mpv

For Fedora / CentOS / RHEL

bash
sudo dnf install ffmpeg vlc mencoder mpv

Working with Video Files Using FFmpeg

Convert Video Formats

Convert a video from MP4 to AVI:

bash
ffmpeg -i input.mp4 output.avi

Convert to WebM (VP9 codec):

bash
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:

bash
ffmpeg -i input.mp4 -q:a 0 -map a output.mp3

Extract audio as a WAV file:

bash
ffmpeg -i input.mp4 -vn -acodec pcm_s16le output.wav

Resize a Video

Resize a video to 1280x720 resolution:

bash
ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4

Compress a Video

Reduce file size while maintaining quality:

bash
ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4

Trim a Video (Without Re-encoding)

Trim the first 30 seconds:

bash
ffmpeg -i input.mp4 -ss 00:00:00 -to 00:00:30 -c copy output.mp4

Trim from 10 seconds to 50 seconds:

bash
ffmpeg -i input.mp4 -ss 00:00:10 -to 00:00:50 -c copy output.mp4

Add Subtitles to a Video

bash
ffmpeg -i input.mp4 -vf subtitles=subtitles.srt output.mp4

Loop a Video

bash
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:

bash
vlc input.mp4

Play a video in fullscreen:

bash
vlc --fullscreen input.mp4

Using MPV

bash
mpv input.mp4

Play a YouTube video directly:

bash
mpv https://www.youtube.com/watch?v=example

Using MPlayer

bash
mplayer input.mp4

Play in fullscreen:

bash
mplayer -fs input.mp4

Download Videos Using YouTube-DL (or yt-dlp)

Install yt-dlp

bash
sudo apt install yt-dlp

Download a YouTube Video

bash
yt-dlp "https://www.youtube.com/watch?v=example"

Download as MP3 (Audio Only)

bash
yt-dlp -x --audio-format mp3 "https://www.youtube.com/watch?v=example"

Screen Recording with FFmpeg

Record the screen at 30fps:

bash
ffmpeg -video_size 1920x1080 -framerate 30 -f x11grab -i :0.0 output.mp4

Record with audio from the microphone:

bash
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:

bash
ffmpeg -i input.mp4 -vf fps=1 frame_%04d.png

Extract a single frame at 5 seconds:

bash
ffmpeg -i input.mp4 -ss 00:00:05 -vframes 1 output.png

Merge Multiple Videos

Merge videos of the same format:

  1. Create a text file listing videos:
bash
echo "file 'video1.mp4'" > list.txt
echo "file 'video2.mp4'" >> list.txt
  1. Merge them:
bash
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:

bash
ffmpeg -h
man vlc
man mplayer

Happy video processing!

Previous Article
post-thumb

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
post-thumb

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.

agico

We transform visions into reality. We specializes in crafting digital experiences that captivate, engage, and innovate. With a fusion of creativity and expertise, we bring your ideas to life, one pixel at a time. Let's build the future together.

Copyright ©  2025  TYO Lab