Scooby-2
January 23rd, 2015, 09:24 PM
I have a bash script which locates all jpg images in a directory and stamps each one with the date and time of the files' creation time in the top left corner using convert. The line in my script is:
convert "${file}" -gravity NorthWest -pointsize 14 -undercolor '#00000080' -fill yellow -annotate +0+20 "$(date -r ${file} +'%d-%m-%y %H:%M:%S')" ${stamped_dir}/frame"$(basename ${file})"_stamped.jpg
where $file is assigned to each jpg to be processed. I wrote bash functions to determine the files' creation date but soon realised that these cannot be called from within parallel, so I wrote a bash script to create a file called jpglist to be used. It contains the path and file name, a tab, then the timestamp for that file, then a new line for the next entry. So each line of this file looks something like this:
2015-01-17--00h-00m/frame00001.jpg 17-01-15_08:00:04
.
.
2015-01-17--00h-00m/frame00015.jpg 19-01-15_09:00:06
The entries are tab-separated. With Parallel, I have tried a multitude of permutations something like the following:
cat jpglist | parallel --gnu -v --colsep '\t' "convert -gravity NorthWest -pointsize 14 -undercolor '#00000080' -fill yellow -annotate +0+20" {1} -write {2} {1}.JPG
However, parallel seems to be awkward about convert and the arguments it needs. The double quotes are there because without them I make even less headway! Here's the output from the above command with 2 jpg files listed in the jpglist:
convert -gravity NorthWest -pointsize 14 -undercolor '#00000080' -fill yellow -annotate +0+20 ./2015-01-19--09h-00m/frame00001.jpg -write 19-01-15_09:00:00 ./2015-01-19--09h-00m/frame00001.jpg.JPG
convert.im6: no images defined `./2015-01-19--09h-00m/frame00001.jpg.JPG' @ error/convert.c/ConvertImageCommand/3044.
convert -gravity NorthWest -pointsize 14 -undercolor '#00000080' -fill yellow -annotate +0+20 ./2015-01-19--09h-00m/frame00015.jpg -write 19-01-15_09:00:06 ./2015-01-19--09h-00m/frame00015.jpg.JPG
convert.im6: no images defined `./2015-01-19--09h-00m/frame00015.jpg.JPG' @ error/convert.c/ConvertImageCommand/3044.
I am running GNU parallel 20141122 on Linux Mint 17. I know my jpglist file is OK as the following works:
cat jpglist | parallel --gnu --colsep '\t' echo "frame={1}, timestamp={2}"
The output is:
2015-01-17--00h-00m/frame=frame00001.jpg, timestamp=19-01-15_09:00:00
2015-01-17--00h-00m/frame=frame00015.jpg, timestamp=19-01-15_09:00:06
My question is: Can convert be used in this way with GNU Parallel? Processing 25,000 files one at a time takes bash around half an hour and as I have 4 cores I was hoping to be able to reduce this.
convert "${file}" -gravity NorthWest -pointsize 14 -undercolor '#00000080' -fill yellow -annotate +0+20 "$(date -r ${file} +'%d-%m-%y %H:%M:%S')" ${stamped_dir}/frame"$(basename ${file})"_stamped.jpg
where $file is assigned to each jpg to be processed. I wrote bash functions to determine the files' creation date but soon realised that these cannot be called from within parallel, so I wrote a bash script to create a file called jpglist to be used. It contains the path and file name, a tab, then the timestamp for that file, then a new line for the next entry. So each line of this file looks something like this:
2015-01-17--00h-00m/frame00001.jpg 17-01-15_08:00:04
.
.
2015-01-17--00h-00m/frame00015.jpg 19-01-15_09:00:06
The entries are tab-separated. With Parallel, I have tried a multitude of permutations something like the following:
cat jpglist | parallel --gnu -v --colsep '\t' "convert -gravity NorthWest -pointsize 14 -undercolor '#00000080' -fill yellow -annotate +0+20" {1} -write {2} {1}.JPG
However, parallel seems to be awkward about convert and the arguments it needs. The double quotes are there because without them I make even less headway! Here's the output from the above command with 2 jpg files listed in the jpglist:
convert -gravity NorthWest -pointsize 14 -undercolor '#00000080' -fill yellow -annotate +0+20 ./2015-01-19--09h-00m/frame00001.jpg -write 19-01-15_09:00:00 ./2015-01-19--09h-00m/frame00001.jpg.JPG
convert.im6: no images defined `./2015-01-19--09h-00m/frame00001.jpg.JPG' @ error/convert.c/ConvertImageCommand/3044.
convert -gravity NorthWest -pointsize 14 -undercolor '#00000080' -fill yellow -annotate +0+20 ./2015-01-19--09h-00m/frame00015.jpg -write 19-01-15_09:00:06 ./2015-01-19--09h-00m/frame00015.jpg.JPG
convert.im6: no images defined `./2015-01-19--09h-00m/frame00015.jpg.JPG' @ error/convert.c/ConvertImageCommand/3044.
I am running GNU parallel 20141122 on Linux Mint 17. I know my jpglist file is OK as the following works:
cat jpglist | parallel --gnu --colsep '\t' echo "frame={1}, timestamp={2}"
The output is:
2015-01-17--00h-00m/frame=frame00001.jpg, timestamp=19-01-15_09:00:00
2015-01-17--00h-00m/frame=frame00015.jpg, timestamp=19-01-15_09:00:06
My question is: Can convert be used in this way with GNU Parallel? Processing 25,000 files one at a time takes bash around half an hour and as I have 4 cores I was hoping to be able to reduce this.