简体   繁体   English

如何在android中以mp4格式录制低质量视频?

[英]How to record low quality video in mp4 format in android?

I am recording a low quality video from camera and uploading it to server.我正在从相机录制低质量视频并将其上传到服务器。 The issue is that the video which is recorded comes in 3gp format.问题是录制的视频是 3gp 格式。 Even if i give EXTRA_OUTPUT flag with a mp4 extension path, still it records in 3gp.即使我给 EXTRA_OUTPUT 标志加上 mp4 扩展路径,它仍然记录在 3gp 中。

Actually, on iOS device, this 3gp video is not playing and i don't want to convert it to mp4 using ffmpeg because it has a overhead and it will take time to convert.实际上,在 iOS 设备上,这个 3gp 视频没有播放,我不想使用 ffmpeg 将其转换为 mp4,因为它有开销并且转换需要时间。

This is the code i am using :-这是我正在使用的代码:-

            ContentValues values = new ContentValues();
            String fileName = System.currentTimeMillis() + ".mp4";
            values.put(MediaStore.Video.Media.TITLE, fileName);
            values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
            try {
                Uri videoUriFromCamera = getContentResolver().insert(
                        MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);
                Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUriFromCamera);
                if (videoSize != -1)
                    intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, videoSize);
                if (videoDuration != -1)
                    intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, videoDuration);

                startActivityForResult(intent, ACTION_REQUEST_VIDEO_FROM_CAMERA);
            } catch (Exception e) {
                e.printStackTrace();
                Toast.makeText(VideoPickActivity.this, "SD-Card not available", Toast.LENGTH_LONG).show();
            }

Is there any way or flag that i can record low quality videos in mp4 format or any other format using the default camera intent ?有什么方法或标志可以使用默认的相机意图以 mp4 格式或任何其他格式录制低质量视频?

No.不。

First, there is no documented extra on ACTION_VIDEO_CAPTURE for stating a particular video container format (eg, MP4).首先,在ACTION_VIDEO_CAPTURE上没有记录额外的ACTION_VIDEO_CAPTURE来说明特定的视频容器格式(例如 MP4)。 The best approach for attempting to ask that would be to pass a Uri for a file, where the file extension is .mp4 , but even that is just a hope.尝试询问的最佳方法是为文件传递一个Uri ,其中文件扩展名为.mp4 ,但即便如此也只是希望。

Second, there are thousands of camera apps that advertise support for ACTION_VIDEO_CAPTURE , including hundreds of camera apps that are preinstalled.其次,有数以千计的相机应用程序宣传对ACTION_VIDEO_CAPTURE支持,其中包括数百个预装的相机应用程序。 None have to honor any of your extras.没有人必须尊重您的任何额外内容。 None have to pay attention to file extensions to make a choice of video container format.没有人必须注意文件扩展名才能选择视频容器格式。

If you want that degree of control over the video recording, record the video yourself, such as by using MediaRecorder .如果您想要对视频录制进行这种程度的控制,请自己录制视频,例如使用MediaRecorder

You probably need to get a bit deeper into the mechanics of using the camera: Create a MediaRecorder, and set up a CamcorderProfile, which you can set up with some finesse.您可能需要更深入地了解使用相机的机制:创建一个 MediaRecorder,并设置一个 CamcorderProfile,您可以对其进行一些巧妙的设置。

    mCamera = Camera.open();
    mRec = new MediaRecorder();
    mRec.setCamera(mCamera);
    mRec.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRec.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    CamcorderProfile mProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
    mProfile.fileFormat = MediaRecorder.OutputFormat.MPEG_4;
    mRec.setProfile(mProfile);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM