Hot answers tagged

215 votes

How to do I convert an animated gif to an mp4 or mv4 on the command line?

Here's what worked for me: ffmpeg -i animated.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video.mp4 movflags – This option optimizes the structure of the MP4 ...
user avatar
  • 2,251
164 votes

How can I reduce a video's size with ffmpeg?

You mentioned wanting to reduce filesize to fit more videos on a mobile device, which is my usecase as well. All the answers here are for reducing the compression quality but nobody has mentioned ...
user avatar
  • 1,821
141 votes
Accepted

Watch YouTube videos in terminal

You can download videos and/or just the audio and then watch/listen to them using youtube-dl. The script is written in Python and makes use of ffmpeg I believe. $ youtube-dl --help Usage: youtube-dl [...
user avatar
  • 344k
102 votes

How can I reduce a video's size with ffmpeg?

I tested most of the other proposed answers to this question. The test data conclusions are below. These are the proposed answers that I tested: (BR) Modify the bitrate, using: ffmpeg -i $infile -b $...
user avatar
93 votes

Merge two video clips into one, placing them next to each other

To be honest, using the accepted answer resulted in a lot of dropped frames for me. However, using the hstack filter_complex produced perfectly fluid output: ffmpeg -i left.mp4 -i right.mp4 -...
user avatar
84 votes
Accepted

Get total duration of video files in a directory

I have no .ts here but this works for .mp4. Use ffprobe (part of ffmpeg) to get the time in seconds, e.g: ffprobe -v quiet -of csv=p=0 -show_entries format=duration Inception.mp4 275.690000 so for ...
user avatar
  • 72.8k
80 votes

How can I reduce a video's size with ffmpeg?

Note that it seems that ffmpeg already performs some optimization when ran without options, so before trying to use settings you don't understand or deciding to explicitly lose information, give a try ...
user avatar
77 votes

Re-encoding video library in x265 (HEVC) with no quality loss

From my own experience, if you want absolutely no loss in quality, --lossless is what you are looking for. Not sure about avconv but the command you typed looks identical to what I do with FFmpeg. In ...
user avatar
  • 919
72 votes
Accepted

Merge two video clips into one, placing them next to each other

ffmpeg \ -i input1.mp4 \ -i input2.mp4 \ -filter_complex '[0:v]pad=iw*2:ih[int];[int][1:v]overlay=W/2:0[vid]' \ -map '[vid]' \ -c:v libx264 \ -crf 23 \ -preset veryfast \ output.mp4 ...
user avatar
  • 7,202
60 votes

How can I reduce a video's size with ffmpeg?

Unless you're looking for a specific bit rate, I'd recommend the -crf option. This is most commonly used for x264 encoding as described in this article. In short: a constant rate factor (CRF) of 23 ...
user avatar
  • 767
52 votes

How to do I convert an animated gif to an mp4 or mv4 on the command line?

In my case, using ffmpeg directly did the trick and provided the best result: $ ffmpeg -f gif -i infile.gif outfile.mp4
user avatar
  • 1,021
44 votes
Accepted

Get metadata from a video in the terminal

On a Debian-based system (but presumably, other distributions will also have mediainfo in their repositories): $ sudo apt-get install mediainfo $ mediainfo foo.mp4 That will spew out a lot of ...
user avatar
  • 215k
37 votes
Accepted

Command to extract audio from video without conversion

ffmpeg -i video.mp4 -vn -acodec copy audio.aac Here’s a short explanation on what every parameter does: -i option specifies the input file. -vn option is used to skip the video part. -acodec copy ...
user avatar
  • 3,629
35 votes

How to extract images from video file?

Try with ffmpeg ffmpeg -i inputfile.avi -r 1 -f image2 image-%3d.jpeg You can read the documentation here -i inputfile.avi The video input file is inputfile.avi -r 1 extract 1 image per second of ...
user avatar
  • 3,804
34 votes

Get metadata from a video in the terminal

You can use exiftool. To install it run: sudo apt-get install libimage-exiftool-perl Then to get the metadata from mp4 file run: exiftool video_file.mp4 > medatata.txt The output saved in the ...
user avatar
  • 3,007
32 votes

Merge two video clips into one, placing them next to each other

This can be done with just two filters and the audio from both inputs will also be included. ffmpeg -i left.mp4 -i right.mp4 -filter_complex \ "[0:v][1:v]hstack=inputs=2[v]; \ [0:a][1:a]amerge[a]" \ ...
user avatar
  • 884
28 votes

How do I watch my webcams feed on Linux?

guvcview This program is ideal for screencasts, as it can show just the camera on a window and nothing else: sudo apt-get install guvcview guvcview Then just use any screen recorder to make a feed. ...
user avatar
28 votes

Convert a video to a fixed screen size by cropping and resizing

ffmpeg -i input.file -vf "scale=(iw*sar)*max(720/(iw*sar)\,480/ih):ih*max(720/(iw*sar)\,480/ih), crop=720:480" -c:v mpeg4 -vtag XVID -q:v 4 -c:a libmp3lame -q:a 4 output.avi Replace "input.file" with ...
user avatar
  • 381
25 votes

Can I pipe /dev/video over ssh

If you have a low bandwidth I recommend compression of the video stream (still works in 2020). with ffmpeg and mplayer ssh USERNAME@REMOTEHOST ffmpeg -an -f video4linux2 -s 640x480 -i /dev/video0 -r ...
user avatar
  • 15.9k
24 votes
Accepted

How to recover a broken mp4 file: moov atom not found

You can try and use Untrunc to fix the file. Restore a damaged (truncated) mp4, m4v, mov, 3gp video. Provided you have a similar not broken video. you may need to compile it from source, but ...
user avatar
  • 3,628
23 votes

Convert OGV video to GIF animation?

Simple script with good quality Script: inputFile=$1 FPS=15 WIDTH=320 #Generate palette for better quality ffmpeg -i $inputFile -vf fps=$FPS,scale=$WIDTH:-1:flags=lanczos,palettegen tmp_palette....
user avatar
  • 333
23 votes
Accepted

Convert a video to a fixed screen size by cropping and resizing

I'm no ffmpeg guru, but this should do the trick. First of all, you can get the size of input video like this: ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width in....
user avatar
  • 3,188
23 votes
Accepted

Multiple /dev/video for one physical device

The second device provides metadata about the video data from the first device. The new devices were introduced by this patch: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/...
user avatar
19 votes

Fast tool to generate thumbnail video galleries for command line

I like using an easy to use unix command line bash script called VCS - Video Contact Sheet. Their official page: http://p.outlyer.net/vcs/ Its a lot easier to use even easier than a GUI ''It is a ...
user avatar
18 votes

How to set the resolution in text consoles (troubleshoot when any `vga=...` fails)

For newer Debian & Ubuntu distros using nvidia, I had to do the following: First, edit /etc/default/grub. Change the following line: #GRUB_GFXMODE=640x480 to this: GRUB_GFXMODE=1280x800 ...
user avatar
  • 1,392
18 votes

How do I watch my webcams feed on Linux?

ffplay /dev/video0 is one of the simpler methods, and will work provided you have ffmpeg installed. To install, use sudo apt install ffmpeg.
user avatar
18 votes

How can I list the available video modes for my screen?

Have you tried "xrandr" ? When run without any option, xrandr shows the names of different outputs available on the system (LVDS, VGA-0, etc.) and resolutions available on each Demo output :* ...
user avatar
  • 413
17 votes

Get metadata from a video in the terminal

You can do this with the FFmpeg project: ffprobe -hide_banner 'Yagya (IS) - Topic-Choose-Hlw4YohQzr4.webm' Result: Input #0, matroska,webm, from 'Yagya (IS) - Topic-Choose-Hlw4YohQzr4.webm': ...
user avatar
  • 5,652
17 votes

How can I reverse a video clip?

From https://stackoverflow.com/questions/2553448: Dump all video frames $ ffmpeg -i input.mkv -an -qscale 1 %06d.jpg Dump audio $ ffmpeg -i input.mkv -vn -ac 2 audio.wav Reverse audio $ sox -V ...
user avatar
  • 3,013
16 votes

Watch YouTube videos in terminal

So, with Terminology (probably the very best thing that ever happened to a terminal emulator, by the way) at the time of this writing the following works: ytplay() ( init() if [ "${#1}" -gt ...
user avatar
  • 55.5k

Only top scored, non community-wiki answers of a minimum length are eligible