Java Code Examples for org.bytedeco.javacv.FFmpegFrameGrabber#start()
The following examples show how to use
org.bytedeco.javacv.FFmpegFrameGrabber#start() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LivePlayTest.java From oim-fx with MIT License | 8 votes |
private static void recordByFrame(FFmpegFrameGrabber grabber, FFmpegFrameRecorder recorder, Boolean status) throws Exception, org.bytedeco.javacv.FrameRecorder.Exception { try {// 建议在线程中使用该方法 grabber.start(); recorder.start(); Frame frame = null; while (status && (frame = grabber.grabFrame()) != null) { recorder.record(frame); } recorder.stop(); grabber.stop(); } finally { if (grabber != null) { grabber.stop(); } } }
Example 2
Source File: JavaCVRecord.java From easyCV with Apache License 2.0 | 6 votes |
/** * 视频源 * * @param src * @return * @throws Exception */ public Recorder from(String src) throws Exception { av_log_set_level(AV_LOG_ERROR); if (src == null) { throw new Exception("源视频不能为空"); } this.src = src; // 采集/抓取器 grabber = new FFmpegFrameGrabber(src); if (hasRTSP(src)) { grabber.setOption("rtsp_transport", "tcp"); } grabber.start();// 开始之后ffmpeg会采集视频信息,之后就可以获取音视频信息 if (width < 0 || height < 0) { width = grabber.getImageWidth(); height = grabber.getImageHeight(); } // 视频参数 audiocodecid = grabber.getAudioCodec(); codecid = grabber.getVideoCodec(); framerate = grabber.getVideoFrameRate();// 帧率 bitrate = grabber.getVideoBitrate();// 比特率 // 音频参数 // 想要录制音频,这三个参数必须有:audioChannels > 0 && audioBitrate > 0 && sampleRate > 0 audioChannels = grabber.getAudioChannels(); audioBitrate = grabber.getAudioBitrate(); if (audioBitrate < 1) { audioBitrate = 128 * 1000;// 默认音频比特率 } sampleRate = grabber.getSampleRate(); return this; }
Example 3
Source File: JavaCVReadAVI.java From Data_Processor with Apache License 2.0 | 6 votes |
public void run() throws Exception, InterruptedException { FFmpegFrameGrabber ffmpegFrameGrabber = FFmpegFrameGrabber.createDefault("C:/Users/Administrator/Desktop/deta/detasource/videoProcess/webwxgetvideo.avi"); ffmpegFrameGrabber.start(); // int fflength = ffmpegFrameGrabber.getLengthInFrames(); // int maxStamp = (int) (ffmpegFrameGrabber.getLengthInTime()/1000000); // int count = 0; while (true) { Frame nowFrame = ffmpegFrameGrabber.grabImage(); // int startStamp = (int) (ffmpegFrameGrabber.getTimestamp() * 1.0/1000000); // double present = (startStamp * 1.0 / maxStamp) * 100; if (nowFrame == null) { System.out.println("!!! Failed cvQueryFrame"); continue; } Java2DFrameConverter paintConverter = new Java2DFrameConverter(); BufferedImage difImage = paintConverter.getBufferedImage(nowFrame, 1); paint(difImage); Thread.sleep(25); } }
Example 4
Source File: CameraFFMPEG.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
/** * TODO: Check the use of this. * @deprecated */ @Deprecated public void startVideo() { FFmpegFrameGrabber grabberFF = new FFmpegFrameGrabber(this.cameraDescription); try { grabberFF.setFrameRate(30); this.setPixelFormat(PixelFormat.BGR); grabberFF.start(); this.grabber = grabberFF; this.setSize(grabber.getImageWidth(), grabber.getImageHeight()); // this.setFrameRate((int) grabberFF.getFrameRate()); grabberFF.setFrameRate(30); this.isConnected = true; } catch (Exception e) { System.err.println("Could not FFMPEG frameGrabber... " + e); System.err.println("Camera ID " + this.cameraDescription + ":" + this.imageFormat + " could not start."); System.err.println("Check cable connection, ID and resolution asked."); this.grabber = null; } }
Example 5
Source File: CameraFFMPEG.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
@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 (FrameGrabber.Exception e) { System.err.println("Could not FFMPEG frameGrabber... " + e); System.err.println("Camera ID " + this.cameraDescription + ":" + this.imageFormat + " could not start."); System.err.println("Check cable connection, ID and resolution asked."); this.grabber = null; } }
Example 6
Source File: ConvertVideoPakcet.java From easyCV with Apache License 2.0 | 5 votes |
/** * 选择视频源 * @param src * @author eguid * @throws Exception */ public ConvertVideoPakcet from(String src) throws Exception { // 采集/抓取器 grabber = new FFmpegFrameGrabber(src); if(src.indexOf("rtsp")>=0) { grabber.setOption("rtsp_transport","tcp"); } grabber.start();// 开始之后ffmpeg会采集视频信息,之后就可以获取音视频信息 if (width < 0 || height < 0) { width = grabber.getImageWidth(); height = grabber.getImageHeight(); } // 视频参数 audiocodecid = grabber.getAudioCodec(); System.err.println("音频编码:" + audiocodecid); codecid = grabber.getVideoCodec(); framerate = grabber.getVideoFrameRate();// 帧率 bitrate = grabber.getVideoBitrate();// 比特率 // 音频参数 // 想要录制音频,这三个参数必须有:audioChannels > 0 && audioBitrate > 0 && sampleRate > 0 audioChannels = grabber.getAudioChannels(); audioBitrate = grabber.getAudioBitrate(); if (audioBitrate < 1) { audioBitrate = 128 * 1000;// 默认音频比特率 } return this; }
Example 7
Source File: VideoThumbnailBuilder.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
private void writeMp4Frame(File videoFile, File frameFile) throws Exception { FFmpegFrameGrabber g = new FFmpegFrameGrabber(videoFile); g.start(); /* * Get a frame in the middle of the video */ int startFrame = g.getLengthInVideoFrames() / 2; g.setVideoFrameNumber(startFrame); try { for (int i = startFrame; i < g.getLengthInFrames() && frameFile.length() == 0; i++) { try { Frame frame = g.grab(); if (frame == null) continue; BufferedImage img = Java2DFrameUtils.toBufferedImage(frame); if (img == null) continue; ImageIO.write(img, "png", frameFile); } catch (Throwable t) { } } } finally { g.stop(); g.close(); } }
Example 8
Source File: VidImageSequence.java From GIFKR with GNU Lesser General Public License v3.0 | 5 votes |
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(); } }
Example 9
Source File: JavaCVRecord.java From easyCV with Apache License 2.0 | 4 votes |
/** * 转发源视频到输出(复制) * * @param src * -源视频 * @param out * -输出流媒体服务地址 * @return * @throws org.bytedeco.javacv.FrameRecorder.Exception */ public Recorder stream(String src, String out) throws IOException { if (src == null || out == null) { throw new Exception("源视频和输出为空"); } this.src = src; this.out = out; // 采集/抓取器 grabber = new FFmpegFrameGrabber(src); grabber.start(); if (width < 0 || height < 0) { width = grabber.getImageWidth(); height = grabber.getImageHeight(); } // 视频参数 int audiocodecid = grabber.getAudioCodec(); int codecid = grabber.getVideoCodec(); double framerate = grabber.getVideoFrameRate();// 帧率 int bitrate = grabber.getVideoBitrate();// 比特率 // 音频参数 // 想要录制音频,这三个参数必须有:audioChannels > 0 && audioBitrate > 0 && sampleRate > 0 int audioChannels = grabber.getAudioChannels(); int audioBitrate = grabber.getAudioBitrate(); int sampleRate = grabber.getSampleRate(); // 录制/推流器 record = new FFmpegFrameRecorderPlus(out, width, height); record.setVideoOption("crf", "18"); record.setGopSize(1); record.setFrameRate(framerate); record.setVideoBitrate(bitrate); record.setAudioChannels(audioChannels); record.setAudioBitrate(audioBitrate); record.setSampleRate(sampleRate); AVFormatContext fc = null; //rtmp和flv if (hasRTMPFLV(out)) { // 封装格式flv,并使用h264和aac编码 record.setFormat("flv"); record.setVideoCodec(AV_CODEC_ID_H264); record.setAudioCodec(AV_CODEC_ID_AAC); if(hasRTMPFLV(src)) { fc = grabber.getFormatContext(); } }else if(hasMP4(out)){//MP4 record.setFormat("mp4"); record.setVideoCodec(AV_CODEC_ID_H264); record.setAudioCodec(AV_CODEC_ID_AAC); } record.start(fc); return this; }
Example 10
Source File: VideoDecoderService.java From Spring with Apache License 2.0 | 4 votes |
public FFmpegFrameGrabber read(File video) throws FrameGrabber.Exception { FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(video); frameGrabber.start(); return frameGrabber; }
Example 11
Source File: VideoPlayer.java From Java-Machine-Learning-for-Computer-Vision with MIT License | 4 votes |
private FFmpegFrameGrabber initFrameGrabber(String videoFileName) throws FrameGrabber.Exception { FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(new File(videoFileName)); grabber.start(); return grabber; }
Example 12
Source File: VideoPlayer.java From Java-Machine-Learning-for-Computer-Vision with MIT License | 4 votes |
private FFmpegFrameGrabber initFrameGrabber(String videoFileName) throws FrameGrabber.Exception { FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(videoFileName); grabber.start(); return grabber; }