You are not logged in.
Hi,
I've found this little script for converting RAW files to JPGs:
raw_convert()
{
if [ ! -d ./processed_images ]; then mkdir ./processed_images; fi;
# processes raw files
for f in *.CR2;
do
echo "Processing $f"
ufraw-batch \
--wb=camera \
--exposure=auto \
--out-type=jpeg \
--compression=96 \
--out-path=./processed_images \
$f
done
cd ./processed_images
# change the image names
for i in *.jpg;
do
mv "$i" "${i/.jpg}"_r.jpg;
done
for i in *.jpg;
do
mv "$i" "${i/imgp/_igp}";
done
}
It works great, except that I would like it to run recursively. I have a folder structure like this: 2012 > 06 > 03 > individual raw files. It's real pain that I must go to each and every folder just to run the script, when it could be so easy. If only I knew how to do it
I would be really glad if someone could spare some time and help me with this.
PS: I don't need it to be in bash. I just need it to work.
Last edited by paralax (2012-07-16 19:33:04)
Offline
Change this line:
for f in *.CR2;
to a find command.
The easiest change - given that I assume your not to fluent in bash - would be to use something like
for f in `find . -type f -name '*.CR2'`;
This would most closely mimic the behavior of the original while adding a recursive directory search (every CR2 file below the current working directory).
However, you could also replace the for loop itself with a similar find command using find's 'exec' option. See `man find` to learn more about that.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thank you very much. Recursive search now works without problem. I just forgot to mention that I would like to have JPGs in appropriate folder next to my RAW files.
Something like this: 2010 > 06 > 15 > (folder with JPGs or just JPGs without the extra folder) + RAW files. That would be absolutely amazing.
I understand that the main problem is that the script checks for folder "processed_images" in the directory I run it from. And then it just puts everything in there.
Sadly I have no idea how to make it work. I have a very limited experience with programming and no experience at all with bash.
Offline
The easiest change - given that I assume your not to fluent in bash - would be to use something like
for f in `find . -type f -name '*.CR2'`;
This is the wrong way to use find. for is meant for iterating over lists, not the output of commands.
This would be far more appropriate...
find . -type f -name '*.CR2' -print0 | while read -rd ''; do
something-with "$REPLY"
done
Last edited by falconindy (2012-07-15 14:46:32)
Offline
Yes, that's what I was getting at with the second part of my post. I kept it as close to the original as possible so it would be easy to implement.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Paralax,
you also might want to have a look at my recurseM3U script which is written in Python:
https://bbs.archlinux.org/viewtopic.php … 9#p1123189
It searchs recursively through all directories from the current level and then creates an M3U playlist inside each subdir. It should be not too hard to adjust the script for your needs.
While I like to do use bash scripts a lot myself, I still think they are a PITA for certain activities (e.g. control structures, loops, string processing) compared to using something like Perl or Python.
Drop me a PM if you need further help.
-D$
Edit: This is how the script could look like in Python:
#!/usr/bin/python
# -*- coding: utf8 -*-
import os
# Grab all files inside subdirectories within the current directory
search_files ="find . -name *.CR2"
# Loop through all found files
for source_file in os.popen (search_files):
# Remove \n at end of found files
source_file = source_file[:-1]
print "Processing file " + source_file
os.popen ("ufraw-batch --wb=camera --exposure=auto --out-type=jpeg --compression=96 --out-path=./processed_images " + source_file )
Last edited by Darksoul71 (2012-07-16 08:01:23)
My archlinux x86_64 host:
AMD E350 (2x1.6GHz) / 8GB DDR3 RAM / GeForce 9500GT (passive) / Arch running from 16GB USB Stick
Offline
Darksoul71 if you should ever visit Czech Republic let me know. I would buy you all the beer you can drink because it works beautifully Thank you!
I've made only one small adjustment
........ --compression=96 " + source_file )
The script was complaining that the directory "processed_images" doesn't exist. But since I prefer to have jpgs directly next to my raw files it was an easy fix.
Last edited by paralax (2012-07-16 08:52:00)
Offline
paralax, you are welcome ! Do not offer such things unless you know how much beer the other one is able to drink
No, just kidding. Thanks for the offer. Unfortunately the Czech Republic is not really that close to western germany.
Sorry for the directory part with processed_images. I simply copied over the commandline from your bash example and adapted it to my few lines of Python code. I know that a lot of people prefer Bash over Python or Perl but for me Python offers both more readable code and you are able to solve most problems in small steps.
Do not forget to add Solved to your title. Thanks....
My archlinux x86_64 host:
AMD E350 (2x1.6GHz) / 8GB DDR3 RAM / GeForce 9500GT (passive) / Arch running from 16GB USB Stick
Offline
Have a look at Exiftools, much faster than ufraw; plus is able to extract the jpg of the Metadata's Canon Raw files, which makes it blazing fast.
exiftool -fileOrder DateTimeOriginal -b -previewImage -w <name>.jpg -ext CR2 <CR2's location>
http://www.archlinux.org/packages/extra … -exiftool/
http://www.sno.phy.queensu.ca/~phil/exiftool/
Last edited by ga01f4733 (2012-07-16 15:33:26)
There are no foreign lands. It is the traveler only who is foreign. --R.L Stevenson
Offline