Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

44
LINES

< > BotCompany Repo | #1006733 // framesFromVideo_reordering

JavaX fragment (include)

1  
!include once #1025007 // JCodec
2  
3  
static int framesFromVideo_bufferSize = 7;
4  
static bool framesFromVideo_verbose;
5  
6  
static IterableIterator<BufferedImage> framesFromVideo_reordering(File video) ctex {
7  
  final int bufferSize = framesFromVideo_bufferSize;
8  
  final bool verbose = framesFromVideo_verbose;
9  
  final FileChannelWrapper ch = NIOUtils.readableChannel(video);
10  
  final AWTFrameGrab8Bit grab = AWTFrameGrab8Bit.createAWTFrameGrab8Bit(ch);
11  
  
12  
  ret iteratorFromFunction(new O {
13  
    new TreeMap<Double, BufferedImage> reorderBuffer;
14  
    bool done;
15  
    
16  
    void grab ctex {
17  
      if (verbose) print("Grabbing (" + l(reorderBuffer) + ")");
18  
      PictureWithMetadata8Bit pmd = grab.getNativeFrameWithMetadata();
19  
      if (pmd == null) {
20  
        done = true;
21  
        NIOUtils.closeQuietly(ch);
22  
      } else {
23  
        BufferedImage img = AWTUtil.toBufferedImage8Bit(pmd.getPicture());
24  
        reorderBuffer.put(pmd.getTimestamp(), img);
25  
      }
26  
    }
27  
  
28  
    O get() {
29  
      while (!done && l(reorderBuffer) < bufferSize)
30  
        grab();
31  
        
32  
      if (done || reorderBuffer.size() >= bufferSize) {
33  
        if (empty(reorderBuffer)) null;
34  
        double leastPts = firstKey(reorderBuffer);
35  
        BufferedImage img = reorderBuffer.get(leastPts);
36  
        reorderBuffer.remove(leastPts);
37  
        if (verbose) print("Giving (" + l(reorderBuffer) + ")");
38  
        ret img;
39  
      }
40  
      null;
41  
    }
42  
  });
43  
  // TODO: close file when not all frames are grabbed
44  
}

Author comment

Began life as a copy of #1006727

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1006733
Snippet name: framesFromVideo_reordering
Eternal ID of this version: #1006733/15
Text MD5: 5d724234a1fc233ebb5c0b1daaad909b
Author: stefan
Category: javax video
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-01 02:13:24
Source code size: 1502 bytes / 44 lines
Pitched / IR pitched: No / No
Views / Downloads: 580 / 551
Version history: 14 change(s)
Referenced in: [show references]