MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / readAVI

Method readAVI

ij/src/main/java/ij/plugin/AVI_Reader.java:575–642  ·  view source on GitHub ↗

Read into a (virtual) stack

(String path)

Source from the content-addressed store, hash-verified

573
574 /** Read into a (virtual) stack */
575 private void readAVI(String path) throws Exception, IOException {
576 if (!headerOK) // we have not read the header yet?
577 openAndReadHeader(path);
578 else {
579 File file = new File(path); // open if currently not open
580 raFile = new RandomAccessFile(file, "r");
581 }
582 startTime += System.currentTimeMillis();// taking previously elapsed time into account
583 /** MOVED UP HERE BY JSP*/
584 if (lastFrame > 0) // last frame number to read: from Dialog
585 lastFrameToRead = lastFrame;
586 if (lastFrame < 0 && dwTotalFrames > 0) // negative means "end frame minus ..."
587 lastFrameToRead = dwTotalFrames+lastFrame;
588 if (lastFrameToRead < firstFrame) // no frames to read
589 return;
590 boolean hasIndex = (dwFlags & AVIF_HASINDEX) != 0;
591 if (isVirtual || firstFrame>1) { // avoid scanning frame-by-frame where we only need the positions
592 frameInfos = new Vector<long[]>(100); // holds frame positions, sizes and time since start
593 long nextPosition = -1;
594 if (indexPosition > 0) { // attempt to get AVI2.0 index instead of scanning for all frames
595 raFile.seek(indexPosition);
596 nextPosition = findFourccAndRead(FOURCC_indx, false, indexPositionEnd, false);
597 }
598 if (hasIndex && (frameInfos==null ||frameInfos.size()==0)) { // got nothing from indx, attempt to read AVI 1 index 'idx1'
599 raFile.seek(headerPositionEnd);
600 moviPosition = findFourccAndSkip(FOURCC_movi, true, fileSize); // go behind the 'movi' list
601 if (moviPosition<0)
602 throw new Exception("AVI File has no movie data");
603 long positionBehindMovie = raFile.getFilePointer();
604 while (positionBehindMovie < fileSize-8) {
605 if (verbose)
606 IJ.log("searching for 'idx1' at 0x"+Long.toHexString(positionBehindMovie));
607 raFile.seek(positionBehindMovie);
608 if (positionBehindMovie > FOUR_GB)
609 isOversizedAvi1 = true;
610 nextPosition = findFourccAndRead(FOURCC_idx1, false, fileSize, false);
611 if (nextPosition >= 0) //AVI-1 index 'idx1' found
612 break;
613 positionBehindMovie += FOUR_GB; //maybe position was wrong because it was a 32-bit number, but > 4GB?
614 }
615 }
616 if (verbose)
617 IJ.log("'frameInfos' has "+frameInfos.size()+" entries");
618 }
619 if (isVirtual && frameInfos.size()>0) // Virtual Stack only needs reading the index
620 return;
621 // Read AVI (movie data) frame by frame - if no index tag is present the pointers
622 // for the virtual AVI stack will be read here
623 raFile.seek(headerPositionEnd);
624 if (firstFrame>1 && frameInfos.size()>0) {
625 long[] frameInfo = (long[])frameInfos.get(0);
626 raFile.seek(frameInfo[0]-8); // chunk starts 8 bytes before frame data
627 frameNumber = firstFrame;
628 if (verbose)
629 IJ.log("directly go to frame "+firstFrame+" @ 0x"+Long.toHexString(frameInfo[0]-8));
630 readMovieData(fileSize);
631 } else {
632 frameNumber = 1;

Callers 1

makeStackMethod · 0.95

Calls 9

openAndReadHeaderMethod · 0.95
findFourccAndReadMethod · 0.95
findFourccAndSkipMethod · 0.95
logMethod · 0.95
readMovieDataMethod · 0.95
seekMethod · 0.65
getFilePointerMethod · 0.65
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected