Thursday, 11 September 2014

Recovering photos from iPOD. (convert ITHMB files to *.png)

Used the following method to recover photos stuck in first generation ipod.

Had lost the originals but found the photos safe in the ipod. iPod converts the originals to small size and stores. Apple does not support this. Asked in 2 different stores.

So had to rely on online help. imageMagick utility converts the photos from uyvy format to png. The only thing required is to get individual photos from the big ITHMB files. The following JAVA code did that.

The ITHMB file name and image sizes are as below:

 1019_*.ithmb offset: 7603200, imgsize: 691200 
 1020_*.ithmb offset: 851840, imgsize: 77440
 1009_*.ithmb offset: 27720, imgsize: 2520
 1015_*.ithmb offset: 251680, imgsize: 22880

We use the 1019_*.ithmb file as its meant for TV output. (720x480 interlaced UYVY (YUV 4:2:2) - used for TV output - 691200 bytes each single thumbnail)

Read details here.
Step 1: The following program will read the ITHMB file and separate out the photos into *.uyvy format.
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;

public class ReadITHMBfile {

static int count = 1,fileCount = 1;
static byte[] intFis = new byte[1];
static BufferedInputStream fis = null;
static BufferedOutputStream fos = null;
static String ithmbExt = ".ithmb", pngExt = ".png";
static Path startingDir;
static private final PathMatcher matcher = null;

public static void main(String[] args)   // unit testing
{
/*if (args[0].length() == 0 )
{
throw new IllegalArgumentException("Pass Directory containing .ITHMB files as Argument");
}

startingDir = Paths.get(args[0]);


matcher = FileSystems.getDefault().getPathMatcher(startingDir+ITHMBFileName);
        Files.walkFileTree(startingDir, matcher);
        finder.done();*/
String ITHMBFileName = "F1019_2";

File fInput  = new File("/home/raj/Pictures/"+ ITHMBFileName + ithmbExt);
File fOutput = new File ("/home/raj/Pictures/FromiPOD/"+ ITHMBFileName +"_"+ fileCount + ".uyvy");

try { 

fis = new BufferedInputStream(new FileInputStream(fInput),2048);
fos = new BufferedOutputStream(new FileOutputStream(fOutput));

while ( fis.read(intFis) >= 0)

{
if (count <= (720 * 480 * 2))
{
//StdOut.print(new Character((char)(intFis[0])) + " in Ascii ");
//StdOut.print(intFis[0] + " in Hex ");
//StdOut.println(new Integer(intFis[0]).toHexString(intFis[0]));
fos.write(intFis);
count=count+1;
}
else
{
fos.close();
fileCount++;
fOutput = new File ("/home/raj/Pictures/FromiPOD/"+ ITHMBFileName +"_"+ fileCount + ".uyvy");
fos = new BufferedOutputStream(new FileOutputStream(fOutput));
fos.write(intFis);
count = 2;
}
}
}
catch (IOException e) 

e.printStackTrace(); 
System.err.println("Error generating uyvy file"); 
}

finally {

try {
fis.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}

}

}

}



Step 2: Download and install the imageMagick utility.
Step 3: Create a mask.png file using the following command. (convert is an imageMagick utility)
convert xc:black xc:white -append -write mpr:m +delete -size 720x400 tile:mpr:m mask.png

Step 4: Using the mask now convert each *.uyvy file to *.png file.
On Linux
for i in {1..759};
 do
 convert -size 720x480 -depth 16 -sampling-factor 4:2:2 F1019_2_$i.uyvy -crop 100%x50% -filter Point -resize 100%x200% mask.png -composite F1019_2_$i.png
done


5 comments:

Angel Bertín said...

Hi, I used your code (thank you, it's great) and convert my uyvy files, but I only get images "made of noise" only I saw a lot o colors lines. No images.

What can I do? please help!

rajendraS said...

Sorry Angel Bertin, saw the comment late (very).. today. Can you please let me know the file (ithmb file) used, the size of the file in bytes and the number of images.

Unknown said...

Hi Rajendra,
thanks for really good post!
Could you please help me to amend your code to process my ithmb file?

Thanks a lot.

Michal

rajendraS said...

Sure Michal-

How many photos do you have and whats the size of the ithmb file?

Unknown said...

I've already managed what I needed. Thank you anyway.