highly recommanded

cmd.to

video

get audio from video

$ ffmpeg -i source.mpg -f s16le -acodec pcm_s16le audio.raw

convert flv to mp4

$ ffmpeg -i name.flv -qscale 0 name.mp4

convert png to mp4

options:

  • pic-%02d.png: Read all images from the current folder with the prefix pic-, a following number of 2 digits (%02d) and an ending of .png
  • -r 1/5 : Displays each image for 5 seconds
  • r 30 : Output framerate of 30 fps.
  • -c:v libx264 : Output video codec: h264
  • pix_fmt yuv420p : YUV pixel format

$ ffmpeg -r 1/5 -i pic-%02d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4

scale the media

$ ffmpeg -i out.mp4 -vf scale=-1:720 out_720p.mp4

convert to 5 mins (300 sec)

$ ffmpeg -i name.mp4 -ss 0 -t 300 name-5m.mp4

sequence convert (every 5 mins ~> 300 secs)

  • first 5 mins (0 ~> 300)
    $ ffmpeg -i name.mp4 -ss 0 -t 300 name-5m-1.mp4
    
  • second 5 mins (300*1 ~> 300)
    $ ffmpeg -i name.mp4 -ss 300 -t 300 name-5m-2.mp4
    
  • third 5 mins (300*2 ~> 300)
    $ ffmpeg -i name.mp4 -ss 600 -t 300 name-5m-3.mp4
    

convert pdf to png

  • -density 400 : Set the horizontal resolution of the image

$ convert -density 400 input.pdf pic.png

combine video and audio

$ ffmpeg -i <origin-video> -i <origin-audio> -c copy -map 0:0 -map 1:0 -shortest <new-video>
combine
1.2.10.1 -- combine

compression mov

[!NOTE|label:references:]

$ ffmpeg -i coc-groovy-lsp.org.mov -c:v libx264 -c:a copy -crf 20 coc-groovy-lsp.mov
$ ls -altrh | grep coc-groovy-lsp
-rw-r--r--   1 marslo staff  37M Jan 15 18:39 coc-groovy-lsp.org.mov
-rw-r--r--   1 marslo staff  10M Jan 15 19:02 coc-groovy-lsp.mov

$ ffmpeg -i coc-groovy-lsp-minirc.org.mov -c:v libx264 -c:a copy -crf 20 coc-groovy-lsp-minirc.mov
$ ls -altrh | grep coc-groovy-lsp-minirc
-rw-r--r--   1 marslo staff  14M Jan 15 19:16 coc-groovy-lsp-minirc.org.mov
-rw-r--r--   1 marslo staff 4.1M Jan 15 19:20 coc-groovy-lsp-minirc.mov

convert mov to mp4

[!NOTE|label:reference:]

# handbrakecli
$ handbrakecli -i {in-video}.mov -e x264 -E facc -o {out-video}.mp4

# ffmpeg
$ ffmpeg -i {in-video}.mov -vcodec h264 -acodec aac {out-video}.mp4
# or
$ ffmpeg -i input.mov -c copy -movflags +faststart output.mp4

convert video to gif

[!NOTE|label:references:]

# with specific size
$ ffmpeg -ss 30 -t 3 -i input.mp4 \
         -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
         -loop 0 output.gif

# or
$ ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos" -c:v pam \
         -f image2pipe - | \
         convert -delay 10 - -loop 0 -layers optimize output.gif

# with original size
$ ffmpeg -ss 30 -t 3 -i coc-groovy-minirc.org.mov \
         -vf "fps=35" \
         -loop 0 output.gif

# using ImageMagick
$ convert in.mp4 out.gif
  • function

    #### video2gif.sh
    # Convert video to gif file.
    # Usage: video2gif video_file (scale) (fps)
    video2gif() {
      ffmpeg -y -i "${1}" -vf fps=${3:-10},scale=${2:-320}:-1:flags=lanczos,palettegen "${1}.png"
      ffmpeg -i "${1}" -i "${1}.png" -filter_complex "fps=${3:-10},scale=${2:-320}:-1:flags=lanczos[x];[x][1:v]paletteuse" "${1}".gif
      rm "${1}.png"
    }
    
    REM video2gif.bat
    @echo off
    set arg1=%1
    set arg2=%arg1:~0,-4%
    ffmpeg -y -i %arg1% -vf fps=10,scale=-1:-1:flags=lanczos,palettegen %TEMP%\palette.png
    ffmpeg -i %arg1% -i %TEMP%\palette.png -filter_complex "fps=10,scale=-1:-1:flags=lanczos[x];[x][1:v]paletteuse" %arg2%.gif
    del /f %TEMP%\palette.png
    
    # usage
    $ video2gif input.flv
    $ video2gif input.flv 320 10
    
  • another simple solution

    src="input.flv"
    dest="output.gif"
    palette="/tmp/palette.png"
    
    ffmpeg -i $src -vf palettegen -y $palette
    ffmpeg -i $src -i $palette -lavfi paletteuse -y $dest
    

convert pngs into gif

$ convert -delay 5 -loop 0 -dither None -colors 80 "frames/ffout*.png" -fuzz "40%" -layers OptimizeFrame  "output.gif"

image

convert webp to png

$ ffmpeg -i file.webp out.png
  • for multiple images
    $ for x in ls *.webp; do
        ffmpeg -i "$x" "${x%.webp}.jpg"
      done
    

identity an image

$ identify arms009.jpg | grep -o "[[:digit:]]*x[[:digit:]]*" | tail -1
1024x768

convert svg to png

  • qlmanage

    $ qlmanage -t -s 1000 -o . k-1.svg
    
  • convert

    $ convert -resize 128x128 input.svg output.png
    
    # or
    $ convert -density 500 -resize 128x128 input.svg output.png
    $ convert -density 1200 -resize 10000x10000 your.svg your.png
    $ convert -background none -size 1024x1024 infile.svg outfile.png
    

convert HEIC/HEIF to PNG

magick
1.2.10.2 -- magick
$ brew install imagemagick --with-libheif

# for single convert
$ magick convert [-monitor] <name>.HEIC <new-name>.png

# for batch convert
$ magick mogrify [-monitor] -format png *.HEIC.

sed command to batch change fill and stroke of an SVG

#!/usr/bin/env sh

COLOR=yellow
sed -i -E 's/fill\="[^"]+"//g; s/stroke\="[^"]+"//g' *.svg
sed -i "s/<path/<path fill=\"$COLOR\" stroke=\"$COLOR\"/g" *.svg
  • or
    #!/usr/bin/env sh
    COLOR=yellow
    sed -i -E 's/fill\="[^"]+"//g; s/stroke\="[^"]+"//g' *.svg
    sed -i "s/<path/<path fill=\"$COLOR\" stroke=\"$COLOR\"/g" *.svg
    sed -i "s/<rect/<rect fill=\"$COLOR\" stroke=\"$COLOR\"/g" *.svg
    sed -i "s/<polygon/<polygon fill=\"$COLOR\" stroke=\"$COLOR\"/g" *.svg
    sed -i "s/<circle/<circle fill=\"$COLOR\" stroke=\"$COLOR\"/g" *.svg
    sed -i "s/<ellipse/<ellipse fill=\"$COLOR\" stroke=\"$COLOR\"/g" *.svg
    sed -i "s/<polyline/<polyline fill=\"$COLOR\" stroke=\"$COLOR\"/g" *.svg
    sed -i -E "s/stroke\:[^\;]+/stroke\:$COLOR/g" *.svg
    sed -i -E "s/fill\:\#[0-9]+/fill\:$COLOR/g" *.svg
    
Copyright © marslo 2020-2023 all right reserved,powered by GitbookLast Modified: 2024-05-15 11:26:20

results matching ""

    No results matching ""