bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.6k stars 1.59k forks source link

android FFmpegFrameRecorder and otaliastudios #2255

Open openmotion opened 4 months ago

openmotion commented 4 months ago

Hello i use the library otaliastudios for managing camera

i set the recorder recorder = new FFmpegFrameRecorder(ffmpeg_link, imageWidth, imageHeight, 0); recorder.setFormat("flv"); recorder.setFrameRate(frameRate);

try { recorder.start(); } catch (FFmpegFrameRecorder.Exception e) { throw new RuntimeException(e); }

then in frame processor i added

mCameraView.addFrameProcessor(new FrameProcessor() { @Override @WorkerThread public void process(@NonNull Frame frame) {

try { Log.d(TAG, "add frame ok"); recorder.record(frame.getData()); } catch (FFmpegFrameRecorder.Exception e) { Log.d(TAG, "add frame ko"); throw new RuntimeException(e); }

then i stopped the record after 10 seconds but the flv file has a very low size of 212 ( bytes ) and is unreadeable

any suggestion ?

how can i convert the frame ( otaliastudio format ) to javacv.Frame

Required type: org.bytedeco.javacv.Frame Provided: com.otaliastudios.cameraview.frame.Frame

thanks

saudet commented 4 months ago

You'll need to call recorder.close() somewhere

openmotion commented 4 months ago

You'll need to call recorder.close() somewhere

yes i do that

` long time = 1000*20; new android.os.Handler().postDelayed( new Runnable() { public void run() { Log.i("tag","A Kiss after 5 seconds"); mymodel_toast.make_toasty(mContext,"stop record","success"); try { recorder.stop(); recorder.release(); } catch (FFmpegFrameRecorder.Exception e) { throw new RuntimeException(e); }

                }
            }, time);

`

the size is 0 before the stop, and 212 after i suspect the original frame is not correctly converted to the ffmpegframerecorder format

saudet commented 4 months ago

Please try again with the snapshots: http://bytedeco.org/builds/

openmotion commented 4 months ago

Please try again with the snapshots: http://bytedeco.org/builds/

thanks but if i change my build.gradle to implementation("org.bytedeco:javacv-platform:1.5.11-SNAPSHOT") the library is no more recognized in the import section

Cannot resolve symbol 'bytedeco'

this is code i use to save image in jpeg

YuvImage yuvImage = new YuvImage(bitmapbytes, ImageFormat.NV21, width, height, null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); compression = 50; Rect imageSizeRectangle = new Rect(0, 0, width, height); yuvImage.compressToJpeg(imageSizeRectangle, compression, baos); byte[] imageData = baos.toByteArray();

but imageData doesn't works with javacv