/** Read 8-byte int with Intel (little-endian) byte order * (note: RandomAccessFile.readLong has other byte order than AVI) */ final long readLong() throws IOException { long low = readInt() & 0x00000000FFFFFFFFL; long high = readInt() & 0x00000000FFFFFFFFL; long result = high <<32 | low; return (long) result; //(high << 32 | low); } /** Read 4-byte int with Intel (little-endian) byte order
/** Read 8-byte int with Intel (little-endian) byte order * (note: RandomAccessFile.readLong has other byte order than AVI) */ final long readLong() throws IOException { long low = readInt() & 0x00000000FFFFFFFFL; long high = readInt() & 0x00000000FFFFFFFFL; long result = high <<32 | low; return (long) result; //(high << 32 | low); } /** Read 4-byte int with Intel (little-endian) byte order
/** Read type of next chunk that is not JUNK. * Returns type (or 0 if no non-JUNK chunk until endPosition) */ private int readType(long endPosition) throws IOException { while (true) { long pos = raFile.getFilePointer(); if (pos%paddingGranularity!=0) { pos = (pos/paddingGranularity+1)*paddingGranularity; raFile.seek(pos); //pad to even address } if (pos >= endPosition) return 0; int type = readInt(); if (type != FOURCC_JUNK) return type; long size = readInt()&SIZE_MASK; if (verbose) IJ.log("Skip JUNK: "+posSizeString(size)); raFile.seek(raFile.getFilePointer()+size); //skip junk } }
/** Read type of next chunk that is not JUNK. * Returns type (or 0 if no non-JUNK chunk until endPosition) */ private int readType(long endPosition) throws IOException { while (true) { long pos = raFile.getFilePointer(); if (pos%paddingGranularity!=0) { pos = (pos/paddingGranularity+1)*paddingGranularity; raFile.seek(pos); //pad to even address } if (pos >= endPosition) return 0; int type = readInt(); if (type != FOURCC_JUNK) return type; long size = readInt()&SIZE_MASK; if (verbose) IJ.log("Skip JUNK: "+posSizeString(size)); raFile.seek(raFile.getFilePointer()+size); //skip junk } }
void readAviHeader() throws Exception, IOException { //'avih' dwMicroSecPerFrame = readInt(); dwMaxBytesPerSec = readInt(); dwReserved1 = readInt(); //in newer avi formats, this is dwPaddingGranularity? dwFlags = readInt(); dwTotalFrames = readInt(); dwInitialFrames = readInt(); dwStreams = readInt(); dwSuggestedBufferSize = readInt(); dwWidth = readInt(); dwHeight = readInt(); // dwReserved[4] follows, ignored if (verbose) { IJ.log("AVI HEADER (avih):"+timeString()); IJ.log(" dwMicroSecPerFrame=" + dwMicroSecPerFrame); IJ.log(" dwMaxBytesPerSec=" + dwMaxBytesPerSec); IJ.log(" dwReserved1=" + dwReserved1); IJ.log(" dwFlags=" + dwFlags); IJ.log(" dwTotalFrames=" + dwTotalFrames); IJ.log(" dwInitialFrames=" + dwInitialFrames); IJ.log(" dwStreams=" + dwStreams); IJ.log(" dwSuggestedBufferSize=" + dwSuggestedBufferSize); IJ.log(" dwWidth=" + dwWidth); IJ.log(" dwHeight=" + dwHeight); } }
void readAviHeader() throws Exception, IOException { //'avih' dwMicroSecPerFrame = readInt(); dwMaxBytesPerSec = readInt(); dwReserved1 = readInt(); //in newer avi formats, this is dwPaddingGranularity? dwFlags = readInt(); dwTotalFrames = readInt(); dwInitialFrames = readInt(); dwStreams = readInt(); dwSuggestedBufferSize = readInt(); dwWidth = readInt(); dwHeight = readInt(); // dwReserved[4] follows, ignored if (verbose) { IJ.log("AVI HEADER (avih):"+timeString()); IJ.log(" dwMicroSecPerFrame=" + dwMicroSecPerFrame); IJ.log(" dwMaxBytesPerSec=" + dwMaxBytesPerSec); IJ.log(" dwReserved1=" + dwReserved1); IJ.log(" dwFlags=" + dwFlags); IJ.log(" dwTotalFrames=" + dwTotalFrames); IJ.log(" dwInitialFrames=" + dwInitialFrames); IJ.log(" dwStreams=" + dwStreams); IJ.log(" dwSuggestedBufferSize=" + dwSuggestedBufferSize); IJ.log(" dwWidth=" + dwWidth); IJ.log(" dwHeight=" + dwHeight); } }
void readStreamHeader() throws Exception, IOException { //'strh' fccStreamHandler = readInt(); dwStreamFlags = readInt(); dwPriorityLanguage = readInt(); dwStreamInitialFrames = readInt(); dwStreamScale = readInt(); dwStreamRate = readInt(); dwStreamStart = readInt(); dwStreamLength = readInt(); dwStreamSuggestedBufferSize = readInt(); dwStreamQuality = readInt(); dwStreamSampleSize = readInt();
void readStreamHeader() throws Exception, IOException { //'strh' fccStreamHandler = readInt(); dwStreamFlags = readInt(); dwPriorityLanguage = readInt(); dwStreamInitialFrames = readInt(); dwStreamScale = readInt(); dwStreamRate = readInt(); dwStreamStart = readInt(); dwStreamLength = readInt(); dwStreamSuggestedBufferSize = readInt(); dwStreamQuality = readInt(); dwStreamSampleSize = readInt();
if ((raFile.getFilePointer()+16) >endPosition) break; int dwChunkId = readInt(); int dwFlags = readInt(); int dwOffset = readInt(); int dwSize = readInt(); if (pos < moviPosition) continue; // frame must be in 'movi' list raFile.seek(pos); int chunkIdAtPos = readInt(); // see whether this offset points to the desired chunk
/** Open the file with given path and read its header */ private void openAndReadHeader (String path) throws Exception, IOException { startTime = System.currentTimeMillis(); if (verbose) IJ.log("OPEN AND READ AVI FILE HEADER "+timeString()); File file = new File(path); // o p e n raFile = new RandomAccessFile(file, "r"); raFilePath = path; fileSize = raFile.length(); int fileType = readInt(); // f i l e h e a d e r if (verbose) IJ.log("File header: File type='"+fourccString(fileType)+"' (should be 'RIFF')"+timeString()); if (fileType != FOURCC_RIFF) throw new Exception("Not an AVI file."); aviSize = readInt() & SIZE_MASK; //size of AVI chunk int riffType = readInt(); if (verbose) IJ.log("File header: RIFF type='"+fourccString(riffType)+"' (should be 'AVI ')"); if (riffType != FOURCC_AVI) throw new Exception("Not an AVI file."); findFourccAndRead(FOURCC_hdrl, true, fileSize, true); startTime -= System.currentTimeMillis(); //becomes minus elapsed Time headerOK = true; }
/** Open the file with given path and read its header */ private void openAndReadHeader (String path) throws Exception, IOException { startTime = System.currentTimeMillis(); if (verbose) IJ.log("OPEN AND READ AVI FILE HEADER "+timeString()); File file = new File(path); // o p e n raFile = new RandomAccessFile(file, "r"); raFilePath = path; fileSize = raFile.length(); int fileType = readInt(); // f i l e h e a d e r if (verbose) IJ.log("File header: File type='"+fourccString(fileType)+"' (should be 'RIFF')"+timeString()); if (fileType != FOURCC_RIFF) throw new Exception("Not an AVI file."); aviSize = readInt() & SIZE_MASK; //size of AVI chunk int riffType = readInt(); if (verbose) IJ.log("File header: RIFF type='"+fourccString(riffType)+"' (should be 'AVI ')"); if (riffType != FOURCC_AVI) throw new Exception("Not an AVI file."); findFourccAndRead(FOURCC_hdrl, true, fileSize, true); startTime -= System.currentTimeMillis(); //becomes minus elapsed Time headerOK = true; }
/** Find the next position of fourcc or LIST fourcc, but does not read it, only * returns the first position inside the fourcc chunk and puts the file pointer * behind the fourcc chunk (if successful). * If not found, returns -1 */ private long findFourccAndSkip(int fourcc, boolean isList, long endPosition) throws IOException { while (true) { int type = readType(endPosition); if (type == 0) //reached endPosition without finding return -1; long size = readInt() & SIZE_MASK; long chunkPos = raFile.getFilePointer(); long nextPos = chunkPos + size; //note that 'size' of a list includes the 'type' that follows now if (isList && type == FOURCC_LIST) type = readInt(); if (verbose) IJ.log("Searching for (to skip) '"+fourccString(fourcc)+"', found "+fourccString(type)+ "' data "+posSizeString(chunkPos, size)); raFile.seek(nextPos); if (type == fourcc) return chunkPos; //found and skipped, breaks the loop } }
/** Find the next position of fourcc or LIST fourcc, but does not read it, only * returns the first position inside the fourcc chunk and puts the file pointer * behind the fourcc chunk (if successful). * If not found, returns -1 */ private long findFourccAndSkip(int fourcc, boolean isList, long endPosition) throws IOException { while (true) { int type = readType(endPosition); if (type == 0) //reached endPosition without finding return -1; long size = readInt() & SIZE_MASK; long chunkPos = raFile.getFilePointer(); long nextPos = chunkPos + size; //note that 'size' of a list includes the 'type' that follows now if (isList && type == FOURCC_LIST) type = readInt(); if (verbose) IJ.log("Searching for (to skip) '"+fourccString(fourcc)+"', found "+fourccString(type)+ "' data "+posSizeString(chunkPos, size)); raFile.seek(nextPos); if (type == fourcc) return chunkPos; //found and skipped, breaks the loop } }
/** Read AVIX chunks following the first RIFF AVI for large files (sequential reading frame-by-frame beyond the first chunk) **/ private void readAVIX(long endPosition) throws Exception, IOException { if (verbose) IJ.log("Trying to read AVIX"+timeString()); int riffType = readInt(); if (verbose) IJ.log("File header: RIFF type='"+fourccString(riffType)+"' (should be 'AVIX')"); if (riffType != FOURCC_AVIX) throw new Exception("Not an AVI file."); findFourccAndRead(FOURCC_movi, true, fileSize, true); //read movie data }
/** Read AVIX chunks following the first RIFF AVI for large files (sequential reading frame-by-frame beyond the first chunk) **/ private void readAVIX(long endPosition) throws Exception, IOException { if (verbose) IJ.log("Trying to read AVIX"+timeString()); int riffType = readInt(); if (verbose) IJ.log("File header: RIFF type='"+fourccString(riffType)+"' (should be 'AVIX')"); if (riffType != FOURCC_AVIX) throw new Exception("Not an AVI file."); findFourccAndRead(FOURCC_movi, true, fileSize, true); //read movie data }
int type = readType(endPosition); if (type==0) break; //endPosition of 'movi' reached? long size = readInt() & SIZE_MASK; long pos = raFile.getFilePointer(); long nextPos = pos + size;
int type = readType(endPosition); if (type==0) break; //endPosition of 'movi' reached? long size = readInt() & SIZE_MASK; long pos = raFile.getFilePointer(); long nextPos = pos + size;
return true; case FOURCC_strh: int streamType = readInt(); if (streamType != FOURCC_vids) { if (verbose)