本文整理汇总了Java中org.bytedeco.javacv.FFmpegFrameGrabber类的典型用法代码示例。如果您正苦于以下问题:Java FFmpegFrameGrabber类的具体用法?Java FFmpegFrameGrabber怎么用?Java FFmpegFrameGrabber使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FFmpegFrameGrabber类属于org.bytedeco.javacv包,在下文中一共展示了FFmpegFrameGrabber类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadData
import org.bytedeco.javacv.FFmpegFrameGrabber; //导入依赖的package包/类
protected List<Writable> loadData(File file, InputStream inputStream) throws IOException {
List<Writable> ret = new ArrayList<>();
try (FFmpegFrameGrabber grabber = inputStream != null ? new FFmpegFrameGrabber(inputStream)
: new FFmpegFrameGrabber(file.getAbsolutePath())) {
grabber.setSampleFormat(AV_SAMPLE_FMT_FLT);
grabber.start();
Frame frame;
while ((frame = grabber.grab()) != null) {
while (frame.samples != null && frame.samples[0].hasRemaining()) {
for (int i = 0; i < frame.samples.length; i++) {
ret.add(new FloatWritable(((FloatBuffer) frame.samples[i]).get()));
}
}
}
}
return ret;
}
示例2: main
import org.bytedeco.javacv.FFmpegFrameGrabber; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(args[0]);
grabber.start();
int i = 0;
opencv_core.IplImage img = null;
int max = Integer.parseInt(args[2]);
if (max <= 0) {
max = Integer.MAX_VALUE;
}
while (i++ < max) {
opencv_core.IplImage source = grabber.grab();
if (img == null) {
opencv_core.CvSize size = cvSize(source.width() / 2, source.height() / 2);
img = opencv_core.IplImage.create(size, source.depth(), source.nChannels());
}
cvResize(source, img);
cvSaveImage(String.format(args[1] + "/%05d.jpg", i), img);
}
System.out.println("done, got " + i + " images");
}
示例3: configureThumbnail
import org.bytedeco.javacv.FFmpegFrameGrabber; //导入依赖的package包/类
/**
* Configures the thumbnails for the given uploadId
* @param uploadId The session id
* @return Result
* @throws Exception
* @throws IOException
* @throws ClientProtocolException
*/
protected StatusResult configureThumbnail(String uploadId) throws Exception, IOException, ClientProtocolException {
try (FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(videoFile)) {
frameGrabber.start();
Java2DFrameConverter converter = new Java2DFrameConverter();
int width = frameGrabber.getImageWidth();
int height = frameGrabber.getImageHeight();
long length = frameGrabber.getLengthInTime();
BufferedImage bufferedImage;
if (thumbnailFile == null) {
bufferedImage = MyImageUtils.deepCopy(converter.convert(frameGrabber.grabImage()));
thumbnailFile = File.createTempFile("insta", ".jpg");
log.info("Generated thumbnail: " + thumbnailFile.getAbsolutePath());
ImageIO.write(bufferedImage, "JPG", thumbnailFile);
} else {
bufferedImage = ImageIO.read(thumbnailFile);
}
holdOn();
StatusResult thumbnailResult = api.sendRequest(new InstagramUploadPhotoRequest(thumbnailFile, caption, uploadId));
log.info("Thumbnail result: " + thumbnailResult);
StatusResult configureResult = api.sendRequest(InstagramConfigureVideoRequest.builder().uploadId(uploadId)
.caption(caption)
.duration(length)
.width(width)
.height(height)
.build());
log.info("Video configure result: " + configureResult);
return configureResult;
}
}
示例4: start
import org.bytedeco.javacv.FFmpegFrameGrabber; //导入依赖的package包/类
@Override
public void start() {
FFmpegFrameGrabber grabberFF = new FFmpegFrameGrabber(this.cameraDescription);
grabberFF.setImageMode(FrameGrabber.ImageMode.COLOR);
this.setPixelFormat(PixelFormat.BGR);
grabberFF.setFormat(this.imageFormat);
grabberFF.setImageWidth(width());
grabberFF.setImageHeight(height());
grabberFF.setFrameRate(frameRate);
try {
grabberFF.start();
this.grabber = grabberFF;
this.isConnected = true;
} catch (Exception e) {
System.err.println("Could not start frameGrabber... " + e);
System.err.println("Could not camera start frameGrabber... " + e);
System.err.println("Camera ID " + this.systemNumber + " could not start.");
System.err.println("Check cable connection, ID and resolution asked.");
this.grabber = null;
}
}
示例5: VidImageSequence
import org.bytedeco.javacv.FFmpegFrameGrabber; //导入依赖的package包/类
public VidImageSequence(File f) throws IOException {
super(f.getName());
try {
g = new FFmpegFrameGrabber(f);
g.start();
width = g.getImageWidth();
height = g.getImageHeight();
frames = g.getLengthInFrames();
} catch (Exception e) {
throw new IOException();
}
}
示例6: initialize
import org.bytedeco.javacv.FFmpegFrameGrabber; //导入依赖的package包/类
@Override
public void initialize() throws IOException {
try {
frameGrabber = new FFmpegFrameGrabber(path);
frameGrabber.start();
final double fps = frameGrabber.getFrameRate();
fpsSocket.setValue(fps);
frameCount = frameGrabber.getLengthInFrames();
if (frameCount <= 1) {
// Only one frame, no point in scheduling automatic updates to grab the same
// image over and over
manualGrabberService.submit(this::grabNextFrame);
} else {
grabberFuture = Executors.newSingleThreadScheduledExecutor(DaemonThread::new)
.scheduleAtFixedRate(
() -> {
if (!isPaused()) {
grabNextFrame();
}
},
0L,
(long) (1e3 / fps),
TimeUnit.MILLISECONDS
);
}
} catch (FrameGrabber.Exception e) {
throw new IOException("Could not open video file " + path, e);
}
}
示例7: track
import org.bytedeco.javacv.FFmpegFrameGrabber; //导入依赖的package包/类
/**
* Read a video from a URL, and perform pedestrian tracking on it.
*
* @param videoStream the video stream to conduct tracking on.
* @return a set of tracklets of pedestrians.
*/
@Nonnull
@Override
public Tracklet[] track(@Nonnull InputStream videoStream) throws FrameGrabber.Exception {
FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(videoStream);
av_log_set_level(AV_LOG_QUIET);
frameGrabber.start();
logger.debug("Initialized video decoder!");
long trackerPointer = initialize(frameGrabber.getImageWidth(), frameGrabber.getImageHeight(), 3, conf);
logger.debug("Initialized tracker!");
int cnt = 0;
// Every time a frame is retrieved during decoding, it is immediately fed into the tracker,
// so as to save runtime memory.
while (true) {
Frame frame;
try {
frame = frameGrabber.grabImage();
} catch (FrameGrabber.Exception e) {
logger.error("On grabImage: " + e);
break;
}
if (frame == null) {
break;
}
final byte[] buf = new byte[frame.imageHeight * frame.imageWidth * frame.imageChannels];
final opencv_core.Mat cvFrame = new OpenCVFrameConverter.ToMat().convert(frame);
cvFrame.data().get(buf);
int ret = feedFrame(trackerPointer, buf);
if (ret != 0) {
break;
}
++cnt;
if (cnt % 1000 == 0) {
logger.debug("Tracked " + cnt + " frames!");
}
}
logger.debug("Totally processed " + cnt + " framed!");
logger.debug("Getting targets...");
Tracklet[] targets = getTargets(trackerPointer);
logger.debug("Got " + targets.length + " targets!");
free(trackerPointer);
for (int i = 0; i < targets.length; ++i) {
targets[i].numTracklets = targets.length;
targets[i].id.serialNumber = i;
}
return targets;
}
示例8: open
import org.bytedeco.javacv.FFmpegFrameGrabber; //导入依赖的package包/类
@Override
public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
frameId = 0;
sampleID = 0;
sampleFrames = ConfigUtil.getInt(map, "sampleFrames", 1);
firstFrameId = getInt(map, "firstFrameId");
lastFrameId = getInt(map, "lastFrameId");
SOURCE_FILE = getString(map, "videoSourceFile");
grabber = new FFmpegFrameGrabber(SOURCE_FILE);
System.out.println("Created capture: " + SOURCE_FILE);
W = ConfigUtil.getInt(map, "width", 640);
H = ConfigUtil.getInt(map, "height", 480);
delayInMS = getInt(map, "inputFrameDelay");
this.collector = spoutOutputCollector;
try {
grabber.start();
while (++frameId < firstFrameId)
grabber.grab();
} catch (FrameGrabber.Exception e) {
e.printStackTrace();
}
//kp.deallocate();
if (Debug.topologyDebugOutput)
System.out.println("Grabber started");
if (Debug.timer)
System.out.println("TIME=" + System.currentTimeMillis());
//TODO: caustion, for RedisStreamProducerBeta version, we reajust the start and end frameID!!!
int diff = lastFrameId - firstFrameId + 1;
frameId = 0;
endFrameID = frameId + diff;
openTimeStamp = System.currentTimeMillis();
}
示例9: FFMpegFrameFinder
import org.bytedeco.javacv.FFmpegFrameGrabber; //导入依赖的package包/类
public FFMpegFrameFinder(File file) throws FrameGrabber.Exception {
frameGrabber = new FFmpegFrameGrabber(file);
converter = new Java2DFrameConverter();
frameGrabber.start();
}