package com.casic.endoscope.extensions import android.util.Log import com.casic.endoscope.utils.FFmpegCommandHub import com.casic.endoscope.utils.ProjectConstant import io.microshow.rxffmpeg.RxFFmpegInvoke import io.microshow.rxffmpeg.RxFFmpegSubscriber import java.util.regex.Pattern /** * String扩展方法 */ fun String.getChannel(): String { val regEx = "[^0-9]" val p = Pattern.compile(regEx) val m = p.matcher(this) return m.replaceAll("").trim { it <= ' ' } } fun String.transcodeVideo(kTag: String) { /** * //storage/emulated/0/Android/data/com.casic.endoscope/files/Movies/2024-02-21/20240221161555.mp4 * */ val lastIndex = this.lastIndexOf("/") val fileName = this.drop(lastIndex + 1) //文件名前面+t val newFileName = fileName.reversed().plus("t").reversed() val outputPath = this.replace(fileName, newFileName) RxFFmpegInvoke.getInstance() .runCommandRxJava(FFmpegCommandHub.createVideoTranscodeCommand(this, outputPath)) .subscribe(object : RxFFmpegSubscriber() { override fun onError(message: String?) { } override fun onFinish() { Log.d(kTag, "onFinish => $outputPath 转码完成") ProjectConstant.decodedViewCount += 1 ProjectConstant.isUnderDecodingVideo = false } override fun onProgress(progress: Int, progressTime: Long) { Log.d(kTag, "onProgress => $progress") } override fun onCancel() { } }) }