gpt4 book ai didi

android - 使用与生成的视频文件不同的预览大小录制视频

转载 作者:IT老高 更新时间:2023-10-28 22:03:41 29 4
gpt4 key购买 nike

我正在尝试允许用户录制与他们在录制时可以看到的实际屏幕预览不同大小的视频。这似乎可以从 this documentation concerning the getSupportedVideoSizes function其中指出:

If the returned list is not null, the returned list will contain at least one Size and one of the sizes in the returned list must be passed to MediaRecorder.setVideoSize() for camcorder application if camera is used as the video source. In this case, the size of the preview can be different from the resolution of the recorded video during video recording.

这表明某些手机会从此 fn 返回 null(根据我的经验 Galaxy SIII 会),但对于那些不这样做的人,可以提供与实际视频不同分辨率的预览。这种理解正确吗?有些手机允许这种行为,有些则不允许吗?

尝试解决方案:

official description of the setPreviewDisplay函数,用于lengthy process of setting up for video recording ,其中提到:

If this method is called with null surface or not called at all, media recorder will not change the preview surface of the camera.

这似乎是我想要的,但不幸的是,如果我这样做,整个视频录制过程就完全搞砸了。我假设在录制视频的过程中,这个函数不能传递 null 或根本不调用。也许在其他情况下这是可以的。不幸的是,这似乎对我没有帮助。

我接下来的唯一步骤是查看 TextureViews 并使用预览纹理而不是典型的 SurfaceView 实现,以便使用 openGL 将纹理拉伸(stretch)到我想要的大小,而不是实际分辨率(并裁剪掉屏幕上的任何多余部分),然后使用 Surface 的 Surface(SurfaceTexture surfaceTexture) 构造函数为 setPreviewDisplay 函数构造一个 Surface。我想避免使用 TextureView,因为它在 ICS 下不兼容,也因为这增加了很大的复杂性。

这似乎是一个微妙的过程,但我希望有人可以在这方面提供一些建议。

谢谢。

最佳答案

a.假设用户将x,y的大小设置为视频大小

b.现在使用 getSupportedVideoSizes 函数获取整个列表并查看 x,y 是否属于其中之一并设置 MediaRecorder.setVideoSize()。如果 x,y 不属于 getSupportedVideoSizes 列表,则设置默认配置文件用于视频记录。

这是关于视频大小

现在是预览大小,没有太多的解决方法选项。获取一个保存 SurfaceView 的 RelativeLayout。

<android.view.SurfaceView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

preview 是 SurfaceView 的名称。在这里,我给出了一个将其重新调整为宽度和高度一半的示例。

resetCamera();  //reset the camera   

ViewGroup.LayoutParams params = preview.getLayoutParams();
RelativeLayout myRelLayout = (RelativeLayout) findViewById(R.id.myRelLayout);
params.width = (int) (myRelLayout.getWidth()/2);
params.height = (int)(myRelLayout.getHeight()/2);
preview.setLayoutParams(params);

initCamera(); //initiate the camera(open camera, set parameter, setPreviewDisplay,startPreview)

请查看预览的分辨率,然后根据视频大小相应缩小高度或宽度。

希望对你有帮助。

关于android - 使用与生成的视频文件不同的预览大小录制视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14132558/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com