Hot answers tagged

116

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


105

Here is the one line solution: ffmpeg -i input.mp4 -c copy -map 0 -segment_time 00:20:00 -f segment output%03d.mp4 Please note that this does not give you accurate splits, but should fit your needs. It will instead cut at the first frame after the time specified after segment_time, in the code above it would be after the 20 minute mark. If you find that ...


97

ffmpeg seems to have a new option -to in the documentation: -to position (input/output) Stop writing the output or reading the input at position. position must be a time duration specification, see (ffmpeg-utils)the Time duration section in the ffmpeg-utils(1) manual. -to and -t are mutually exclusive and -t has priority. Sample command with ...


81

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


78

This worked for me when I tried it on a mp3 file. $ ffmpeg -i somefile.mp3 -f segment -segment_time 3 -c copy out%03d.mp3 Where -segment_time is the amount of time you want per each file (in seconds). References Splitting an audio file into chunks of a specified length 4.22 segment, stream_segment, ssegment - ffmpeg documentation


71

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


65

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


63

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


60

A simple 1 liner solution: find -name "*.flac" -exec ffmpeg -i {} -acodec libmp3lame -ab 128k {}.mp3 \; http://lewisdiamond.blogspot.ca/2012/01/converting-flac-to-mp3.html Note that this will be applied recursively in the given directory. I.e. if you run this from your Music folder, it will convert all flacs from subfolders and produce a .mp3 next to it. ...


54

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


52

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


41

Try this: for i in *.flac ; do ffmpeg -i "$i" -acodec libmp3lame "$(basename "${i/.flac}")".mp3 sleep 60 done


40

You can use: ldconfig -p | grep libavfilter If there is no output library is not installed. I am not sure if this is 100% reliable. At least in man page of ldconfig for option -p: Print the lists of directories and candidate libraries stored in the current cache.


36

To split a big audio file into a set of tracks with varying lengths, you can use the following command: # -to is the end time of the sub-file ffmpeg -i BIG_FILE -acodec copy -ss START_TIME -to END_TIME LITTLE_FILE For example, I broke up a single .opus file of the Inception Original Soundtrack into sub-files using this text file containing start, end, name:...


34

Ok, I was probably a little quick to ask here but for the sake of future reference here is the answer: One should pass the flag -acodec alac to ffmpeg for a lossless conversion between FLAC and ALAC: ffmpeg -i track.flac -acodec alac track.m4a


30

If your HDD allows, you can try to do it this way: First write uncompressed file: ffmpeg -f x11grab -s SZ -r 30 -i :0.0 -qscale 0 -vcodec huffyuv grab.avi here SZ is your display size (e.g. 1920x1080). After that you can compress it at any time you want: ffmpeg -i grab.avi grab.mkv Of course, you can change compression, select codec and so on.


30

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.


26

The best way that I've seen is by adding the -l flag to silence as follows: sox in.wav out6.wav silence -l 1 0.1 1% -1 2.0 1% I've copied this command from Example 6 of this very useful blog post called The Sox of Silence


23

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


23

The stream selection default behavior only selects one stream per type of stream, so inputs with multiple audio streams will create an output with one audio stream. To disable this behavior and manually choose desired streams use the -map option. These examples use -c copy to stream copy (re-mux) from the input to to the output. No re-encoding occurs. ...


20

If you want a one-liner for FFMPEG that generates a video that plays at 1 frame per second, what you want to do is specify framerates for both input and output, like this: ffmpeg -r 1 -i data/input-%4d.png -pix_fmt yuv420p -r 10 data/output.mp4 The -r 1 means the video will play at 1 of the original images per second. The -r 10 means the video will play ...


19

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


18

As seen in man mpv: --sub-auto=<no|exact|fuzzy|all>, --no-sub-auto Load additional subtitle files matching the video filename. The parameter specifies how external subtitle files are matched. exact is enabled by default. no Don't automatically load external subtitle files. exact Load the ...


14

As far as i understand it's required to replace avi-container with mp4 one (formally - ISO base media file format ISO/IEC 14496-12 ). if you run the following command: ffmpeg -i input.avi -y output.mp4 In such case ffmpeg re-encodes elementary streams within input.avi (cahnge containers and re-encode is the default mode of ffmpeg). It's worth noticing ...


14

If you want to crop and scale in one go, you can make a crop-then-scale filterchain like so: ffmpeg -i SomeInput.mp4 -vf "crop=in_h*9/16:in_h,scale=-2:400" -t 4 SomeOutput.mp4 The above first crops a video to 16:9 portrait, then scales to 400px high x the appropriate (even number) width.


13

I've recently gone through the trouble of Transcoding my whole video catalog over to HEVC. I use https://github.com/FallingSnow/h265ize with the following settings. h265ize -v -m medium -q 20 -x --no-sao --aq-mode 3 --delete --stats -v - Verbose Output -m medium - Medium encode speed (smaller higher quality, anything slower I find is not worth the time/...


13

I came to this topic for the message, just to add one tip for users, I found out that if the filename itself has ':' in it would cause the problem, as some programs generate files with the time stamp like "audio 12:34:14.ogg"


12

ffmpeg is an OS agnostic tool that is capable of determining if a video file has been completely downloaded. The command below instructs ffmpeg to read the input video and encode the video to nothing. During the encoding process, any errors such as missing frames are output to test.log. ffmpeg -v error -i FILENAME.mp4 -f null - 2>test.log If a video ...


11

I compressed a 40-minute HD video presentation from 505MB to 183MB That's like going from 100MB → 36MB. Original video was HD and output was almost zero noticeable difference. It's a video file "I'd like to keep around, but HD is overkill." Here's the command I used with reasons: ffmpeg -n -loglevel error -i inputfile.mp4 -vcodec libx264 -crf 28 -...


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