User Tools

Site Tools


en:ressources:astuces:ffmpeg

FFMPEG Video Encoding

- Convert Sony's HD MTS format into MP4

see: http://flash.flowplayer.org/forum/7/12671 This works on Ubuntu 12.10 with ffmpeg 0.8.3-6ubuntu2

$ ffmpeg -y -i input.MTS -threads 6 -ar 44100 -ab 96k -acoder aac -ac 2 -vcodec libx264 -level 41 -crf 20 -bufsize 20000k -maxrate 25000k -g 250 -r 20 -s 1280x544 -coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8   -subq 7 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -bf 16 -b_strategy 1 -bidir_refine 1 -refs 6 -deblockalpha 0 -deblockbeta 0 output.mp4

- Cut a video

ffmpeg -ss 545 -t 2587 -i input.mp4 -sameq  output.mp4

<note>-ss and -t must be inserted before -i, because ffmpeg takes all argument that precede -i as input parameters, and all subsequent ones as output parameters</note>

- Clean up the audio

I recorded a video by a fountain once. The image was great, but my voice was hard to hear because of the fountain noise. I got asked to reshoot it. That's would have been the last resort. Fortunately, ffmpeg and audacity came to the rescue !

- Split the audio and video in two files

$ ffmpeg -i film.MTS -vcodec copy -an film-video.mp4
$ ffmpeg -i film.MTS film-audio.wav

- Process the audio in audacity

  • noise reduction
  • amplification

- Reassemble the audio & video together

$ ffmpeg -i film-video.mp4 -i film-audio-processed.wav -vcodec copy film-clean.mp4

- Make a video from multiple jpegs

From a GoPro camera that takes a photo every two seconds, make a video that has 10 frames per seconds.

$ ffmpeg -r 10 -pattern_type glob -i 'G0010*.JPG' -c:v libx264 -s 1920x1080 ~/video.mp4

- Put two videos next to each other

This works if both videos are the same size. source1 will be on the left, source2 on the right.

ffmpeg -i source1.mp4 -i source2.mp4 -filter_complex '[0:v]setpts=PTS-STARTPTS, pad=iw*2:ih[bg]; [1:v]setpts=PTS-STARTPTS[fg]; [bg][fg]overlay=w' -strict -2 -s 1920x1080 fly2.mp4

- Concat splitted GoPro videos

Create a file that contains the video portions, and call ffmpeg with that file in argument.

$ cat kayak.txt
file 'GOPR1006.MP4'
file 'GP011006.MP4'
file 'GP021006.MP4'
file 'GP031006.MP4'

$ ffmpeg -f concat -i kayak.txt -c copy kayak-long.mp4

- Accelerate a video

The following filter will accelerate the video 20 times (0.05xPTS). ffmpeg maintain the original framerate, and achieve acceleration by keeping 1 frame every 20. Increase the framerate with -r to reduce that effect.

$ ffmpeg -i kayak-long.mp4 -s 1920x1080 -r 60 -strict -2 -filter:v "setpts=0.05*PTS" -an kayak.mp4

- Screencast, with sound

The command below will take a video of the screen, starting at pixels x=0, y=1200, and filming a size of 1600×900. It will record the audio from pulseaudio, and save it into output.mp4.

$ ffmpeg -video_size 1600x900 -framerate 25 -f x11grab -i :0.0+0,1200 -f alsa -ac 2 -i pulse -strict -2 output.mp4

- Screencast, no sound, term size 104*38

ffmpeg -video_size 1450x850 -framerate 10 -f x11grab -i :0.0+1100,550 -strict -2 -vcodec libx264 -threads 0 output.mp4

- Animated GIF from MP4

First, convert the video to individual PNG files, then use imagemagick convert's to make the GIF.

$ ffmpeg -i mig-console-demo.mp4 -r 5 -compression_level 9 mig-console-demo-%05d.png

$ convert -layers Optimize -resize 800 mig-console-demo*.png mig-console-demo.gif
en/ressources/astuces/ffmpeg.txt · Last modified: 2024/04/17 10:19 by 127.0.0.1