java .lang.NoClassDefFoundError: org.bytedeco. javacpp .avutil эта ошибка с javacv - PullRequest
0 голосов
/ 12 апреля 2020

Я использую javacv для захвата видео в android.

, когда я запускаю свое приложение, возникает ошибка.

мой код:

package com.example.usb.grabbers;

import android.graphics.ImageFormat;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.media.AudioRecord;
import android.os.Build;
import android.util.Log;


import androidx.annotation.RequiresApi;

import com.example.usb.StreamerActivity;


import org.bytedeco.javacpp.avcodec;
import org.bytedeco.javacv.FFmpegFrameRecorder;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.FrameRecorder;

import java.nio.ByteBuffer;
import java.util.Objects;


public class VideoFrameGrabber {
// Member variables
private final String LOG_TAG = VideoFrameGrabber.class.getName();
private boolean recording;
private Camera camera;
private FFmpegFrameRecorder recorder;
private int frameRate = 30;
private int imagesIndex;
private Frame yuvImage = null;
private long[] timestamps;
private long startTime = 0;
private long videoTimestamp;

public VideoFrameGrabber() {
    yuvImage = new Frame(StreamerActivity.CAMERA_WIDTH, StreamerActivity.CAMERA_HEIGHT, 
Frame.DEPTH_UBYTE, 2);
    yuvImage.imageChannels = 2;
    recording = false;
}

public FFmpegFrameRecorder getRecorder() {
    return recorder;
}



@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public Size start(Camera camera, String url) {
    this.camera = camera;
    this.startTime = System.currentTimeMillis();
    recording = true;

    Camera.Parameters params = camera.getParameters();
    params.setPreviewSize(StreamerActivity.CAMERA_WIDTH, StreamerActivity.CAMERA_HEIGHT);
    camera.setParameters(params);
    Size previewSize = params.getPreviewSize();
    int bufferSize = previewSize.width * previewSize.height * 
 ImageFormat.getBitsPerPixel(params.getPreviewFormat());
    camera.addCallbackBuffer(new byte[bufferSize]);
    camera.setPreviewCallback(new Camera.PreviewCallback() {
        @RequiresApi(api = Build.VERSION_CODES.KITKAT)
        @Override
        public void onPreviewFrame(byte[] data, Camera camera) {
            if (yuvImage != null && recording) {
                videoTimestamp = 1000 * (System.currentTimeMillis() - startTime);
                ((ByteBuffer)yuvImage.image[0].position(0)).put(data);

                try {
                    recorder.setTimestamp(videoTimestamp);
                    recorder.record(yuvImage);

                } catch (FFmpegFrameRecorder.Exception e) {
                    Log.v(LOG_TAG, Objects.requireNonNull(e.getMessage()));
                    e.printStackTrace();
                }
            }
        }
    });

    recorder = new FFmpegFrameRecorder(url, previewSize.width, previewSize.height, 1);
    recorder.setFormat("flv");
    recorder.setSampleRate(44100);

    recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
    recorder.setVideoCodecName("libx264");
    Log.v(LOG_TAG, String.format("Codec after is %s", recorder.getVideoCodecName()));
    recorder.setVideoOption("preset", "ultrafast");
    recorder.setFrameRate(frameRate);
    recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);
    Log.v(LOG_TAG, String.format("Audi codec is %s", recorder.getAudioCodecName()));
    recorder.setAudioCodecName("libfdk_aac");
    Log.v(LOG_TAG, String.format("Audi codec after is %s", recorder.getAudioCodecName()));
    recorder.setAudioBitrate(128000);
    recorder.setVideoBitrate(1500000);
    recorder.setVideoQuality(0.5);
    recorder.setGopSize(12);
    recorder.setVideoOption("partitions", "i8x8,i4x4,p8x8,b8x8");
    recorder.setVideoOption("direct-pred", "1");
    recorder.setVideoOption("weightb", "0");

    try {
        recorder.start();
        Log.v(LOG_TAG, String.format("Codec is %d %s", recorder.getVideoCodec(), 
 recorder.getVideoCodecName()));
        Log.v(LOG_TAG, String.format("Audio is %d %s", recorder.getAudioCodec(), 
recorder.getAudioCodecName()));
    } catch (FrameRecorder.Exception e) {
        Log.v(VideoFrameGrabber.class.getName(), Objects.requireNonNull(e.getMessage()));
    }

    return previewSize;
}

public void stop() {
    camera.setPreviewCallbackWithBuffer(null);
    camera = null;

    try {
        recorder.stop();
        recorder.release();
    } catch (FFmpegFrameRecorder.Exception e) {
        e.printStackTrace();
    }
    recorder = null;
   }
   }

Мой папка libs

enter image description here

Ошибка при запуске:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.usb, PID: 22647
java.lang.NoClassDefFoundError: org.bytedeco.javacpp.avutil
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:454)
    at org.bytedeco.javacpp.Loader.load(Loader.java:585)
    at org.bytedeco.javacpp.Loader.load(Loader.java:530)
    at org.bytedeco.javacpp.avcodec$AVPacket.<clinit>(avcodec.java:1694)
    at org.bytedeco.javacv.FFmpegFrameRecorder.<init>(FFmpegFrameRecorder.java:152)
    at com.example.usb.grabbers.VideoFrameGrabber.start(VideoFrameGrabber.java:106)
    at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2067)
    at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2099)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:7814)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)
 Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.usb-V_C2VyCe0226B4jxtx52Iw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.usb-V_C2VyCe0226B4jxtx52Iw==/lib/arm64, /data/app/com.example.usb-V_C2VyCe0226B4jxtx52Iw==/base.apk!/lib/arm64-v8a, /system/lib64]]] couldn't find "libjniavutil.so"
    at java.lang.Runtime.loadLibrary0(Runtime.java:1067)
    at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
    at java.lang.System.loadLibrary(System.java:1667)
    at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:804)
    at org.bytedeco.javacpp.Loader.load(Loader.java:613)
    at org.bytedeco.javacpp.Loader.load(Loader.java:530)
    at org.bytedeco.javacpp.avutil.<clinit>(avutil.java:10)
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:454)
    at org.bytedeco.javacpp.Loader.load(Loader.java:585)
    at org.bytedeco.javacpp.Loader.load(Loader.java:546)
    at org.bytedeco.javacv.FFmpegFrameRecorder.tryLoad(FFmpegFrameRecorder.java:94)
    at org.bytedeco.javacv.FFmpegFrameRecorder.<clinit>(FFmpegFrameRecorder.java:115)
    at com.example.usb.grabbers.VideoFrameGrabber.start(VideoFrameGrabber.java:106) 
    at com.example.usb.VideoStreamingConnection.open(VideoStreamingConnection.java:46) 
    at com.example.usb.StreamerService.startStreaming(StreamerService.java:78) 
    at com.example.usb.StreamerActivity.startStreaming(StreamerActivity.java:211) 
    at com.example.usb.StreamerActivity.access$200(StreamerActivity.java:51) 
    at com.example.usb.StreamerActivity$1.onServiceConnected(StreamerActivity.java:73) 
    at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2067) 
    at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2099) 
    at android.os.Handler.handleCallback(Handler.java:883) 
    at android.os.Handler.dispatchMessage(Handler.java:100) 
    at android.os.Looper.loop(Looper.java:237) 
    at android.app.ActivityThread.main(ActivityThread.java:7814) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068) 
 Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.usb-V_C2VyCe0226B4jxtx52Iw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.usb-V_C2VyCe0226B4jxtx52Iw==/lib/arm64, /data/app/com.example.usb-V_C2VyCe0226B4jxtx52Iw==/base.apk!/lib/arm64-v8a, /system/lib64]]] couldn't find "libavutil.so"
    at java.lang.Runtime.loadLibrary0(Runtime.java:1067)
    at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
    at java.lang.System.loadLibrary(System.java:1667)
    at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:804)
    at org.bytedeco.javacpp.Loader.load(Loader.java:604)
    at org.bytedeco.javacpp.Loader.load(Loader.java:530) 
    at org.bytedeco.javacpp.avutil.<clinit>(avutil.java:10) 
    at java.lang.Class.classForName(Native Method) 
    at java.lang.Class.forName(Class.java:454) 
    at org.bytedeco.javacpp.Loader.load(Loader.java:585) 
    at org.bytedeco.javacpp.Loader.load(Loader.java:546) 
    at org.bytedeco.javacv.FFmpegFrameRecorder.tryLoad(FFmpegFrameRecorder.java:94) 
    at org.bytedeco.javacv.FFmpegFrameRecorder.<clinit>(FFmpegFrameRecorder.java:115) 
    at com.example.usb.grabbers.VideoFrameGrabber.start(VideoFrameGrabber.java:106) 
    at com.example.usb.VideoStreamingConnection.open(VideoStreamingConnection.java:46) 
    at com.example.usb.StreamerService.startStreaming(StreamerService.java:78) 
    at com.example.usb.StreamerActivity.startStreaming(StreamerActivity.java:211) 
    at com.example.usb.StreamerActivity.access$200(StreamerActivity.java:51) 
    at com.example.usb.StreamerActivity$1.onServiceConnected(StreamerActivity.java:73) 
    at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2067) 
    at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2099) 
    at android.os.Handler.handleCallback(Handler.java:883) 
    at android.os.Handler.dispatchMessage(Handler.java:100) 
    at android.os.Looper.loop(Looper.java:237) 
    at android.app.ActivityThread.main(ActivityThread.java:7814) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068) 
    I/Process: Sending signal. PID: 22647 SIG: 9

Как мне решить эту проблему?

В моя папка libs добавили все библиотеки libsware, но эта ошибка возникает.

почему возникает эта ошибка?

Я видел много ответов, и я пытался. но это не сделано.

мой другой вопрос.

Дайте решение для этого.

...