Hot answers tagged

159

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 file so the browser can load it as quickly as possible. pix_fmt – MP4 videos store pixels in different formats. We include this option to specify a specific ...


137

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 [options] url [url...] Options: General Options: -h, --help print this help text and exit --version ...


96

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 reducing video frame size. It's a lot quicker, from about 3 to 5 times quicker than recompressing in my experience. See the ffmpeg docs on scaling for more info. ...


73

OK then I started ffcast, did vim, quit ffcast, then converted .avi→.gif. I ran the recording commands in another terminal. Polished script for your $PATH at the end of this answer. What happened? Capturing FFcast helps the user interactively select a screen region and hands over the geometry to an external command, such as FFmpeg, for screen ...


71

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 $bitrate $newoutfile (CR) Vary the Constant Rate Factor, using: ffmpeg -i $infile -vcodec libx264 -crf 23 $outfile (SZ) Change the video screen-size (for ...


70

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 all .mp4 files in the current dir: find . -maxdepth 1 -iname '*.mp4' -exec ffprobe -v quiet -of csv=p=0 -show_entries format=duration {} \; 149.233333 130....


70

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 FFmpeg you can pass the parameter like this: ffmpeg -i INPUT.mkv -c:v libx265 -preset ultrafast -x265-params lossless=1 OUTPUT.mkv Most x265 switches (...


59

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 -filter_complex hstack output.mp4


58

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 This essentially doubles the size of input1.mp4 by padding the right side with black the same size as the original video, and then places input2.mp4 over the top ...


52

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 would make a DVD quality movie (~700MB - 1GB) and lower CRF values would be higher quality (larger files). An example from the linked article: ffmpeg -i input....


46

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 to a default conversion : ffmpeg -i input.mp4 output.mp4 In my case it reduced the bitrate of both the video and audio (you can check and compare the input ...


46

In my case, using ffmpeg directly did the trick and provided the best result: $ ffmpeg -f gif -i infile.gif outfile.mp4


35

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 will copy the audio stream keeping the original codec.


34

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 information. To get, for example, the length, resolution, codec and dimensions use: $ $ mediainfo "The Blues Brothers.mp4" | grep -E 'Duration|Format |Width|Height' ...


33

Pull out the image captures (these are 100 pixels tall, and keep aspect ratio), the rate (-r) is per-second (this yields one frame every ~5 minutes), this also adds time stamp to output image. ffmpeg -i MOVIE.mp4 -r 0.0033 -vf scale=-1:120 -vcodec png capture-%002d.png Then use ImageMagick to build your gallery image: montage -title "Movie Name\nSubtitle"...


29

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 file should be something like this: ExifTool Version Number : 9.60 File Name : video_file.mp4 Directory : . ...


28

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 video. Replace that number for the number of images you want to get per second. -f image2 force image output format, you may probable be able to omit this since ...


28

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]" \ -map "[v]" -map "[a]" -ac 2 output.mp4 hstack will place each video side-by-side. amerge will combine the audio from both inputs into a single, multichannel ...


27

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 the name of your input file.


23

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.png #Generate gif using palette ffmpeg -i $inputFile -i tmp_palette.png -loop 0 -filter_complex "fps=$FPS,scale=$WIDTH:-1:flags=lanczos[x];[x][1:v]paletteuse" ...


22

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.mp4 With a reasonably recent ffmpeg, you can resize your video with these options: ffmpeg -i in.mp4 -vf scale=720:480 out.mp4 You can set the width or height ...


21

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. recordmydesktop works fine. Tested on Ubuntu 18.04. Related questions: https://askubuntu.com/questions/536563/screen-recorder-webcam https://askubuntu.com/...


20

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 10 -b:v 500k -f matroska - | mplayer - -idle -demuxer matroska where -an turns off audio encoding. If you want audio, replace -an with -f alsa -ac 1 -i hw:3 (...


18

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 there is another option to use a Docker container and bind the folder with the file into the container and fix it that way. You can use the included Dockerfile to ...


17

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 GRUB_GFXPAYLOAD_LINUX=keep replacing 1280x800 with the desired resolution. Then: echo "echo FRAMEBUFFER=y" | sudo tee /etc/initramfs-tools/conf.d/splash sudo ...


16

ddrescue You can try ddrescue. I read recommendation for it, but I do not have experience. There are two programs called ddrescue (see https://askubuntu.com/questions/211578/whats-the-difference-between-ddrescue-gddrescue-and-dd-rescue). Gnu ddrescue is the newer one and designed to overcome some of the problems in the older ddrescue. Gnu ddrescue uses a ...


16

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 0 ] && i=$? du= f= then durl \! \" \# \$ \% \& \' \( \) \* \ \+ \, \/ \: \; \= \? \@ \[ \] : &...


16

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 audio.wav backwards.wav reverse Cat video frames in reverse order to FFmpeg as input $ cat $(ls -t *jpg) | ffmpeg -f image2pipe -vcodec mjpeg -r 25 -i - -i ...


15

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/commit/?id=088ead25524583e2200aa99111bea2f66a86545a More information on the V4L metadata interface can be found here: https://linuxtv.org/downloads/v4l-dvb-apis/...


14

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 bash script meant to create video contact sheets (previews) aka thumbnails or previews of videos. Any video supported by mplayer and ffmpeg can be used by this ...


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