Am I properly using my input file with convert? - imagemagick-convert

I have a list of images in a file that looks like
/home/myuser/timelapse/2016-03-16 10:00:02.jpg
/home/myuser/timelapse/2016-03-16 09:45:02.jpg
/home/myuser/timelapse/2016-03-16 09:30:02.jpg
/home/myuser/timelapse/2016-03-16 09:15:02.jpg
I want to add these images to a animation. I usually do that by using this command.
convert -verbose -delay 50 -loop 0 /home/myuser/timelapse/2016*.jpg /home/myuser/animation.gif
However if I want to add images from say the last ten. I have the latest 10 file names in my file and I try to use this command
convert -verbose -delay 50 -loop 0 < "$(< list.txt)" /home/myuser/animation.gif
I get
/home/myuser/timelapse/2016-03-16 09:45:02.jpg
/home/myuser/timelapse/2016-03-16 09:30:02.jpg
/home/myuser/timelapse/2016-03-16 09:15:02.jpg
/home/myuser/timelapse/2016-03-16 09:00:02.jpg
/home/myuser/timelapse/2016-03-16 08:45:02.jpg : No such file or directory
Is it possible the space in the file name is creating the problem? How would that be corrected?
Am I properly using my input file with convert?

The correct way to use input file list with convert is to use "#"
here is the example that works for me
convert -verbose -delay 50 -loop 0 #newfile.txt /home/myuser/animation.gif

Related

crop and keep the names on multiples images on magick

I would like to crop multiple images files and keep the same name or add a "_2" at the end of the name.
any idea how to do it?
I tried this
magick *jpg -set filename:base "%[basename]" -fuzz 90% "%[filename:base]_2.jpg"
To just keep the same name use magick mogrify. This works exactly like magick or magick convert but overwrites the input file, so there is no output specification. It is quite simple to use on a set of files:
magick mogrify [parameters] file [file...]

gdal_translate only translating first three bands from .vrt to .tif

I'm trying to translate a set of .tif images to one multiband .tif following this tutorial. I'm not getting any errors but every time I run the script it generates a three-band image when I have a lot more input .tifs than that. I have tried the -r flag and it didn't change anything.
I have:
wdir="/Users/<mydir>"
creoleLA="$wdir/data/s2l2a_tiffs/T15RVP"
dhaka="$wdir/data/s2l2a_tiffs/T45QZG"
easthouston="$wdir/data/s2l2a_tiffs/T15RTN"
kolkata="$wdir/data/s2l2a_tiffs/T45QXF"
murcia="$wdir/data/s2l2a_tiffs/T30SXH"
wuhan="$wdir/data/s2l2a_tiffs/T50RKU"
#=============================================
# Main script
#=============================================
read -p 'ROI: ' roi
indir=${!roi}
outdir="$wdir/data/s2l2a_tiffs"
ls ${indir}*"_B"*.tif > "$outdir/btif_${roi}.txt"
gdalbuildvrt -separate -overwrite -input_file_list "$outdir/btif_${roi}.txt" "$outdir/S2L2A_${roi}.vrt"
gdal_translate -strict -ot uint16 "$outdir/S2L2A_${roi}.vrt" "$outdir/S2L2A_${roi}_mb.tif"
rm "$outdir/S2L2A_${roi}.vrt"
rm "$outdir/btif_${roi}.txt"
Where "$outdir/btif_${roi}.txt" is a textile of the GeoTIFF file paths like this:
/Users/<mydir>/data/s2l2a_tiffs/T15RVP_20200831T164849_B01_60m.tif
/Users/<mydir>/data/s2l2a_tiffs/T15RVP_20200831T164849_B02_60m.tif
...
I am processing Sentinel-2 imagery and using OSX 11.6.

ffmpeg - Why does concatenating .ts videos through .txt fail from \folder\ but work from \folder\subfolder\?

I have a bunch of .ts videofiles that I want to merge into a single file so I can convert it to a .mp4 video.
The .ts files are in a folder "E:\videotest" like:
E:\videotest\0.ts
E:\videotest\1.ts
[...]
E:\videotest\100.ts
I used a PowerShell command to output the filepaths in a .txt file:
foreach ($i in Get-ChildItem .\*.ts) {echo "file '$i'" >> mylist.txt}
The resulting mylist.txt looks like:
file 'E:\videotest\0.ts'
file 'E:\videotest\1.ts'
[...]
file 'E:\videotest\100.ts'
When I run the command:
ffmpeg -f concat -safe "0" -protocol_whitelist "file,http,https,tcp,tls" -i "E:\videotest\concat\mylist.txt" -c copy "E:\videotest\concat\combined_video.ts"
I get the error:
Line 1: unknown keyword ' ■f'
E:\videotest\concat\mylist.txt:
Invalid data found when processing input
But if I add a subfolder layer to the files like this:
E:\videotest\0\0.ts
E:\videotest\1\1.ts
[...]
E:\videotest\100\100.ts
And change mylist.txt to:
file 'E:\videotest\0\0.ts'
file 'E:\videotest\1\1.ts'
[...]
file 'E:\videotest\100\100.ts'
The same ffmpeg command will work and create the combined_video.ts file.
Why does converting work with the subfolder structure but not from the main folder?
How do I adjust the ffmpeg command to make it work?
Thank you.
It turns out that the problem was the encoding of the "mylist.txt" file. For some reason it was encoded as "UCS-2 LE BOM". After setting it to "UTF-8" I was able to concatenate the files.

How to use imagemagick "convert" to create Google Earth pyramid files

I have a large image that I am using imagemagick to convert into tiles for use in a Google Earth KML as explained here
instructions on image pyramid construction
The idea is to chop up the images into 4 pieces, then 16, then 64, etc.
To keep things simple, I made the image canvas 4096x4096 so that dividing it in will produce equal size files. The basic command is very simple. For example:
convert large.png -crop 512x512 tiles.png
The issue is the convert command creates file names sequentially, while google needs a format of row column. For instance if there were four files output, the file names should be:
tiles00.png
tiles01.png
tiles10.png
tiles11.png
I brute forced renaming scripts for up to 64 files, but before doing the 256 file case, I'd like to know if there is a simpler way to generate the file names. I'm using linux.
Here is one way in Imagemagick 6 using for loops.
lena.png
The lena.png image is 256x256. I choose 128x128 size tiles. So there will be a total of 2 rows and 2 columns for four output images.
infile="lena.png"
tx=128
ty=128
ncols=`convert -ping "$infile" -format "%[fx:floor(w/$tx)]" info:`
nrows=`convert -ping "$infile" -format "%[fx:floor(h/$ty)]" info:`
for ((j=0; j<nrows; j++)); do
offy=$((j*ty))
for ((i=0; i<ncols; i++)); do
offx=$((i*tx))
convert lena.png -crop ${tx}x${ty}+${offx}+${offy} +repage lena_tile${j}${i}.png
done
done
lena_tile00
lena_tile01
lena_tile10
lena_tile11
An alternate, more compact way is to use -set filename command with fx calculations to name the files in the image chain.
infile="lena.png"
tx=128
ty=128
ncols=`convert -ping "$infile" -format "%[fx:floor(w/$tx)]" info:`
nrows=`convert -ping "$infile" -format "%[fx:floor(h/$ty)]" info:`
convert "$infile" -crop ${tx}x${ty} -set filename:row_col "%[fx:floor(t/$nrows)]%[fx:mod(t,$ncols)]" "lena_tile%[filename:row_col].png"
See:
https://imagemagick.org/Usage/basics/#set
https://imagemagick.org/script/fx.php
Are you trying to make your own in order to learn about the process? If not, existing tools like dzsave can build complete pyramids for you very quickly in a single command. For example:
$ vipsheader wtc.jpg
wtc.jpg: 10000x10000 uchar, 3 bands, srgb, jpegload
$ /usr/bin/time -f %M:%e vips dzsave wtc.jpg x --layout google
211224:1.52
$ ls -R x | wc
2404 2316 15186
So that's making a google-style pyramid of 2400 tiles in directory x from a 10,000 x 10,000 pixel JPG image. It takes about 1.5s and 210mb of ram.
There's a chapter in the manual introducing dzsave:
http://libvips.github.io/libvips/API/current/Making-image-pyramids.md.html

Mac Terminal - Create animated gif from png files

I have a bunch of png files named as 1.png, 2.png, etc. and I want to create an animated gif image from them all. I haven't been successful in finding a solution for a terminal command that will convert these png files into a single animated gif.
Can someone post some commands that I can try? I have tried "convert" commands but my terminal always says convert is not found even though I have installed ImageMagik.
convert *.png screens.gif
This answer suggested installing convert with brew install ImageMagick.
ImageMagick's convert command works perfectly for this but you'll want to list the filenames in the correct order. Using *.png will jumble frames if the digits don't have the leading zeros because the ordering is alphabetical:
1.png 10.png 11.png 2.png 3.png ...
If you use zsh you can simply use a glob qualifier:
convert *.png(n) out.gif
Otherwise you can sort the ls output
convert $(ls *.png | sort -V) out.gif
If your filenames have leading zeros go ahead and use *.png. Note that the default delay between frames is small, so depending on your use case the frame rate might be too quick. To change that use the -delay option, for example:
convert -delay 50 *.png out.gif
This will set FPS to 100/50 = 2 frames per second.

Resources