Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

部分设备无法正常开始录制 #9

Open
RavenGluttonous opened this issue Dec 11, 2023 · 8 comments
Open

部分设备无法正常开始录制 #9

RavenGluttonous opened this issue Dec 11, 2023 · 8 comments

Comments

@RavenGluttonous
Copy link

   if (videoRecorderNative != null) {
                videoRecorderNative.stopRecord();
                videoRecorderNative = null;
            }
            videoRecordParams = new VideoRecordParams();
            videoRecordParams.setOutputPath(videoPath);
            videoRecordParams.setHasAudio(false);
            videoRecordParams.setVideoFrameRate(30);
            videoRecordParams.setBitRate(250000000);
            videoRecordParams.setRecordSpeed(1.0f); // 视频录制速度

            videoRecorderNative = new VideoRecorderNative();
    public void start(int width, int height) throws Exception {
        if (initialized)
            return;

        try {
            videoFormatWidth = width;
            videoFormatHeight = height;
            if (videoFormatWidth <= 0 || videoFormatHeight <= 0) {
                throw new Exception("视频宽高非法");
            }
            videoRecordParams.setInputWidth(videoFormatWidth);
            videoRecordParams.setInputHeight(videoFormatHeight);
            videoRecordParams.setTargetWidth(videoFormatWidth);
            videoRecordParams.setTargetHeight(videoFormatHeight);
            int ret = videoRecorderNative.startRecord(videoRecordParams);
            if (ret < 0) {
                MyLogUtil.e("startRecord fail000");
                videoRecorderNative.stopRecord();
                videoRecorderNative = null;
            }
            initialized = true;
        } catch (Exception e) {
            MyLogUtil.e("startRecord fail:"+e.getMessage());
        }
    }

bz_ cn.xymind.D output_path=/sdcard/xyVideos/video_1702290053634raven.mp4
bz_ cn.xymind.D inputWidth=300
bz_ cn.xymind.D inputHeight=300
bz_ cn.xymind.D targetWidth=288
bz_ cn.xymind.D targetHeight=288
bz_ cn.xymind.D videoFrameRate=30
bz_ cn.xymind.D nbSamples=1024
bz_ cn.xymind.D sampleRate=44100
bz_ cn.xymind.D videoRotate=0
bz_ cn.xymind.D pixelFormat=0
bz_ cn.xymind.D hasAudio=0
bz_ cn.xymind.D synEncode=1
bz_ cn.xymind.D avPacketFromMediaCodec=0
bz_ cn.xymind.D needFlipVertical=0
bz_ cn.xymind.D allFrameIsKey=0
bz_ cn.xymind.D bitRate=250000000
bz_ cn.xymind.D startRecord output_path=/sdcard/xyVideos/video_1702290053634raven.mp4--srcWidth=300--srcHeight=300--targetWidth=288--targetHeight=288
rate=30--nb_samples=1024--sampleRate=44100--videoRotate=0--pixelFormat=0
allFrameIsKey=0,synEncode=1,avPacketFromMediaCodec=0
bz_ cn.xymind.D VideoRecorder 对齐后targetWidth=288--targetHeight=288
bz_ cn.xymind.D VideoRecorder addStream mediaType=0
bz_ cn.xymind.D VideoRecorder video bit_rate=29.802322
bz_ cn.xymind.D VideoRecorder openVideo

bz_ cn.xymind.D VideoRecorder alloc_picture
bz_ cn.xymind.D VideoRecorder alloc_picture

bz_ cn.xymind.D VideoRecorder Could not open '/sdcard/xyVideos/video_1702290053634raven.mp4': Operation not permitted
bz_ cn.xymind.E VideoRecorder yuvBufferTotalCount<=0
bz_ cn.xymind.D VideoRecorder closeStream index=0

bz_ cn.xymind.D VideoRecorder endRecordAndReleaseResource --success
bz_ cn.xymind.E startRecord fail
bz_ cn.xymind.D setStopRecordFlag encodeThreadIsRunning=
bz_ cn.xymind.D VideoRecorder start stopRecord
bz_ cn.xymind.V VideoRecorder ------flush_video start-------

DEBUG crash_dump64 A #00 pc 000000000003c248 /data/app/~~8uXsUgyCHMGMmMbTCHrT_Q==/cn.xymind-ldCGmFV6hShxe3lrOEq5Ew==/base.apk!libbzmedia.so (VideoRecorder::flushBuffer()+76) (BuildId: e2f00b046f613c2563a9c3154c43ca5a913419dd)
DEBUG crash_dump64 A #1 pc 000000000003c690 /data/app/~~8uXsUgyCHMGMmMbTCHrT_Q==/cn.xymind-ldCGmFV6hShxe3lrOEq5Ew==/base.apk!libbzmedia.so (VideoRecorder::stopRecord()+128) (BuildId: e2f00b046f613c2563a9c3154c43ca5a913419dd)
DEBUG crash_dump64 A #2 pc 000000000003269c /data/app/~~8uXsUgyCHMGMmMbTCHrT_Q==/cn.xymind-ldCGmFV6hShxe3lrOEq5Ew==/base.apk!libbzmedia.so (Java_com_luoye_bzmedia_BZMedia_startRecord+1664) (BuildId: e2f00b046f613c2563a9c3154c43ca5a913419dd)
DEBUG crash_dump64 A #10 pc 0000000000353428 [anon:dalvik-classes19.dex extracted in memory from /data/app/~~8uXsUgyCHMGMmMbTCHrT_Q==/cn.xymind-ldCGmFV6hShxe3lrOEq5Ew==/base.apk!classes19.dex]
DEBUG crash_dump64 A #16 pc 00000000000037ba [anon:dalvik-classes7.dex extracted in memory from /data/app/~~8uXsUgyCHMGMmMbTCHrT_Q==/cn.xymind-ldCGmFV6hShxe3lrOEq5Ew==/base.apk!classes7.dex]
DEBUG crash_dump64 A #22 pc 000000000000342a [anon:dalvik-classes7.dex extracted in memory from /data/app/~~8uXsUgyCHMGMmMbTCHrT_Q==/cn.xymind-ldCGmFV6hShxe3lrOEq5Ew==/base.apk!classes7.dex]
DEBUG crash_dump64 A #28 pc 000000000000fd7c [anon:dalvik-classes17.dex extracted in memory from /data/app/~~8uXsUgyCHMGMmMbTCHrT_Q==/cn.xymind-ldCGmFV6hShxe3lrOEq5Ew==/base.apk!classes17.dex]
DEBUG crash_dump64 A #34 pc 00000000000069c0 [anon:dalvik-classes5.dex extracted in memory from /data/app/~~8uXsUgyCHMGMmMbTCHrT_Q==/cn.xymind-ldCGmFV6hShxe3lrOEq5Ew==/base.apk!classes5.dex]
DEBUG crash_dump64 A #40 pc 0000000000001d2a [anon:dalvik-classes10.dex extracted in memory from /data/app/~~8uXsUgyCHMGMmMbTCHrT_Q==/cn.xymind-ldCGmFV6hShxe3lrOEq5Ew==/base.apk!classes10.dex]

@bookzhan
Copy link
Owner

bz_ cn.xymind.D VideoRecorder Could not open '/sdcard/xyVideos/video_1702290053634raven.mp4': Operation not permitted 你先解决文件读写权限问题,先写到私有目录试试

@RavenGluttonous
Copy link
Author

startRecord videoPath:/storage/emulated/0/Movies/xyVideos/_VID_1710211924428.mp4,
videoFormatWidth:480,
videoFormatHeight:640
startRecord videoFormatWidth=480 videoFormatHeight=640
startRecord onVideoError what=528 extra=528
文件权限没有问题,在华为手机可以正常录制(android 10),红米k30报错(Android 12)

@bookzhan
Copy link
Owner

bookzhan commented Mar 12, 2024 via email

@RavenGluttonous
Copy link
Author

------------------------------日志 start------------------------------
start
startRecord videoPath=/storage/emulated/0/Movies/xyVideos/_VID_1710214664108.mp4
startRecord videoPath:/storage/emulated/0/Movies/xyVideos/_VID_1710214664108.mp4,
videoFormatWidth:480,
videoFormatHeight:640
startRecord videoFormatWidth=480 videoFormatHeight=640
startRecord onVideoError what=528 extra=528
stopRecord success
startRecord fail
视频保存路径:/storage/emulated/0/Movies/xyVideos/_VID_1710214664108.mp4
addVideoData fail
------------------------------日志 end------------------------------

    public void startRecord(String videoPath, int videoFormatWidth, int videoFormatHeight) {
        synchronized (videoRecorderLock) {
            MyLog.e(TAG, "startRecord videoPath=" + videoPath);
            if (videoRecorderNative != null) {
                videoRecorderNative.stopRecord();
                videoRecorderNative = null;
            }
            MyLog.e(TAG, "startRecord videoPath:" + videoPath + ",\nvideoFormatWidth:" + videoFormatWidth + ",\nvideoFormatHeight:" + videoFormatHeight);
            if (videoFormatWidth <= 0 || videoFormatHeight <= 0) {
                MyLog.e(TAG, "startRecord videoFormatWidth<=0||videoFormatHeight<=0");
                return;
            }

            VideoRecordParams videoRecordParams = new VideoRecordParams();
            videoRecordParams.setInputWidth(videoFormatWidth);
            videoRecordParams.setInputHeight(videoFormatHeight);
            if(Math.max(videoFormatWidth,videoFormatHeight)>640 || Math.min(videoFormatWidth,videoFormatHeight) >480){
                videoFormatWidth = 480;
                videoFormatHeight = 640;
            }
            MyLog.e(TAG,"startRecord videoFormatWidth=" +videoFormatWidth +" videoFormatHeight="+videoFormatHeight);
            videoRecordParams.setTargetWidth(videoFormatWidth);
            videoRecordParams.setTargetHeight(videoFormatHeight );
            videoRecordParams.setOutputPath(videoPath);
            videoRecordParams.setHasAudio(false);
            videoRecordParams.setVideoFrameRate(30);
            videoRecordParams.setBitRate(250000000);

            videoRecorderNative = new VideoRecorderNative();
            videoRecorderNative.setOnVideoRecorderStateListener(new VideoRecorderBase.OnVideoRecorderStateListener() {
                @Override
                public void onVideoRecorderStarted(boolean success) {
                }

                @Override
                public void onVideoRecording(long recordTime) {

                }

                @Override
                public void onVideoRecorderStopped(String videoPath, boolean success) {
                }
            });

            videoRecorderNative.setOnRecorderErrorListener(new OnRecorderErrorListener() {
                @Override
                public void onVideoError(int what, int extra) {
                    MyLog.e(TAG,"startRecord onVideoError what=" + what + " extra=" + extra);
                    videoRecorderNative.stopRecord();
                }

                @Override
                public void onAudioError(int what, String message) {
                    MyLog.e(TAG,"startRecord onAudioError what=" + what + " extra=" + message);
                    videoRecorderNative.stopRecord();
                }
            });
            int ret = videoRecorderNative.startRecord(videoRecordParams);
            if (ret < 0) {
                MyLog.e(TAG, "startRecord startRecord fail");
                videoRecorderNative.stopRecord();
                videoRecorderNative = null;
            }
        }
    }

@RavenGluttonous
Copy link
Author

信息补充:是否因为路径创建为MediaStore,Environment.DIRECTORY_MOVIES方式所创建,导致库没有写入权限。

@bookzhan
Copy link
Owner

bookzhan commented Mar 12, 2024

底层是FFmpeg是不支持MediaStore的,只是支持文件路径,一般的操作方式是录制路径用私有目录的路径,录制完成后插入到相册,并且需要保证父级目录存在

@RavenGluttonous
Copy link
Author

很抱歉如此麻烦您,我通过

1. File customDir = new File(getExternalFilesDir(null), "xyVideos");
2. File customDir = new File("/sdcard/xyVideos");

等方式创建文件夹,并写入视频文件,依然报相同错误,上述路径如下。

/storage/emulated/0/Android/data/包名/files/xyVideos/VID_1710239597508.mp4
/sdcard/xyVideos/VID_1710239597508.mp4

@bookzhan
Copy link
Owner

我用了红米k30(Android 10)试了没有发现问题,你先用我的工程试试,看看行不行,不行的话你就debug看看到底是哪儿的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants