Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kotlin 断开USB连接时后台处理速度减慢_Kotlin_Ffmpeg_Background_Usb_Opencv4android - Fatal编程技术网

Kotlin 断开USB连接时后台处理速度减慢

Kotlin 断开USB连接时后台处理速度减慢,kotlin,ffmpeg,background,usb,opencv4android,Kotlin,Ffmpeg,Background,Usb,Opencv4android,我在kotlin中使用openCV和ffmpeg创建视频编辑应用程序。 通过USB调试拍摄电影后,可以编辑大约5分钟。 但是,一旦断开USB连接,出于某种原因,编辑视频将需要30分钟 我遇到了麻烦,因为我不能不调试就纠正它。 从编辑到将其保存在后台,这有问题吗 class OpenCV(val inputPath: String, val context: Context, val setuptime: Int){ ..... init{

我在kotlin中使用openCV和ffmpeg创建视频编辑应用程序。 通过USB调试拍摄电影后,可以编辑大约5分钟。 但是,一旦断开USB连接,出于某种原因,编辑视频将需要30分钟

我遇到了麻烦,因为我不能不调试就纠正它。 从编辑到将其保存在后台,这有问题吗

class OpenCV(val inputPath: String, val context: Context, val setuptime: Int){

         .....

        init{
            videoCapture = VideoCapture()
            videoCapture.open(inputPath)

            videoCapture.grab()
            width = videoCapture.get(Videoio.CAP_PROP_FRAME_WIDTH)
            height = videoCapture.get(Videoio.CAP_PROP_FRAME_HEIGHT)

            val file = File(context.getExternalFilesDir(Environment.DIRECTORY_MOVIES), "output.avi")

            writer = VideoWriter()
            writer.open(
                file.path,
                VideoWriter.fourcc('M', 'J', 'P', 'G'),
                30.0,
                Size(width,height)
            )


            if(writer.isOpened){
                posefinish=true
                val inpMat = Mat(width.toInt(), height.toInt(),CvType.CV_8UC4)
                while (true){
                    if (!posefinish){continue}//Wait in an infinite loop until one frame is processed

                    if(videoCapture.read(inpMat)){
                        posefinish=false
                        if(inpMat.dims() == 0){ posefinish = true;  continue }


                        val bmp = Bitmap.createBitmap(
                            width.toInt(),
                            height.toInt(),
                            Bitmap.Config.ARGB_8888
                        )

                        Utils.matToBitmap(inpMat, bmp, false)

                        DrawPose(inpMat, bmp)// the function to edit video frame by frame

                    }else{
                        if(MainActivity.debag){Log.d(MainActivity.TAG, "videoCapture終了!")}
                        writer.release()
                        videoCapture.release()


                        with_ffmpeg(file, file2, file3, file4)//     avi -> mp4 -> save video  with ffmpeg

                        break
                    }
                }

            }
        }

    }
我用coroutine线程调用上面的代码

val job =CoroutineScope(Dispatchers.Default).launch {
                            OpenCV(file.toString(),this, taskSec)
                        }

标题错了。正确地说,“当USB断开连接时,后台处理速度会减慢”,您可以根据您的问题进行更正和任何其他所需的改进。