Jpegloop: Difference between revisions
No edit summary |
No edit summary |
||
(12 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== | == Counting up == | ||
<source lang="bash"> | |||
for ((i=1;i<=100;i++)) | |||
do | |||
echo $i | |||
done | |||
</source> | |||
== Counting down == | |||
<source lang="bash"> | <source lang="bash"> | ||
for ((i=1;i<=100;i++)) | for ((i=1;i<=100;i++)) | ||
Line 9: | Line 15: | ||
</source> | </source> | ||
== Doing something == | |||
<source lang="bash"> | |||
for ((i=1;i<=10;i++)) | |||
do | |||
convert original.jpg -quality $i output$i.jpg | |||
done | |||
</source> | |||
== Fixing the filenames (zero padding with printf) == | |||
printf can be used to "zero-pad" a number (ie make a good filename from a counting number) | |||
printf "%03d" 7 | |||
means "zero-pad" (add zeros) to always be 3 characters long, and outputs: | |||
007 | |||
=== command substitution === | |||
$() means "command substitution" -- or do what's inside the parentheses and then substitute the result. This can be used to store the result of running printf in a variable (to then use again) | |||
<source lang="bash"> | |||
for ((i=1;i<=10;i++)) | |||
do | |||
name=$(printf "%03d\n" $i) | |||
convert original.jpg -quality $i output$name.jpg | |||
done | |||
</source> | |||
== Compressing the "lastframe" to perform an iterative compression == | |||
The trick here is to keep a "lastframe" copy that can always be used as the input to the convert command. | |||
<source lang="bash"> | <source lang="bash"> | ||
cp $j lastframe.jpg | cp $j lastframe.jpg | ||
Line 25: | Line 60: | ||
ffmpeg -f image2 -i output%03d.jpg -r 10 $j.mp4 | ffmpeg -f image2 -i output%03d.jpg -r 10 $j.mp4 | ||
</source> | </source> | ||
== Converting the images to a movie == | |||
ffmpeg -f image2 -i output%03d.jpg -r 10 output.mp4 | |||
== Apply to a directory of files == | == Apply to a directory of files == | ||
The whole thing can be wrapped in a "for" loop to process a whole bunch of input images at once. | |||
<source lang="bash"> | <source lang="bash"> | ||
Line 33: | Line 73: | ||
for j | for j | ||
do | do | ||
cp $j lastframe.jpg | cp $j lastframe.jpg | ||
for ((i=100;i>=1;i--)) | for ((i=100;i>=1;i--)) | ||
do | do | ||
name=$(printf "%03d\n" $((100-i))) | |||
convert lastframe.jpg -quality $i output$name.jpg | |||
# COPY THE CURRENT TO "lastframe.jpg" | |||
cp output$name.jpg lastframe.jpg | |||
done | done | ||
Line 49: | Line 87: | ||
done | done | ||
</source> | </source> | ||
{{vimeo|14969253}} |
Latest revision as of 20:16, 23 February 2018
Counting up
for ((i=1;i<=100;i++))
do
echo $i
done
Counting down
for ((i=1;i<=100;i++))
do
echo $i
done
Doing something
for ((i=1;i<=10;i++))
do
convert original.jpg -quality $i output$i.jpg
done
Fixing the filenames (zero padding with printf)
printf can be used to "zero-pad" a number (ie make a good filename from a counting number)
printf "%03d" 7
means "zero-pad" (add zeros) to always be 3 characters long, and outputs:
007
command substitution
$() means "command substitution" -- or do what's inside the parentheses and then substitute the result. This can be used to store the result of running printf in a variable (to then use again)
for ((i=1;i<=10;i++))
do
name=$(printf "%03d\n" $i)
convert original.jpg -quality $i output$name.jpg
done
Compressing the "lastframe" to perform an iterative compression
The trick here is to keep a "lastframe" copy that can always be used as the input to the convert command.
cp $j lastframe.jpg
for ((i=100;i>=1;i--))
do
name=$(printf "%03d\n" $((100-i)))
convert lastframe.jpg -quality $i output$name.jpg
cp output$name.jpg lastframe.jpg
done
ffmpeg -f image2 -i output%03d.jpg -r 10 $j.mp4
Converting the images to a movie
ffmpeg -f image2 -i output%03d.jpg -r 10 output.mp4
Apply to a directory of files
The whole thing can be wrapped in a "for" loop to process a whole bunch of input images at once.
#!/bin/bash
for j
do
cp $j lastframe.jpg
for ((i=100;i>=1;i--))
do
name=$(printf "%03d\n" $((100-i)))
convert lastframe.jpg -quality $i output$name.jpg
# COPY THE CURRENT TO "lastframe.jpg"
cp output$name.jpg lastframe.jpg
done
ffmpeg -f image2 -i output%03d.jpg -r 10 $j.mp4
done