alptugan
10/28/2018 - 9:34 AM

FFMPEG

https://www.ostechnix.com/20-ffmpeg-commands-beginners/
http://www.mpabo.com/2014/12/14/ffmpeg-and-x264-encoding-guide/
http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html

# Install brew from
brew.sh

# download ffmpeg binary for 64-bit to your mac
# goto bin folder and run!!!
brew install ffmpeg

# 1- Basic MP4 Video compression
ffmpeg -i name_of_the_video_to_be_compressed.mp4 output_name_of_the_video.mp4

#Calculate the bitrate you need by dividing 1 GB by the video length in seconds. So, for a video of length 16:40 (1000 seconds), use a bitrate of 1000000 bytes/sec:
ffmpeg -i input.mp4 -b 1000000 output.mp4

#Additional options that might be worth considering is setting the Constant Rate Factor, which lowers the average bit rate, but retains better quality. Vary the CRF between around 18 and 24 — the lower, the higher the bitrate.
ffmpeg -i input.mp4 -vcodec libx264 -crf 20 output.mp4
ffmpeg -i input.mkv -vf "scale=iw/2:ih/2" half_the_frame_size.mkv
# basic conversion
ffmpeg -i MVI_6654.MOV firsttry.gif

# -t flag to specify duration of the file
ffmpeg -t 2 -i MVI_6654.MOV secondtry.gif

# -r for framerate, the order of the flags affects the output file, keep in mind
ffmpeg -t 2 -i MVI_6654.MOV -r "15" thirdtry.gif

#The -ss flag defines the starting point. Your seconds can be decimals. If you have a longer video and want to define the starting position in hours, minutes, seconds, you can use “hh:mm:ss” format, like “00:00:03” instead of “3”
ffmpeg -t 3 -ss 0.5 -i MVI_6663.MOV -r "15" fourthtry.gif

# To reduce file size; We have to generate a custom color palette so we don’t waste space storing colors we don’t use (the gif file format is limited to 256 colors):
# -vf is a way to invoke filters on our video. so we can describe fps and scale here
ffmpeg -ss 2.6 -t 1.3 -i MVI_7035.MOV -vf fps=15,scale=320:-1:flags=lanczos,palettegen palette.png

ffmpeg -ss 2.6 -t 1.3 -i MVI_7035.MOV -i palette.png -filter_complex "fps=15,scale=400:-1:flags=lanczos[x];[x][1:v]paletteuse" sixthtry.gif

#################################
# Another method from giphy.com #
#################################
# 1- Generate color palette
ffmpeg -ss 61.0 -t 2.5 -i StickAround.mp4 -filter_complex "[0:v] palettegen" palette.png
# 2- Convert to gif using the color palette
ffmpeg -ss 61.0 -t 2.5 -i StickAround.mp4 -i palette.png -filter_complex "[0:v][1:v] paletteuse" prettyStickAround.gif

## Combination of [1] and [2]
$ ffmpeg -ss 61.0 -t 2.5 -i StickAround.mp4 -filter_complex "[0:v] fps=12,scale=480:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" SmallerStickAround.gif
# lists the available input audio & capture devices
ffmpeg -f avfoundation -list_devices true -i ""

# type the following command to find out what your audio device is called.
ffmpeg -list_devices true -f dshow -i dummy
# 1- List devices
ffmpeg -f avfoundation -list_devices true -i ""

# 2- set audio device