highly recommanded

cmd.to

video

get audio from video

[!NOTE|label:references:]

  • ffmpeg params:
    • -acodec copy -vn
    • -ab 12800 -ar 44100
$ ffmpeg -i source.mpg -f s16le -acodec pcm_s16le audio.raw

# https://www.commandlinefu.com/commands/view/52/rip-audio-from-a-video-file.
$ mplayer -ao pcm -vo null -vc dummy -dumpaudio -dumpfile <output.file> <input.file>

# or
$ ffmpeg -i file.video file.audio

download video

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

slice video to images

$ ffmpeg -i video.mp4 -vf "fps=24" css_%04d.png

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
    
  • create an animated gif from a youtube video

    $ url=http://www.youtube.com/watch?v=V5bYDhZBFLA;
    youtube-dl -b $url; mplayer $(ls ${url##*=}*| tail -n1) -ss 00:57 -endpos 10 -vo gif89a:fps=5:output=output.gif -vf scale=400:300 -nosound
    

convert pngs into gif

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

# simple version
$ convert -delay 10 *.png sample.gif

record a screencast and convert to mpeg

$ ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/outputFile.mpg

# or: https://www.commandlinefu.com/commands/view/7109/capture-video-of-a-linux-desktop
$ ffmpeg -y -f alsa -ac 2 -i pulse -f x11grab -r 30 -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -i :0.0 -acodec pcm_s16le output.wav -an -vcodec libx264 -vpre lossless_ultrafast -threads 0 output.mp4

# or: https://www.commandlinefu.com/commands/view/5189/capture-video-of-a-linux-desktop
$ ffmpeg -f x11grab -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -r 25 -i :0.0 -sameq /tmp/out.mpg > /root/howto/capture_screen_video_ffmpeg

# or: https://www.commandlinefu.com/commands/view/24389/capture-video-of-a-linux-desktop
$ ffmpeg -video_size 1024x768 -framerate 25 -f x11grab -i :0.0+100,200 output.mp4

# or: https://www.commandlinefu.com/commands/view/12572/capture-video-of-a-linux-desktop
ffmpeg -f x11grab -s wxga -r 25 -i :0.0+1366,0 -qscale 0 /tmp/out.mpg

tips

  • get the total length of time

    $ find -type f -name "*.avi" -print0 | xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1
    
  • edit video by cutting the part you like without transcoding

    $ mencoder -ss <start point> -endpos <time from start point> -oac copy -ovc copy <invid> -o <outvid>
    
    # i.e.: take frames starting at 15.2 seconds for a total of 45.9 seconds
    $ mencoder -ss 15.2 -endpos 30.7 -oac copy -ovc copy origin.avi -o new.avi
    
    # i.e.: total 3m3s length
    $ mencoder -ss 1 minute -endpos 2 minutes 3 seconds -oac copy -ovc copy origin.avi -o new.avi
    
  • stream and copy a video from lan

    $ nc HOST PORT | tee movie.mp4 | mplayer -
    
    # via ssh: https://www.commandlinefu.com/commands/view/12955/securely-stream-and-save-a-file-from-a-remote-server
    $ ssh USER@HOST cat REMOTE_FILE.mp4 | tee LOCAL_FILE.mp4 | mplayer -
    

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

  • rsvg-convert

    $ brew install librsvg
    $ rsvg-convert -h 256 file.svg > file.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
    
  • svgexport

    $ npm install svgexport -g
    $ svgexport input.svg output.png 256:256
    
  • inkscape

    [!NOTE]

    • Warning: Option --without-gui= is deprecated
    $ brew install inkscape
    $ inkscape --shell -w 256 -h 256 code.svg -o code.png -background none
    
    # or
    $ inkscape -z -w 1024 -h 1024 input.svg -e output.png
    
  • imagemagick

    in_size=50
    in_density=96
    out_size=512
    
    magick -density "%[fx:$in_density*$out_size/$in_size]" button.svg button3.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
    

animation flow chart

create animation flow

[!NOTE|label:references:]

  • draw.io

    flow animation
    1.2.10.3 -- flow animation
  • export to svg

    export to svg
    1.2.10.4 -- export to svg

convert svg to gif

  • online tools

    [!NOTE|label:references:]

    • convert svg to gif with watermark in html5animationtogif.com

      • increase the SVG image height to make the watermark shows below of original image
      without increase height
      1.2.10.5 -- without increase height
      increase height
      1.2.10.6 -- increase height

others

create manpage pdf

$ man -t manpage | ps2pdf - filename.pdf

# https://www.commandlinefu.com/commands/view/9751/save-man-page-as-pdf
$ man -t awk | ps2pdf - awk.pdf

save command output to image

$ ifconfig | convert label:@- ip.png
# or: https://www.commandlinefu.com/commands/view/18168/save-command-output-to-image
$ convert label:"$(ifconfig)" output.png

# and more
$ ifconfig | convert -background none label:@- miff:- | composite -tile pattern:checkerboard - -compose Dst_Over ip.png

# and more with fonts: `convert -list font | grep Font:`
$ /usr/bin/lynx -dump -nolist http://www.commandlinefu.com/ | /usr/bin/convert -font "FreeMono-Medium" label:@- output.png
Copyright © marslo 2020-2024 all right reserved,powered by GitbookLast Modified: 2024-10-30 04:30:28

results matching ""

    No results matching ""