Uses 1860K of libraries. Click here for Pure Java version (653L/5K/16K).
1 | !7 |
2 | lib 1006715 // jcodec 0.2.0 |
3 | lib 1006717 // jcodec 0.2.0 javase |
4 | |
5 | import org.jcodec.api.awt.AWTSequenceEncoder8Bit; |
6 | |
7 | /** |
8 | * This class is part of JCodec ( www.jcodec.org ) This software is distributed |
9 | * under FreeBSD License |
10 | * |
11 | * A demo of SequenceEncoder that generates a video with a bouncing ball |
12 | * |
13 | * @author Stan Vitvitskyy |
14 | * |
15 | */ |
16 | p { |
17 | final int speed = 4; |
18 | final int ballSize = 40; |
19 | |
20 | File outFile = prepareProgramFile("test.mp4"); |
21 | int framesToEncode = 100; |
22 | |
23 | AWTSequenceEncoder8Bit enc = AWTSequenceEncoder8Bit.create25Fps(outFile); |
24 | enc.getEncoder().setKeyInterval(25); |
25 | |
26 | long totalNano = 0; |
27 | BufferedImage image = new BufferedImage(640, 480, BufferedImage.TYPE_3BYTE_BGR); |
28 | for (int i = 0, x = 0, y = 0, incX = speed, incY = speed; i < framesToEncode; i++, x += incX, y += incY) { |
29 | Graphics g = image.getGraphics(); |
30 | g.setColor(Color.BLACK); |
31 | g.fillRect(0, 0, image.getWidth(), image.getHeight()); |
32 | g.setColor(Color.YELLOW); |
33 | if (x >= image.getWidth() - ballSize) |
34 | incX = -speed; |
35 | if (y >= image.getHeight() - ballSize) |
36 | incY = -speed; |
37 | if (x <= 0) |
38 | incX = speed; |
39 | if (y <= 0) |
40 | incY = speed; |
41 | g.fillOval(x, y, ballSize, ballSize); |
42 | long start = System.nanoTime(); |
43 | enc.encodeImage(image); |
44 | totalNano += System.nanoTime() - start; |
45 | } |
46 | enc.finish(); |
47 | |
48 | System.out.println("FPS: " + ((1000000000L * framesToEncode) / totalNano)); |
49 | } |
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: | #1006716 |
Snippet name: | Make silent .mp4 (SequenceEncoderDemo JCodec 0.2.0) - WORKS! |
Eternal ID of this version: | #1006716/5 |
Text MD5: | 66cb42fa265acd1054c3cd3478c45c4b |
Transpilation MD5: | 0c7c233377ceee1019839f99d967ac51 |
Author: | stefan |
Category: | javax video |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-02-02 22:50:17 |
Source code size: | 1503 bytes / 49 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 957 / 1331 |
Version history: | 4 change(s) |
Referenced in: | [show references] |