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
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