public void stop() throws Exception { // Free the RGB image if (buffer != null) { av_free(buffer); buffer = null; } if (pFrameRGB != null) { av_free(pFrameRGB); pFrameRGB = null; } // Free the YUV frame if (pFrame != null) { av_free(pFrame); pFrame = null; } // Close the codec if (pCodecCtx != null) { avcodec_close(pCodecCtx); pCodecCtx = null; } // Close the video file if (pFormatCtx != null && !pFormatCtx.isNull()) { av_close_input_file(pFormatCtx); pFormatCtx = null; } if (return_image != null) { return_image.release(); return_image = null; } }