REBIRTH
This commit is contained in:
169
vision/ffmpeg.md
169
vision/ffmpeg.md
@@ -1,169 +0,0 @@
|
||||
---
|
||||
title: ffmpeg
|
||||
tags:
|
||||
- sound
|
||||
- vision
|
||||
---
|
||||
# Basics
|
||||
|
||||
Translate a media file to a new type.
|
||||
|
||||
ffmpeg -i [input file] output_file.mkv
|
||||
|
||||
The input file might be a device, such as a camera.
|
||||
|
||||
# Record screen
|
||||
|
||||
Take the format as 'grab the x11 screen'.
|
||||
|
||||
```sh
|
||||
ffmpeg -f x11grab -s [screensize] -i :0.0 out.mkv
|
||||
```
|
||||
|
||||
Get screensize with
|
||||
|
||||
```sh
|
||||
xrandr -q
|
||||
```
|
||||
|
||||
or maybe just...
|
||||
|
||||
```sh
|
||||
ffmpeg -f x11grab -s "$(xdpyinfo | grep dimensions | awk '{print $2}')" -i :1.0 out.mkv
|
||||
```
|
||||
|
||||
# Add default pulse audio
|
||||
|
||||
```sh
|
||||
ffmpeg -f x11grab -s [screensize] -i :0.0 -f alsa -i default out.mkv
|
||||
```
|
||||
|
||||
For problems, see pavucontrol.
|
||||
|
||||
# Random online suggestion
|
||||
ffmpeg -video_size "$(xdpyinfo | grep dimensions | awk '{print $2}')" -f x11grab -i :0.0 -f pulse -ac 2 -i default ~/out.mkv
|
||||
|
||||
# Rotate
|
||||
|
||||
```sh
|
||||
ffmpeg -i in.mov -vf "transpose=1" out.mov
|
||||
```
|
||||
|
||||
0 = 90 Counterclockwise and verfical flip (default)
|
||||
1 = 90 Clockwise
|
||||
2 = 90 CounterClockwise
|
||||
3 = 90Clockwise and vertical flip
|
||||
|
||||
# Lower Video Quality
|
||||
|
||||
A crf quality of 18 is high, while 24 is low quality.
|
||||
|
||||
ffmpeg -i input.mp4 -vcodec libx264 -crf 20 output.mp4
|
||||
|
||||
# convert
|
||||
|
||||
Check for supported formats:
|
||||
|
||||
```sh
|
||||
ffmpeg -formats
|
||||
```
|
||||
|
||||
To convert from mkv to mp4 we can use a codec rather than proper conversion. Both are wrappers around other formats, so this conversion loses less quality than other conversion types.
|
||||
|
||||
```sh
|
||||
ffmpeg -i LostInTranslation.mkv -codec copy LostInTranslation.mp4
|
||||
```
|
||||
|
||||
Opus to mp3
|
||||
|
||||
```sh
|
||||
ffmpeg -i song.opus song.mp3
|
||||
```
|
||||
|
||||
```sh
|
||||
ffmpeg -i video.flv video.mpeg
|
||||
```
|
||||
|
||||
```sh
|
||||
ffmpeg -i input.webm -qscale 0 output.mp4
|
||||
```
|
||||
|
||||
# Video to Audio
|
||||
|
||||
```sh
|
||||
ffmpeg -i input.mp4 -vn output.mp3
|
||||
```
|
||||
|
||||
|
||||
# Convert all mkv files to mp4
|
||||
|
||||
```sh
|
||||
for i in *.mkv; do
|
||||
```
|
||||
|
||||
> ffmpeg -i "$i" -codec copy "${i%.*}.mp4"
|
||||
|
||||
```sh
|
||||
done
|
||||
```
|
||||
|
||||
|
||||
# Change resolution
|
||||
|
||||
```sh
|
||||
ffmpeg -i input.mp4 -filter:v scale=1280:720 -c:a copy output.mp4
|
||||
```
|
||||
|
||||
Or just crop:
|
||||
|
||||
```sh
|
||||
ffmpeg -i input.mp4 -filter:v "crop=w:h:x:y" output.mp4
|
||||
```
|
||||
|
||||
Or aspect ratio:
|
||||
|
||||
```sh
|
||||
ffmpeg -i input.mp4 -aspect 16:9 output.mp4
|
||||
```
|
||||
|
||||
Or trim to start and stop times:
|
||||
|
||||
```sh
|
||||
ffmpeg -i input.mp4 -ss 00:00:50 -codec copy -t 50 output.mp4
|
||||
```
|
||||
|
||||
Indicate start times with -ss and time with -t in seconds.
|
||||
|
||||
Or split a video into parts:
|
||||
|
||||
```sh
|
||||
ffmpeg -i input.mp4 -t 00:00:30 -c copy part1.mp4 -ss 00:00:30 -codec copy part2.mp4
|
||||
```
|
||||
|
||||
|
||||
# Compress Video
|
||||
|
||||
```sh
|
||||
ffmpeg -i input.mp4 -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 output.mp4
|
||||
```
|
||||
|
||||
# Extract Images from Video
|
||||
|
||||
-r sets the frame rate, and -f selects the format.
|
||||
|
||||
```sh
|
||||
ffmpeg -i input.mp4 -r 1 -f image2 image-%2d.png
|
||||
```
|
||||
|
||||
# Add Images to Audio
|
||||
|
||||
```sh
|
||||
$ ffmpeg -loop 1 -i inputimage.jpg -i inputaudio.mp3 -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest output.mp4
|
||||
```
|
||||
|
||||
# Add Subtitles
|
||||
|
||||
```sh
|
||||
fmpeg -i input.mp4 -i subtitle.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast output.mp4
|
||||
```
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
---
|
||||
title: imagemagick
|
||||
tags:
|
||||
- vision
|
||||
---
|
||||
|
||||
Convert jpg to png.
|
||||
|
||||
```sh
|
||||
magick image.jpg image.png
|
||||
```
|
||||
|
||||
```sh
|
||||
magick image.jpg -quality 50 image.jpg
|
||||
```
|
||||
|
||||
'Quality' must be from 1 to 100.
|
||||
|
||||
```sh
|
||||
magick -resize 50% image.jpg image2.jpg
|
||||
```
|
||||
|
||||
Resizing only changes jpegs. Change a png with:
|
||||
|
||||
```sh
|
||||
magick input.png png8:out.png
|
||||
```
|
||||
|
||||
# Invert Colours
|
||||
|
||||
```sh
|
||||
magick input.jpg output.jpg -negate
|
||||
```
|
||||
|
||||
# Make Images Smaller
|
||||
|
||||
```sh
|
||||
magick image.jpg -resize 25% output.jpg
|
||||
```
|
||||
|
||||
|
||||
# Trim images to border
|
||||
|
||||
This is generally used for transparent images.
|
||||
|
||||
```sh
|
||||
magick -trim image.png output.png
|
||||
```
|
||||
|
||||
Make the white of an image transparent.
|
||||
|
||||
```sh
|
||||
magick -transparent white -fuzz 10% input.png output.png
|
||||
```
|
||||
|
||||
The 'fuzz' option tells the computer that 'close to white' is fine. You might want to use 20% or higher fuzz.
|
||||
|
||||
|
||||
## Dropshadow
|
||||
|
||||
```sh
|
||||
`magick <input file> \( +clone -background black -shadow 50x8+0+5 \) +swap -background none -layers merge +repage <output file>`
|
||||
```
|
||||
|
||||
|
||||
# Convert every jpg in directory to png
|
||||
|
||||
```sh
|
||||
mogrify -format png *.jpg
|
||||
```
|
||||
|
||||
# Printing Words
|
||||
|
||||
# Mass magick
|
||||
|
||||
This script magicks all jpg files in a directory to svg.
|
||||
|
||||
```
|
||||
for i in *jpg
|
||||
do magick "$i" $(ls "$i" | sed s#jpg\$#svg#)
|
||||
done
|
||||
```
|
||||
|
||||
# SVG
|
||||
|
||||
The above script has crappy results.
|
||||
It's better to use potrace.
|
||||
|
||||
```
|
||||
$magick -flatten input.jpg output.ppm
|
||||
$potrace -s output.ppm -o svgout.svg
|
||||
```
|
||||
|
||||
# Writing Words
|
||||
|
||||
[docs](https://www.imagemagick.org/Usage/text/)
|
||||
|
||||
See your installed fonts:
|
||||
|
||||
```sh
|
||||
magick -list font
|
||||
```
|
||||
|
||||
Make an image showing day of the week:
|
||||
|
||||
```sh
|
||||
magick -fill blue -font Sauce-Code-Pro-Semibold-Nerd-Font-Complete-Mono -gravity center -pointsize 79 label:$(date +%A) day.png
|
||||
```
|
||||
|
||||
|
||||
Make a meme:
|
||||
|
||||
```sh
|
||||
magick inputmemeimage.png -font impact -fill white -pointsize 84 -stroke black -strokewidth 3 -gravity north -annotate +0+20 'TOP MEME TEXT' -gravity south -annotate +0+20 'BOTTOM MEME TEXT' outputmemeimage.png
|
||||
```
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
title: Markdown to PDF
|
||||
tags:
|
||||
- markdown
|
||||
- .pdf
|
||||
- pdf
|
||||
- vision
|
||||
---
|
||||
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
output: all
|
||||
|
||||
.PHONY: example
|
||||
example: html/foot.html html/head.html
|
||||
mkdir -p articles/
|
||||
fortune > articles/fort_1.md
|
||||
fortune > articles/fort_2.md
|
||||
|
||||
HTML = $(patsubst articles/%.md,public/%.html,$(wildcard articles/*.md))
|
||||
|
||||
$(HTML): public/ articles/ $(wildcard html/*)
|
||||
|
||||
html/head.html:
|
||||
@mkdir $(@D)
|
||||
echo '<head> Something about CSS probably </head>' > $@
|
||||
echo '<body>' >> $@
|
||||
|
||||
html/foot.html: html/head.html
|
||||
echo '</body>' >> $@
|
||||
|
||||
public/%.html : articles/%.md
|
||||
cat html/head.html > $@
|
||||
lowdown $< >> $@
|
||||
cat html/foot.html >> $@
|
||||
|
||||
.PHONY: all
|
||||
all : $(HTML)
|
||||
|
||||
articles/:
|
||||
mkdir $@
|
||||
|
||||
public/:
|
||||
mkdir $@
|
||||
|
||||
clean :
|
||||
rm -rf public
|
||||
Reference in New Issue
Block a user