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

82
LINES

< > BotCompany Repo | #1033432 // Screenshotting with VLCJ!! (30 fps)

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Transpiled version (8024L) is out of date.

1  
// https://stackoverflow.com/a/48214101
2  
3  
// sudo apt install vlc-plugin-access-extra !!!
4  
5  
!7
6  
7  
lib 1400526 // vlcj player (stable version for VLCJ 3)
8  
lib 1400527 // vlcj 3
9  
lib 1400528 lib 1400529 // jna
10  
sS megaLibID = #1400525;
11  
12  
import uk.co.caprica.vlcj.player.*;
13  
import uk.co.caprica.vlcj.player.direct.*;
14  
import uk.co.caprica.vlcj.player.direct.format.*;
15  
16  
static BufferedImage image;
17  
static MediaPlayerFactory factory;
18  
static DirectMediaPlayer mediaPlayer;
19  
static int width, height;
20  
21  
static FPSCounter fps;
22  
23  
p {
24  
  pnl(pairToList(addMegaLibrary(myClassLoader(), megaLibID)));
25  
  fixContextClassLoader();
26  
27  
  width = screenWidth();
28  
  height = screenHeight();
29  
  print(width + "/" + height);
30  
  
31  
  image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(width, height);
32  
  
33  
  image.setAccelerationPriority(1.0f);
34  
35  
  String mrl = "screen://";
36  
  String[] options = {
37  
          ":screen-fps=30",
38  
          ":live-caching=0",
39  
          ":screen-width=" + width,
40  
          ":screen-height=" + height,
41  
          ":screen-left=0",
42  
          ":screen-top=0"
43  
  };
44  
  pnl(options);
45  
  factory = new MediaPlayerFactory();
46  
  mediaPlayer = factory.newDirectMediaPlayer(new TestBufferFormatCallback(), new TestRenderCallback());
47  
  mediaPlayer.playMedia(mrl, options);
48  
}
49  
50  
// Callbacks are required.
51  
sclass TestRenderCallback extends RenderCallbackAdapter {
52  
  public TestRenderCallback() {
53  
    super(((DataBufferInt) image.getRaster().getDataBuffer()).getData());
54  
  }
55  
56  
  @Override
57  
  public void onDisplay(DirectMediaPlayer mediaPlayer, int[] data) {
58  
    if (fps == null) fps = new FPSCounter;
59  
    fps.inc();
60  
    print("Got image data (" + n2(l(data)) + ") - " + fps! + " fps");
61  
    
62  
    // The image data could be manipulated here...
63  
64  
    /* RGB to GRAYScale conversion example */
65  
//            for(int i=0; i < data.length; i++){
66  
//                int argb = data[i];
67  
//                int b = (argb & 0xFF);
68  
//                int g = ((argb >> 8 ) & 0xFF);
69  
//                int r = ((argb >> 16 ) & 0xFF);
70  
//                int grey = (r + g + b + g) >> 2 ; //performance optimized - not real grey!
71  
//                data[i] = (grey << 16) + (grey << 8) + grey;
72  
//            }
73  
//            imagePane.repaint();
74  
  }
75  
}
76  
77  
sclass TestBufferFormatCallback implements BufferFormatCallback {
78  
  @Override
79  
  public BufferFormat getBufferFormat(int sourceWidth, int sourceHeight) {
80  
      return new RV32BufferFormat(width, height);
81  
  }
82  
}

Author comment

Began life as a copy of #1033431

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033432
Snippet name: Screenshotting with VLCJ!! (30 fps)
Eternal ID of this version: #1033432/20
Text MD5: 36369065dab9824dae54d269fa114b33
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-27 14:17:57
Source code size: 2565 bytes / 82 lines
Pitched / IR pitched: No / No
Views / Downloads: 134 / 694
Version history: 19 change(s)
Referenced in: [show references]