media
highly recommanded
video
get audio from video
[!NOTE|label:references:]
ffmpegparams:
-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.audiodownload video
download video and extract with sepcific time
$ yt-dlp --external-downloader ffmpeg --external-downloader-args "-ss 00:05:00 -t 00:01:00" "https://www.youtube.com/watch?v=Y6DGABIcB3w"$ youtube-dl -t --extract-audio --audio-format mp3 YOUTUBE_URL_HERE
convert flv to mp4
$ ffmpeg -i name.flv -qscale 0 name.mp4$ ffmpeg -r 1/5 -i pic-%02d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4$ ffmpeg -i out.mp4 -vf scale=-1:720 out_720p.mp4convert to 5 mins (300 sec)
$ ffmpeg -i name.mp4 -ss 0 -t 300 name-5m.mp4sequence convert (every 5 mins ~> 300 secs)
first 5 mins (0 ~> 300)
$ ffmpeg -i name.mp4 -ss 0 -t 300 name-5m-1.mp4second 5 mins (300*1 ~> 300)
$ ffmpeg -i name.mp4 -ss 300 -t 300 name-5m-2.mp4third 5 mins (300*2 ~> 300)
$ ffmpeg -i name.mp4 -ss 600 -t 300 name-5m-3.mp4
$ convert -density 400 input.pdf pic.pngcombine video and audio
$ ffmpeg -i <origin-video> -i <origin-audio> -c copy -map 0:0 -map 1:0 -shortest <new-video>
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.movconvert 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.mp4slice video to images
$ ffmpeg -i video.mp4 -vf "fps=24" css_%04d.pngconvert video to gif
[!NOTE|label:references:]
How do I convert a video to GIF using ffmpeg, with reasonable quality?
options:
-ss 30: skip first 30 seconds
-t 3: create a 3 second output
fps=10: fps filter sets the frame rate
scale=320:-1: resize the output to 320 pixels wide and automatically determine the height, the lanczos scaling algorithm is used in this example.
scale=0:-1: do not resize
split[s0][s1]: split filter will allow everything to be done in one command and avoids having to create a temporary PNG file of the palette
[s0]palettegen[p];[s1][p]paletteuse: palettegen and paletteuse filters will generate and use a custom palette generated from your inputffmpeg options:
-vf "fps=10,scale=320:-1:flags=lanczos"a filtergraph using the fps and scale filters.
-c:v pam: chooses the pam image encoder
-f image2pipe: chooses the image2pipe muxerconvert options:
-delay: set frame rate with a combination of the fps filter in ffmpeg
-loop 0: makes infinite loop
-layers optimize: enable the general purpose GIF optimizerto set rgb
-vf scale=320:-1,format=rgb8,format=rgb24
# 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#### 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 10src="input.flv" dest="output.gif" palette="/tmp/palette.png" ffmpeg -i $src -vf palettegen -y $palette ffmpeg -i $src -i $palette -lavfi paletteuse -y $destcreate 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$ 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.mpgtips
$ 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 1edit 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.avistream 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
$ ffmpeg -i file.webp out.pngfor 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
1024x768convert svg to png
$ brew install librsvg $ rsvg-convert -h 256 file.svg > file.png$ qlmanage -t -s 1000 -o . k-1.svgconvert
$ convert -background none \ # transparent background -density 300 \ # DPI (dots per inch) to 300, default is 72 -filter Lanczos \ # lanczos provides high-quality resampling -resize 400x \ # width of 400 pixels x height is auto-calculated -antialias \ # antialiasing input.svg output.png $ 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$ npm install svgexport -g $ svgexport input.svg output.png 256:256[!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.pngin_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

$ 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.#!/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" *.svgor
#!/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:]

flow animation export to svg

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 
increase height crop the watermark in animated GIF editor and Gif maker

crop gif
local tools
chrome extension: Chrome Capture - screenshot & GIF
desktop application: GIF Brewery:
.045s,0.50sor0.52s
others
$ man -t manpage | ps2pdf - filename.pdf
# https://www.commandlinefu.com/commands/view/9751/save-man-page-as-pdf
$ man -t awk | ps2pdf - awk.pdf$ 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.pngLast updated
Was this helpful?