Featured image of post A Several FFmpeg command

A Several FFmpeg command

picture to Gif

Define custom palette The converted GIF has only three colors: white and two tints of blue, therefore, the default 256 color palette can be reduced to 16. The custom palette is created with the palettegen filter.

1
ffmpeg -i frames/200.png -vf palettegen=16 palette.png

After the palette was created it can be used in the GIF conversion.

1
ffmpeg -i frames/%03d.png -i palette.png -filter_complex "fps=20,scale=720:-1:flags=lanczos[x];[x][1:v]paletteuse" logo.gif

Image Compression

1
ffmpeg -i image_source -q compress_level out_source

compress_level: The compression level is a positive integer, the larger the value, the higher the compression level

Constrained proportional compression

1
ffmpeg -i image_source -vf scale=width:height out_source

width is the compressed image width height is the height of the compressed image When either width or height has a value of -1, it will keep the original image size ratio and compress

Image crop

1
ffmpeg -i image_source -vf crop=width:height:from_x:from_y out_source

width is the width of the image to be cropped out height is the height of the image to be cropped from_x is the position of the starting X axis of the crop from_y is the position of the starting Y axis of the crop If from_x and from_y are not specified, it means to start cropping from the center of the original image

Add watermark image

1
ffmpeg -i image_source -vf movie=logo_source,scale=logo_width:logo_height,lut=a=val*opacity_num[watermask];[in][watermask] overlay=from_x:from_y[out] -y out_source

logo_source is the watermark image address logo_width is the width of the watermark image logo_height is the height of the watermark image opacity_num is the transparency of the watermark image from_x is the position of the starting X axis of the watermark from_y is the position of the starting Y axis of the watermark

Add text watermark

1
ffmpeg -i image_source -vf drawtext=fontfile=font_ttf_path:fontcolor=font_color:fontsize=font_size:text=message_info:x=from_x:y=from_y out_source

font_ttf_path is the font path, this item must be set, otherwise there will be an error that the font cannot be found The font path should be set to an absolute path and pay attention to the slash escape of the path (eg C\:/Windows/Fonts/simhei.ttf) font_color is the color of the font font_size is the size of the font message_info is the watermark text content from_x is the position of the starting X axis of the watermark from_y is the position of the starting Y axis of the watermark If the watermark content is Chinese, you need to set the Chinese font, otherwise the text will display garbled characters

Rotate the picture by the specified angle

1
ffmpeg -i image_source -vf rotate=route_num*PI/180 -y out_source

route_num is the angle to rotate

Rotate clockwise when route_num is greater than 0, and rotate counterclockwise when route_num is less than 0

Image rotation special and convenient commands

1
ffmpeg -i image_source -vf transpose=route_number -y out_source

route_number=0 Rotate 90 degrees clockwise and then mirror left and right route_number=1 rotate 90 degrees clockwise route_number=2 rotate 90 degrees counterclockwise route_number=3 Rotate 90 degrees counterclockwise and then mirror left and right

Mirror image left and right

1
ffmpeg -i image_source -vf hflip out_source

Mirror the picture up and down

1
ffmpeg -i image_source -vf vflip out_source

Specify length and width

1
ffmpeg -i input.jpg -vf scale=320:240 output_320x240.png

Specify the length and height to scale proportionally

1
ffmpeg -i input.jpg -vf scale=320:-1 output_320x240.png

Scale twice as before

1
ffmpeg -i input.jpg -vf scale=iw*2:ih input_double_width.png

Scale to one-half of the previous

1
ffmpeg -i input.jpg -vf “scale=iw*.5:ih*.5” input_half_size.png
1
ffmpeg -i input.jpg -vf “scale=iw/2:ih/2” input_half_size.png
Built with Hugo
Theme Stack designed by Jimmy