Log.v(LOG_TAG,e.getMessage()); e.printStackTrace();
public static FrameRecorder create(Class<? extends FrameRecorder> c, Class p, Object o, int w, int h) throws Exception { Throwable cause = null; try { return (FrameRecorder)c.getConstructor(p, int.class, int.class).newInstance(o, w, h); } catch (InstantiationException ex) { cause = ex; } catch (IllegalAccessException ex) { cause = ex; } catch (IllegalArgumentException ex) { cause = ex; } catch (NoSuchMethodException ex) { cause = ex; } catch (InvocationTargetException ex) { cause = ex.getCause(); } throw new Exception("Could not create new " + c.getSimpleName() + "(" + o + ", " + w + ", " + h + ")", cause); }
throw new Exception("av_guess_format() error: Could not guess output format for \"" + filename + "\" and " + format + " format."); throw new Exception("avformat_alloc_context2() error:\tCould not allocate format context"); (video_codec = avcodec_find_encoder(oformat.video_codec())) == null) { release(); throw new Exception("avcodec_find_encoder() error: Video codec not found."); throw new Exception("avformat_new_stream() error: Could not allocate video stream."); throw new Exception("avcodec_alloc_context3() error: Could not allocate video encoding context."); if ((ret = avcodec_copy_context(video_st.codec(), inpVideoStream.codec())) < 0) { release(); throw new Exception("avcodec_copy_context() error:\tFailed to copy context from input to output stream codec context"); (audio_codec = avcodec_find_encoder(oformat.audio_codec())) == null) { release(); throw new Exception("avcodec_find_encoder() error: Audio codec not found."); throw new Exception("avformat_new_stream() error: Could not allocate audio stream."); throw new Exception("avcodec_alloc_context3() error: Could not allocate audio encoding context."); throw new Exception("avcodec_copy_context() error:\tFailed to copy context from input audio to output audio stream codec context\n"); release(); av_dict_free(options); throw new Exception("avcodec_open2() error " + ret + ": Could not open video codec.");
public boolean recordImage(int width, int height, int depth, int channels, int stride, int pixelFormat, Buffer ... image) throws Exception { if (video_st == null) { throw new Exception("No video output stream (Is imageWidth > 0 && imageHeight > 0 and has start() been called?)"); throw new Exception("Could not guess pixel format of image: depth=" + depth + ", channels=" + channels); null, null, (DoublePointer)null); if (img_convert_ctx == null) { throw new Exception("sws_getCachedContext() error: Cannot initialize the conversion context."); picture.quality(video_c.global_quality()); if ((ret = avcodec_encode_video2(video_c, video_pkt, image == null || image.length == 0 ? null : picture, got_video_packet)) < 0) { throw new Exception("avcodec_encode_video2() error " + ret + ": Could not encode video packet.");
public boolean recordSamples(int sampleRate, int audioChannels, Buffer ... samples) throws Exception { if (audio_st == null) { throw new Exception("No audio output stream (Is audioChannels > 0 and has start() been called?)"); throw new Exception("Audio samples Buffer has unsupported type: " + samples); av_get_default_channel_layout(audioChannels), inputFormat, sampleRate, 0, null); if (samples_convert_ctx == null) { throw new Exception("swr_alloc_set_opts() error: Cannot allocate the conversion context."); } else if ((ret = swr_init(samples_convert_ctx)) < 0) { throw new Exception("swr_init() error " + ret + ": Cannot initialize the conversion context."); throw new Exception("swr_convert() error " + ret + ": Cannot convert audio samples."); } else if (ret == 0) { break;
outputStream.close(); } catch (IOException ex) { throw new Exception("Error on OutputStream.close(): ", ex); } finally { outputStream = null;
Log.v(LOG_TAG, e.getMessage()); e.printStackTrace(); recorder.release(); } catch(FFmpegFrameRecorder.Exception e) { e.printStackTrace();
Log.e(LOG_TAG, e.getMessage()); e.printStackTrace();
} catch (Exception e) e.printStackTrace();
boolean record(AVFrame frame) throws Exception { int ret; av_init_packet(audio_pkt); audio_pkt.data(audio_outbuf); audio_pkt.size(audio_outbuf_size); if ((ret = avcodec_encode_audio2(audio_c, audio_pkt, frame, got_audio_packet)) < 0) { throw new Exception("avcodec_encode_audio2() error " + ret + ": Could not encode audio packet."); } if (frame != null) { frame.pts(frame.pts() + frame.nb_samples()); // magic required by libvorbis and webm } if (got_audio_packet[0] != 0) { if (audio_pkt.pts() != AV_NOPTS_VALUE) { audio_pkt.pts(av_rescale_q(audio_pkt.pts(), audio_c.time_base(), audio_st.time_base())); } if (audio_pkt.dts() != AV_NOPTS_VALUE) { audio_pkt.dts(av_rescale_q(audio_pkt.dts(), audio_c.time_base(), audio_st.time_base())); } audio_pkt.flags(audio_pkt.flags() | AV_PKT_FLAG_KEY); audio_pkt.stream_index(audio_st.index()); } else { return false; } /* write the compressed frame in the media file */ writePacket(AVMEDIA_TYPE_AUDIO, audio_pkt); return true; }
public static void tryLoad() throws Exception { if (loadingException != null) { throw loadingException; } else { try { Loader.load(org.bytedeco.javacpp.avutil.class); Loader.load(org.bytedeco.javacpp.swresample.class); Loader.load(org.bytedeco.javacpp.avcodec.class); Loader.load(org.bytedeco.javacpp.avformat.class); Loader.load(org.bytedeco.javacpp.swscale.class); /* initialize libavcodec, and register all codecs and formats */ av_jni_set_java_vm(Loader.getJavaVM(), null); avcodec_register_all(); av_register_all(); avformat_network_init(); Loader.load(org.bytedeco.javacpp.avdevice.class); avdevice_register_all(); } catch (Throwable t) { if (t instanceof Exception) { throw loadingException = (Exception)t; } else { throw loadingException = new Exception("Failed to load " + FFmpegFrameRecorder.class, t); } } } }
private void writePacket(int mediaType, AVPacket avPacket) throws Exception { AVStream avStream = (mediaType == AVMEDIA_TYPE_VIDEO) ? audio_st : (mediaType == AVMEDIA_TYPE_AUDIO) ? video_st : null; String mediaTypeStr = (mediaType == AVMEDIA_TYPE_VIDEO) ? "video" : (mediaType == AVMEDIA_TYPE_AUDIO) ? "audio" : "unsupported media stream type"; synchronized (oc) { int ret; if (interleaved && avStream != null) { if ((ret = av_interleaved_write_frame(oc, avPacket)) < 0) { throw new Exception("av_interleaved_write_frame() error " + ret + " while writing interleaved " + mediaTypeStr + " packet."); } } else { if ((ret = av_write_frame(oc, avPacket)) < 0) { throw new Exception("av_write_frame() error " + ret + " while writing " + mediaTypeStr + " packet."); } } } av_packet_unref(avPacket); }
public void stopRecord() { // This should stop the audio thread from running runAudioThread = false; if (recorder != null && recording) { recording = false; Log.v(LOG_TAG,"Finishing recording, calling stop and release on recorder"); try { recorder.stop(); recorder.release(); } catch (FFmpegFrameRecorder.Exception e) { e.printStackTrace(); } recorder = null; } }
public static Class<? extends FrameRecorder> get(String className) throws Exception { className = FrameRecorder.class.getPackage().getName() + "." + className; try { return Class.forName(className).asSubclass(FrameRecorder.class); } catch (ClassNotFoundException e) { String className2 = className + "FrameRecorder"; try { return Class.forName(className2).asSubclass(FrameRecorder.class); } catch (ClassNotFoundException ex) { throw new Exception("Could not get FrameRecorder class for " + className + " or " + className2, e); } } }
public void startRecording() { initRecorder(); try { recorder.start(); startTime = System.currentTimeMillis(); recording = true; audioThread.start(); } catch(FFmpegFrameRecorder.Exception e) { e.printStackTrace(); } }
public void startRecord() { initRecorder(); try { recorder.start(); startTime = System.currentTimeMillis(); recording = true; audioThread.start(); } catch (FFmpegFrameRecorder.Exception e) { e.printStackTrace(); } }
public static void tryLoad() throws Exception { if (loadingException != null) { throw loadingException; } else { try { Loader.load(org.bytedeco.javacpp.opencv_highgui.class); } catch (Throwable t) { throw loadingException = new Exception("Failed to load " + OpenCVFrameRecorder.class, t); } } }
public void record(Frame frame) throws Exception { Mat mat = converter.convert(frame); if (writer != null) { writer.write(mat); } else { throw new Exception("Cannot record: There is no writer (Has start() been called?)"); } frame.keyFrame = true; } }