Code Monkey home page Code Monkey logo

Comments (13)

CainKernel avatar CainKernel commented on July 24, 2024 3

我觉得你似乎搞错了一样东西,filter中的drawFrame只是渲染了视频画面。但是渲染的画面大小和坐标都是你手动来调整的,也就是说你要做的是调整VertexCoords 和 TextureCoords的坐标,默认情况下,VertexCoords 和 TextureCoords的坐标是0.0-1.0的,也就是根据长宽比来录制的,如果你要进行正方形录制,比如最靠近的4:3的1440 x 1080、1024 x 768等分辨率,合适的1:1分辨率太少了,然后调整录制的TextureCoords坐标,裁剪掉上下超出的部分,裁剪的方式就是重新计算VertexCoords 和 TextureCoords的坐标,filter中的drawFrame方法用到的两个坐标都是可以重新计算的,记住不要放在绘制时计算,会影响预览帧率的,你可以在绘制的空档时间内计算。我觉得你要理解顶点坐标和纹理坐标分别有什么用的,不然以后你要加入动态贴纸的话,你还是不会做的。预览画面的话,有两种方案,一种是在FrameLayout上面覆盖一层遮罩。另一种是在输出画面的DisplayFilter上做裁剪处理,然后再调整显示的位置。至少在用SurfaceView + EGL、GLSurfaceView的情况下,没太好的办法,用TextureView 可以灵活一些,但会有1~3帧的延迟,一般很少会用这个做相机的。目前市面上用得最多的就是SurfaceView + EGL或者直接用GLSurfaceView。

from caincamera.

CainKernel avatar CainKernel commented on July 24, 2024 1

from caincamera.

icepring avatar icepring commented on July 24, 2024

感谢解惑,不然还不知道该怎么谷歌...

from caincamera.

erleizh avatar erleizh commented on July 24, 2024

@CainKernel 通过坐标的方式调整预览画面这种只是改变了预览的样子 ,并没有改变录制的时候视频尺寸 , 这个录制尺寸最终还是由 camera 支持的尺寸来决定的 我理解的对吧

from caincamera.

CainKernel avatar CainKernel commented on July 24, 2024

from caincamera.

CainKernel avatar CainKernel commented on July 24, 2024

from caincamera.

icepring avatar icepring commented on July 24, 2024

感谢这波技术支持,昨天了解了顶点坐标和纹理坐标后已经做好了,和大佬下面的思路一样

from caincamera.

CainKernel avatar CainKernel commented on July 24, 2024

不用客气。其实OpenGLES 用起来并不难,刚开始接触的时候,因为没经验没思路,然后又没人指导,所以无从下手,我当初写这个项目的时候也是为了能给后来者提供一些的思路的。

from caincamera.

mackzheng avatar mackzheng commented on July 24, 2024

这里有一个非常简洁的录制demo OpenGL + GLSurfaceView + Camera 实现录制。
https://github.com/saki4510t/AudioVideoRecordingSample.git

sdk>18 MediaCodec 通过参数设置实现, 内部原理还没有细看。
生成正方形 视频 ,确实可以实现,已经验证了。
后续有空在saki4510t 的demo基础上 在录制前,设置相关参数。

修改方法:

  1. CameraGLView layout的布局 。
    <com.serenegiant.audiovideosample.CameraGLView
    android:id="@+id/cameraView"
    android:layout_width="480px"
    android:layout_height="480px"
    android:layout_centerInParent="true" />

  2. mCameraHandler.startPreview(1280, 720/width, height/); 修改预览宽高
    ->mCameraHandler.startPreview(480, 480/width, height/);

  3. mCameraView.setVideoSize(1280, 720);
    -> mCameraView.setVideoSize(480, 480);

  4. CameraGLView -> startPreview(final int width, final int height) 方法中
    st.setDefaultBufferSize(previewSize.width, previewSize.height); 起到关键作用。
    实际上是通过如下代码设置:
    final Camera.Size closestSize = getClosestSupportedSize(
    params.getSupportedPreviewSizes(), width, height);
    params.setPreviewSize(closestSize.width, closestSize.height);

这里选取了摄像头支持的最接近的 分辨率设置:

最关键地方 修改如下:
parent.post(new Runnable() {
@OverRide
public void run() {
// parent.setVideoSize(previewSize.width, previewSize.height);
关键修改: parent.setVideoSize(480, 480);
}
});
final SurfaceTexture st = parent.getSurfaceTexture();
关键修改: st.setDefaultBufferSize(480, 480);
mCamera.setPreviewTexture(st);

打印如下
com.serenegiant.audiovideosample D/CameraGLView: Camera thread start
com.serenegiant.audiovideosample V/CameraGLView: startPreview:
com.serenegiant.audiovideosample I/CameraGLView: fps:8000-30000
com.serenegiant.audiovideosample V/CameraGLView: setRotation:
com.serenegiant.audiovideosample I/CameraGLView: previewSize(640, 480)
com.serenegiant.audiovideosample V/CameraGLView: getSurfaceTexture:
com.serenegiant.audiovideosample I/CameraGLView: view(480,480)1.000000,video(480,480)

这里目前自己还有几点疑问 没有弄清楚:
### 1. 640 * 480 相机的预览宽高,如何 转换成了 480 * 480 的宽高?
### 2. SurfaceTexture 与CameraGLView 设置 宽高的关系?
### 3. 640 *480 的相机预览 按照什么样的方式裁剪成 480 * 480?
### 4. 如何修改码率和帧率?

5.视频会保存到 sdcard/Movies/AVRecSample/ 目录下。输出了正方形的

第4步最关键的修改。

from caincamera.

Greatkingcj avatar Greatkingcj commented on July 24, 2024

你好, 我这里也需要按特定比例预览和裁剪视频, 看了下你上面的解释,我有些疑惑。比如这里我需要1:1裁剪,然后我选了相机支持的尺寸768 * 1024, 然后预览尺寸是1080 * 1080,viewport也是1080*1080 然后在adjustCoordinateSize中, 我直接把纹理坐标调整如下:
textureCoord = new float[] {
0f, 0.125f,
1f, 0.125f,
0f, 0.875f,
1f, 0.875f
};
这样预览和最后录制就是1:1的正方形了。
你上面说“也就是说你要做的是调整VertexCoords 和 TextureCoords的坐标”, 这里为什么需要调整顶点坐标?
另外是不是相机图片比例和预览比例及viewport比例相同是不是不用做任何调整?我打印了下3:4和9:16这两种情况下,其实你顶点坐标和纹理坐标都没有变的

from caincamera.

CainKernel avatar CainKernel commented on July 24, 2024

from caincamera.

Greatkingcj avatar Greatkingcj commented on July 24, 2024

顶点坐标不一定要调整啊,顶点坐标和纹理坐标调整一个就行,通常只调纹理坐标。比例相同,还需要做啥裁剪?比例都一样了,绘制的纹理就没有多余的图像数据,自然不需要做任何裁剪操作啊。 发自我的小米手机 在 charles [email protected],2019年3月25日 下午7:14写道: 你好, 我这里也需要按特定比例预览和裁剪视频, 看了下你上面的解释,我有些疑惑。比如这里我需要1:1裁剪,然后我选了相机支持的尺寸768 * 1024, 然后预览尺寸是1080 * 1080,viewport也是1080*1080 然后在adjustCoordinateSize中, 我直接把纹理坐标调整如下: textureCoord = new float[] { 0f, 0.125f, 1f, 0.125f, 0f, 0.875f, 1f, 0.875f }; 这样预览和最后录制就是1:1的正方形了。 你上面说“也就是说你要做的是调整VertexCoords 和 TextureCoords的坐标”, 这里为什么需要调整顶点坐标? 另外是不是相机图片比例和预览比例及viewport比例相同是不是不用做任何调整?我打印了下3:4和9:16这两种情况下,其实你顶点坐标和纹理坐标都没有变的 — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub<#14 (comment)>, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AK7ZPLqihZApQSG0RAxfwne1teDoxgMeks5vaK-ogaJpZM4TXmAm.

哦, 是这样啊, 那调整顶点坐标是不是一样的处理, 只是说顶点的范围是[-1, 1]而已, 然后按比例取这个范围的值?

from caincamera.

HeYongRui avatar HeYongRui commented on July 24, 2024

感谢这波技术支持,昨天了解了顶点坐标和纹理坐标后已经做好了,和大佬下面的思路一样

你好,我最近也遇到了同样的问题,我通过改变纹理坐标,但是有些还是不对,能告诉一下你的实现方式吗 @icepring

from caincamera.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.