Hot answers tagged

109

-stream_loop option ffmpeg -stream_loop 3 -i input.mp4 -c copy output.mp4 This can avoid re-encoding because it can use stream copy. 0 means no loop, -1 means infinite loop. This may not work with anything older than FFmpeg 4.0. concat demuxer The concat demuxer allows you to loop an input without needing to re-encode because it can use stream copy. Make ...


88

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 right and 25px down, originating from the top left corner (0:0). enable='between(...


55

Yes, you can use FFmpeg in a commercial product FFmpeg is licensed under the GNU Lesser General Public License (LGPL) version 2.1 or later. It is also available under the General Public License (GPL) version 2 or later. Some features, external libraries (libx264 and libx265 for example), and various filters, require GPL. If those parts get used the GPL ...


48

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 if ...


48

If parts of the file reside on physically bad sectors, or for whatever reason, the OS cannot serve the whole file to FFmpeg, then naturally FFmpeg can't do anything about that. You should get a utility which can ignore those portions and write the salvageable parts to a new file, like ddrescue. Now, if the file protocol is not the cause of errors, you can ...


45

FFmpeg has a reverse video filter and reverse audio filter. For video only: ffmpeg -i /storage/emulated/0/ffvid/frameCount.mp4 -vf reverse reversed.mp4 For audio and video: ffmpeg -i /storage/emulated/0/ffvid/frameCount.mp4 -vf reverse -af areverse reversed.mp4 This filter buffers the entire clip. For larger files, segment the file, reverse each segment ...


44

Add the yadif filter i.e. ffmpeg -i input.vob -vf yadif -c:v libx264 -preset slow -crf 19 -c:a aac -b:a 256k output.mp4 See yadif docs for more info.


44

FFmpeg is indeed a powerful video encoder/decoder tool¹. It operates in the command line, as opposed to using a GUI. Command line is that black window you find by clicking [windows+r] and typing cmd then hitting enter. This is also called "command prompt". Once setup you enter ffmpeg commands in one of these windows to use it. Here are the basic ...


39

These settings helped me to lighten up a dark video using the filter eq, with some added saturation. Syntax: filtername=option1=value1:option2=value2:option3=value3... These can be in any order. Filter ranges and all options: https://ffmpeg.org/ffmpeg-filters.html#eq Preview: ffplay -vf eq=brightness=0.06:saturation=2 INPUT.MOV Render: ffmpeg -i INPUT.MOV -...


34

Image inputs Default frame rate for image inputs is 25. You can change it with the -framerate input option. Example for 24 fps: ffmpeg -framerate 24 -i input_%03d.jpg -vf format=yuv420p output.mp4 -vf format=yuv420p (or the legacy alias -pix_fmt yuv420p) will ensure compatible chroma subsampling for MP4. Otherwise, ffmpeg will try to preserve color fidelity,...


34

Other answers here are only working with the "known" meta keys, for custom/arbitrary meta keys, -map_metadata 0 is not sufficient to keep them all. In my transcoder project, a lot of camera makers like to inject custom meta keys in the MP4/MOV container, and I want to keep them in the transcoded MP4/MOV files. After a lot of head scratching, ffmpeg ...


33

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). Edit: the defaults are now quite sane. With a recent (as in later than 2017) build of ffmpeg you don't need to ...


29

With ffmpeg 2.8.4, the following command creates output.mp4 that is a repeating copy of input.mp4 until the ffmpeg process is stopped: ffmpeg -stream_loop -1 -i input.mp4 -c copy output.mp4 This command won't terminate on its own, and the output file will grow infinitely.


27

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 Breaking down the command: ffmpeg <- call ffmpeg -framerate 30 <- set the input framerate to 30 -i img%03d.png <- read PNG images with filename img001, img002, img003, etc.. ...


25

The image sequence muxer has a start number option, so ffmpeg -i video.webm -start_number 98 image-%03d.png


24

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=fill, \ 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 ...


24

If you only want the information from the first video stream use -select_streams v:0: ffprobe -v error -select_streams v:0 -show_entries stream=width,height,duration,bit_rate -of default=noprint_wrappers=1 input.mp4 Example output: width=640 height=480 duration=10.000000 bit_rate=942704 To see a list all entries use -show_streams and/or -show_format ...


24

Suspend A simple method is to suspend it with ctrl+z. Or you could get the PID with pgrep ffmpeg then use kill -s SIGSTOP <PID> to suspend. Then resume with fg command or kill -s SIGCONT <PID>. Unfortunately this will not survive a reboot. VM If you use a virtual machine, with something like VirtualBox, you could perform your encoding in a ...


24

#1 To simultaneously fade the audio in/out: ffmpeg -i clip.mp4 -vf 'fade=in:0:30,fade=out:960:30' -af 'afade=in:st=0:d=1,afade=out:st=32:d=1' -c:v libx264 -crf 22 -preset veryfast fadeInOut.mp4 The afade times are in seconds. #2 Automatically? No. But see workaround below You can first run ffprobe to get duration. ffprobe -i ...


23

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]; \ [v0]...


23

Answer Use two-pass Constant Quality mode:¹ ffmpeg -i input.mp4 -b:v 0 -crf 30 -pass 1 -an -f webm -y /dev/null ffmpeg -i input.mp4 -b:v 0 -crf 30 -pass 2 output.webm Explanation: Setting the video bitrate to zero while also specifying the CRF (Constant Rate Factor) enables Constant Quality mode which targets a certain perceptual quality level. ...


20

Whenever's there's multiple inputs fed to ffmpeg, and you need one more than video/audio/subtitle stream sent to the output, -map statements are needed. ffmpeg -i $movie.mov -i $sub_en.srt -i $sub_de.srt \ -map 0:v -map 0:a -map 1 -map 2 \ -c:v copy -c:a copy -c:s srt \ -metadata:s:s:0 language=eng -metadata:s:s:1 language=ger \ $output.mkv Since the ...


18

The frames in your H.264 video are grouped into units called GOPs (Group Of Pictures). Inside these GOPs frames are classified into three types: I-frame: frame that stores the whole picture P-frame: frame that stores only the changes between the current picture and previous ones B-frame: frame that stores differences with previous or future pictures ...


17

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 Photoshop, ...


17

On Windows, pressing the "Pause/Break" key (the top-right most key) will pause it. Enter will resume. If it doesn't work, click on the command prompt window to give it focus.


17

You can use ffmpeg, a free command-line tool, to do this. The basic command is ffmpeg -i input.mov -vf "setpts=(PTS-STARTPTS)/30" -crf 18 output.mov The 30 indicates the factor by which the video will be sped up.


16

x264 supports both 8-bit and 10-bit outputs, and you don't have to do anything special. ffmpeg If using ffmpeg you can see what pixel formats and bit depths are supported by libx264: $ ffmpeg -h encoder=libx264 [...] Supported pixel formats: yuv420p yuvj420p yuv422p yuvj422p yuv444p yuvj444p nv12 nv16 nv21 yuv420p10le yuv422p10le yuv444p10le nv20le ...


15

At least on FFmpeg 2.8.x (but oldie should works too) you can use lavfi as input format and complex filter graph using movie and setpts filters as a argument for -i option. Next command doing this work for you: ffmpeg -re -f lavfi -i "movie=filename=input.mp4:loop=0, setpts=N/(FRAME_RATE*TB)" output.mp4 Zero loop= arguments means infinity loop. Values ...


15

r_frame_rate is "the lowest framerate with which all timestamps can be represented accurately (it is the least common multiple of all framerates in the stream)." avg_frame_rate is just that: total duration / total # of frames You can just specify -r 30000/1001 to maintain the average rate (near-abouts). You don't specify which format you're outputting to, ...


14

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 ...


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