Hot answers tagged

82

Use the crop filter: ffmpeg -i in.mp4 -filter:v "crop=out_w:out_h:x:y" out.mp4 Where the options are as follows: out_w is the width of the output rectangle out_h is the height of the output rectangle x and y specify the top left corner of the output rectangle Original image Original 320x240 image Example 1 To crop a 80×60 section, starting ...


24

The -loop option is specific to the image file demuxer and gif muxer, so it can't be used for typical video files, but you can use the concat demuxer. Concat demuxer Make a text file. Contents of an example text file to repeat 4 times. $ cat list.txt file 'input.mp4' file 'input.mp4' file 'input.mp4' file 'input.mp4' Then run ffmpeg: ffmpeg -f concat ...


21

using the scale filter will do it, but there is a bit more to it. ffmpeg -i input.mov -vf scale=720x406 output.mov will create a movie with the required pixel dimensions, but if you look at the output you'll find that it adds information into the metadata so that it will play back at the same aspect ratio as the original, by using non-square pixels. So ...


10

I have a large set of jpgs that I want to convert to a video losslessly You can probably just mux the jpg images: ffmpeg -framerate 30 -i input%03d.jpg -codec copy output.mkv Then compare the md5sums of each frame with the framemd5 muxer: $ ffmpeg -i input%03d.jpg -f framemd5 - 0, 0, 0, 1, 460800, ...


10

You can do a simple image overlay using the following syntax: ffmpeg -i input.mp4 -i image.png \ -filter_complex "[0:v][1:v] overlay=25:25:enable='between(t,0,20)'" \ -pix_fmt yuv420p -c:a copy \ output.mp4 overlay=25:25 means we want to position the image 25px to the left and 25px down, originating from the top left corner. enable='between(t,0,20)' ...


10

Choose your license FFmpeg is licensed under the GNU Lesser General Public License (LGPL) version 2.1 or later. Some features are covered by the GNU General Public License (GPL) version 2 or later. If those parts get used the GPL applies to all of FFmpeg. See LICENSE.md in the source to see a list of GPL parts of FFmpeg and which external libraries require ...


10

Use drawbox for the box, and drawtext for the text. ffmpeg -i input.mp4 -vf \ "format=yuv444p, \ drawbox=y=ih/PHI:color=black@0.4:width=iw:height=48:t=max, \ drawtext=fontfile=OpenSans-Regular.ttf:text='Title of this Video':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th, \ format=yuv420p" \ -c:v libx264 -c:a copy -movflags +faststart output.mp4 ...


9

concat filter This method is best if you need to perform additional filtering: Use the trim, atrim, setpts, asetpts, and concat filters: ffmpeg -i input -filter_complex \ "[0:v]trim=60:65,setpts=PTS-STARTPTS[v0]; \ [0:a]atrim=60:65,asetpts=PTS-STARTPTS[a0]; \ [0:v]trim=120:125,setpts=PTS-STARTPTS[v1]; [0:a]atrim=120:125,asetpts=PTS-STARTPTS[a1]; \ ...


8

FFmpeg is probably being used more than you believe. I think the BBC uses it for some workflows, there is evidence that Laika and Weta may use it, and there is a fork called FFmbc which is targeted for professional broadcast usage. YouTube probably uses FFmpeg to decode as shown by some unique decoding issues (but this was several years ago that I read ...


7

ffmpeg has removed their x264 presets so the -vpre setting doesn't work any more. Now, I have a script for converting video files to a format my Cellphone can handle. ffmpeg -i input.avi -sws_flags lanczos+accurate_rnd -vf "scale=320:240" -c:v libx264 -crf 20 -preset veryslow -profile:v main -tune fastdecode -c:a copy output.mkv I'll explain each option ...


7

A videofilter in ffmpeg always has to modify pixel information hence the reason why you need to re-encode. It seems logical at first that you wouldn't have to do this when cropping but the way lossy video codecs work makes this pretty impossible without re-encoding everything. They usually don't see an array of pixel information but a much more complex ...


7

You could possibly use the curves filter. It has a lighter preset: ffmpeg -i input -vf curves=preset=lighter -c:a copy output The red, green, and blue components can be adjusted separately. The following is the same as what the lighter preset uses: curves=r='0.4/0.5':g='0.4/0.5':b='0.4/0.5' Additionally you can make your own curves preset in ...


6

Besides the workaround in my comment, you should be able to use this syntax from the ffmpeg documentation: ffmpeg -f image2 -pattern_type glob -i '*.png' out.avi The quotes are important, you need ffmpeg to see the *, not have the shell expand it.


6

From http://www.ffmpeg.org/faq.html: If you have large number of pictures to rename, you can use the following command to ease the burden. The command, using the bourne shell syntax, symbolically links all files in the current directory that match *jpg to the ‘/tmp’ directory in the sequence of ‘img001.jpg’, ‘img002.jpg’ and so on. x=1; for i in *jpg; do ...


6

I suspect you are having problems because you are trying to overwrite the input file with the output, ffmpeg just doesn't work that way. For a single file: ffmpeg -i input.avi -an -c:v copy output.mkv To do every file in a directory, you can use a for loop. For every `file.avi``in the working directory, this command will create an output called ...


6

I'm using the below code to do the same thing. ffmpeg -framerate 30 -i img%03d.png -c:v libx264 -pix_fmt yuv420p -crf 23 output.mp4 This reads the input at 30 fps (the -framerate 30 option) and encodes it using the libx264 codec with constant rate factor of 23 (the -crf 23 option).


6

Usage differences Note: ffmbc/ffmpeg will refer to the tools, while FFmbc/FFmpeg will refer to the projects themselves and/or each whole collection of tools and libraries. There are syntax differences including: ffmbc uses the old, confusing -newaudio option while ffmpeg can just use -map. ffmbc does not support -codec or -c, so instead all stream types ...


6

The default settings for ffmpeg are very low quality, and since you don't specify any codec or quality parameters it's just using the defaults (I don't know why the devs don't fix that because it generates a lot of questions on forums everywhere). Try adding -c:v libx264 -crf 20 -preset slow to the command. -c:v libx264 tells it to use the libx264 ...


6

This is possible but will require scripting. ffprobe will be used to determine the duration of the input, then the countdown and background box will be created by the drawtext filter. A 30 second input will start from 30 and count down to 0. Example: input=input.mp4 duration=$(ffprobe -loglevel error -show_entries format=duration -of default=nw=1:nk=1 ...


6

This should do it: ffmpeg -i input.mp4 \ -filter_complex "[0:v] crop=iw/3:ih:0:0,pad=iw:2*ih [left]; \ [0:v] crop=iw/3:ih:(iw/3)+1:0 [middle]; \ [0:v] crop=iw/3:ih:(2*iw/3)+1:0 [right]; \ [left][middle] overlay=0:main_h/2,pad=iw:(3*ih/2) [out1]; \ [out1][right] overlay=0:(2*main_h/3) [fout] " \ -c:v libx264 -an -map "[fout]" ...


6

The fs parameter will stop the encode once it hits its value. So, if the output hits the 10MB mark while encoding the 15th second, then that's the duration of your output file. If you want to make sure that the entire file is encoded but it doesn't cross the set target size, then use the bitrate method. To accommodate the muxing overhead and other data ...


5

Note: This is for recent FFmpeg, not FFmbc, which doesn't use the same option syntax (yet) You need to use the -profile:v option, which has been introduced in FFmpeg 0.9 (afaik) and is now standard in 1.0. ffmpeg -i input.mp4 -c:v libx264 -preset fast -profile:v baseline out.mov Why? -profile was used (and prioritized) for AAC encoding. It's simply ...


5

This will output a lossless H.264 video where frames will use information from other frames ffmpeg -f image2 -r 30 -i %09d.jpg -vcodec libx264 -profile:v high444 -refs 16 -crf 0 -preset ultrafast a.mp4 Explanation of options: -f image2 - tells ffmpeg to select a group of images -r 30 - tells ffmpeg to encode at 30 frames (or images) per second (change ...


5

I work as an assistant editor on feature films, and use ffmpeg all the time, primarily for two purposes: Transcoding files to be uploaded for producers to view on digital dailies systems (Dax, PIX, etc). I've written up shell scripts that accept property-of and recipient strings as command line input, along with target bitrate, and then generate the ...


5

This should work faster... ffmpeg -ss 1:00 -t 5 -i in.mkv -ss 2:00 -t 5 -i in.mkv \ -filter_complex "[0][1]concat=n=2:v=1:a=1" \ out.mkv There's no need to specify -t on the output. There's no need to split the audio and video before the concat.


5

-preset Use the slowest preset that is fast enough that it does not drop frames. You can see if ffmpeg is dropping frames in the console output (if I recall correctly). Presets are: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow. -crf Use the highest -crf value that still provides an acceptable quality level. Range is 0-51. 0 ...


5

Use it. Nothing else can provide the the same quality per bitrate as x264 (the top-class H.264 encoder) while not taking 10,000 years to encode (x265 'n VP9). Some tips: Use a recent ffmpeg build since development is so active. Static builds are available and easy. Add -movflags +faststart to your command. Once encoding is finished this option will ...


5

Using the latest ffmpeg General users should always use ffmpeg from the current git master branch (the latest code available): When encountering an issue the first thing to do is check to see if you are using a build from git master. It is considered stable. It will have more bug fixes and features. FFmpeg development is very active. If you want to get ...


5

-select_streams If you only want the information from the first video stream, then add this to your command: -select_streams v:0 duration Note that duration may be missing or incorrect; especially with damaged files. You can always compare it with the output of: ffmpeg -i input -f null - Then look at time= in the second to last line. This will decode ...


5

I'm not well-versed with Unix shell scripting, and also only have basic proficiency in Windows scripting, so I can only offer a pseudocode flow of the script: 1) Break up your full video into N-second segments of only audio (into a temporary folder) ffmpeg -i GoProFull.mp4 -vn -c:a copy -segment_time n -f segment GP%03d.mp4 Obviously, this will generate ...



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