简体   繁体   English

Android:如何使用Mediacodec将两个重叠的视频保存为一个?

[英]Android: How to save two overlapped videos as one using mediacodec?

I want to do something similar to this on android. 我想要做类似的东西在Android上。

I want to load video from file and display it twice with some transformations (mostly resize). 我想从文件中加载视频并通过一些转换(主要是调整大小)将其显示两次。 And i want to encode it as one video file. 我想将其编码为一个视频文件。

Is it possible to do it in native android? 是否可以在本机android中做到这一点? With mediacodec or in any other way? 使用mediacodec还是其他方式?

I know there is a ffmpeg but i have trouble compiling it and working with Xamarin. 我知道有一个ffmpeg,但是我在编译它和使用Xamarin时遇到了麻烦。

MMSF will allow you to display one video twice on the screen. MMSF将允许您在屏幕上两次显示一个视频。 MediaCodec is used for all video decode operations. MediaCodec用于所有视频解码操作。 No special decode/extra libraries are needed. 不需要特殊的解码/额外库。 MMSF only uses existing Android Java APIs (MediaCodec/GLES). MMSF仅使用现有的Android Java API(MediaCodec / GLES)。 The goal of displaying a single video to multiple geoemtry can be accomplished within the fragment shader with relative ease. 可以相对容易地在片段着色器中实现将单个视频显示到多个几何体的目标。 MMSF Sample #2 illustrates how to display multiple videos, but could be tweaked to make a single video display 1 or more times to the screen. MMSF示例2说明了如何显示多个视频,但可以进行调整以使单个视频在屏幕上显示1次或多次。 Within the fragment FragmentShader.java you would want to change the texture samplers to all sample from the same source instead of unique samplers. 在片段FragmentShader.java中,您需要将纹理采样器更改为来自同一源的所有采样,而不是唯一的采样器。 For example, texture2D(sTexture2,texCoord) would become texture2D(sTexture,texCoord) and so forth. 例如,texture2D(sTexture2,texCoord)将变为texture2D(sTexture,texCoord),依此类推。 This will cause the same video to be applied multiple times to different geometry. 这将导致同一视频多次应用于不同的几何体。 The tiled geometry can also be changed by modifying gles2layout.java to suit your particular needs or you could replace the implementation altogether and simply provide your own vertex data. 也可以通过修改gles2layout.java来更改平铺的几何形状以适合您的特定需求,或者您可以完全替换实现并仅提供自己的顶点数据。 This would get the overlapping effect. 这将获得重叠效果。 Individual pixel processing algorithms & scaling operations / transforms could also be applied to the geometry or with fragement/vertex shader to achieve the other processing goals and may be targeted to specific geometry using the per vertex color as an indicator of what effect to apply. 单独的像素处理算法和缩放操作/变换也可以应用于几何图形,或者与碎片/顶点着色器一起使用,以实现其他处理目标,并且可以使用每个顶点的颜色作为要应用何种效果的指标来针对特定的几何图形。 Another pretty simple approach would be through some creative use of texture coordinate mappings. 另一种非常简单的方法是通过创造性地使用纹理坐标映射。 Hope this helps and good luck! 希望这会有所帮助,并祝你好运!

Try using Google's ExoPlayer library . 尝试使用Google的ExoPlayer库 For the activity layout use a FrameLayout with two TextureViews, one large and one small with the smaller one on top to give the overlap effect. 对于活动布局,请使用带有两个TextureViews的FrameLayout,一个大一个小,顶部一个小,以产生重叠效果。

ExoPlayer demo code is here . ExoPlayer 演示代码在这里

Also ExoPlayer is a layer on top of MediaCodec (API 16), meaning this will work going back to JellyBean 4.1. ExoPlayer也是MediaCodec(API 16)之上的一层,这意味着可以追溯到JellyBean 4.1。

Update : 更新

With both videos playing in the two TextureViews you can record the output to a video file. 在两个TextureViews中播放两个视频后,您可以将输出记录到视频文件中。

High-level Overview: 高层概述:

(I'll try to give a better code sample later) (稍后我将尝试提供更好的代码示例)

Initialization 初始化

  • Prepare a Bitmap-based Canvas 准备基于位图的画布
  • Prepare a MediaEncoder 准备MediaEncoder
  • Prepare a MediaMuxer 准备MediaMuxer

In a periodic loop (ie once every 30 milliseconds): 在周期性循环中(即每30毫秒一次):

  • Draw root view to Canvas 将根视图绘制到画布
  • Enqueue bitmap to MediaEncoder 将位图排队到MediaEncoder
  • Mux to MP4 Mux转MP4

To put multiple overlapped video frames on a testure you can use Multi-Media Sample Framework: https://software.intel.com/sites/landingpage/mmsf/documentation/mmsf_android_example2.html 要将多个重叠的视频帧放在睾丸上,可以使用多媒体样本框架: https ://software.intel.com/sites/landingpage/mmsf/documentation/mmsf_android_example2.html

在此处输入图片说明

To create video file from textures you can try to use GLCapture from Intel INDE Media for Mobile. 要从纹理创建视频文件,您可以尝试使用Intel INDE Media for Mobile的GLCapture。 Tutorials are here: https://software.intel.com/en-us/articles/intel-inde-media-pack-for-android-tutorials-video-capturing-for-opengl-applications and samples are here: https://github.com/INDExOS/media-for-mobile . 教程在这里: https : //software.intel.com/zh-cn/articles/intel-inde-media-pack-for-android-tutorials-video-capturing-for-opengl-应用程序和示例在这里: https: //github.com/INDExOS/media-for-mobile The only issue is that GLCapture does not support audio from file, so if you need audio you might have to go through MediaCodec way. 唯一的问题是GLCapture不支持文件中的音频,因此,如果需要音频,则可能必须使用MediaCodec方式。

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

相关问题 使用android MediaCodec api压缩视频 - Compress Videos using android MediaCodec api 如何使用mediacodec在android中使用软件编解码器 - how to use software codec in android using mediacodec 使用mediacodec的Aac编码器用一个通道初始化,但输出为两个通道 - Aac encoder using mediacodec was initialized with one channel but outputs as two channels Android - 如何加入两个视频 - Android - How to join two videos 当两张图像重叠时,一张消失。 怎么解决呢? - When two images are overlapped, one is disappeared. How to solve it? 如何在android中制作多个重叠的布局(这意味着禁用一个布局而其他布局变得重叠) - how to make multiple overlapped layout in android(it means make one layout disable and other layout become overlapped) 使用MediaCodec和Surface进行Android编码 - Android encoding using MediaCodec and a Surface 如何使用 MediaCodec Android 压缩 mp4 视频? - How to compress mp4 video using MediaCodec Android? 如何通过保存到SDcard在Android中保存流式视频? - How to save streaming videos in Android by saving to SDcard? 如何使用Android AudioRecord和MediaCodec作为音频编码器正确处理PTS? - How to handle the PTS correctly using Android AudioRecord and MediaCodec as audio encoder?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM