MediaRecorder setVideoSize在不同的设备中显示不同的行为

编程入门 行业动态 更新时间:2024-10-21 03:47:55
本文介绍了MediaRecorder setVideoSize在不同的设备中显示不同的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用媒体记录器在android应用中录制视频.

I am using media recorder to record video in an android app.

mMediaRecorder.setCamera(mServiceCamera); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); //mMediaRecorder.setVideoSize(mPreviewSize.width, mPreviewSize.height); mMediaRecorder.setVideoFrameRate(30); mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT); mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); String file_name = Environment.getExternalStorageDirectory().getPath() +"/myVideo.mp4"; mMediaRecorder.setOutputFile(file_name); mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); mMediaRecorder.prepare(); mMediaRecorder.start();

问题出在那

mMediaRecorder.setVideoSize(mPreviewSize.width, mPreviewSize.height);

在HTC和Xperia中,setVideoSize可以正常工作(仅当我不对此行发表评论时才有效).但是在Nexus和Note中,setVideoSize不起作用(仅当我注释此行时才起作用).

In HTC and Xperia, setVideoSize works fine (Will work only if I don't comment this line). But in Nexus and Note, setVideoSize won't work( Will work only if I comment this line).

我应该怎么做才能使该应用程序在所有这些设备中正确运行?

What should I do in order for the app to run in all these devices correctly??

推荐答案

您需要了解预览和实际捕获的视频是两个不同的东西,同样,预览大小和视频大小是两个不同的参数.在取景器中看到的实际上是预览,但实际上并不是录制的内容.

You need to understand that the preview and the actual captured video are two different things, likewise Preview sizes and Video sizes are two different parameters. What you see in the viewfinder is essentially the preview, but it is not what actually gets recorded.

  • 启动相机时,您可以为相机设置预览尺寸.但是您必须查询支持的预览尺寸,并在其中设置一个.

  • When starting a camera, you set the preview size to the camera. But you must query for the supported preview sizes and should set one among them.

    Camera camera = camera.open();列出psizes = camera.getParameters().getSupportedPreviewSizes();

    Camera camera = camera.open(); List psizes = camera.getParameters() .getSupportedPreviewSizes();

    一旦设置了预览,就可以使用MediaRecorder开始记录,并且可以将视频大小设置为媒体记录器,这就是将要捕获的视频的实际大小.同样,您应该设置受支持的视频尺寸之一.

    Once you have set up the preview, you can start recording by using a MediaRecorder, and the video size can be set to the media recorder, and it is the actual size of the video that will be captured. Again, you should set one of supported video size.

    列表大小= camera.getParameters().getSupportedVideoSizes();

    List sizes = camera.getParameters() .getSupportedVideoSizes();

    然后,您可以将其中之一设置为媒体记录器

    and then, you can set one of these to the media recorder

    mediaRecorder.setVideoSize(videoWidth, videoHeight);

    因此,请记住始终检查支持的大小,否则肯定会导致应用程序崩溃.

    So, remember to check for the supported sizes always, else you are bound to get an app crash.

  • 更多推荐

    MediaRecorder setVideoSize在不同的设备中显示不同的行为

    本文发布于:2023-07-18 04:40:53,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1141110.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:设备   MediaRecorder   setVideoSize

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!