android录制视频,android录制视频VBR

Android录制视频,可限制时长,限大小

Android 录制视频:

网站建设哪家好,找成都创新互联公司!专注于网页设计、网站建设、微信开发、微信小程序定制开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了绛县免费建站欢迎大家使用!

public static voidrecordVideo(Context context, intlimit_time, intsize) {    

Intent intent =newIntent();

intent.setAction(MediaStore. ACTION_VIDEO_CAPTURE );

intent.putExtra(MediaStore. EXTRA_VIDEO_QUALITY ,1);

intent.addCategory(Intent. CATEGORY_DEFAULT );

if(size !=0) {        

  //大小限制是long型,int 型无效,所以后边要写一个L

    intent.putExtra(MediaStore. EXTRA_SIZE_LIMIT ,size *1024*1024L);//限制录制大小(10M=10 * 1024 * 1024L)

}

if(limit_time !=0) {      

      intent.putExtra(MediaStore. EXTRA_DURATION_LIMIT ,limit_time);//限制录制时间(10秒=10)

}    

File videoFile =createVideoFile(context);

if(videoFile !=null) {        

    intent.putExtra(MediaStore. EXTRA_OUTPUT ,Uri.fromFile(videoFile));

    context.startActivityForResult(intent, CAPTURE_VIDEO_CODE );

}

}

ADB录制视频 Android 视频录制命令 screenrecord

在Android 4.4(Kitkat - API level 19)上集成了一个比较好用的视频(.mp4格式)录制功能 – screenrecord 。

使用方法

1.  基本用法

$ adb shell screenrecord /sdcard/myscreenrecord.mp4

/sdcard/myscreenrecord.mp4 为视频录制文件路径

录制默认分辨率,默认4Mbps,默认180s的视频,保存到sdcard上名为myscreenrecord.mp4

2.  旋转(参数:–rotate)

$ adb shell screenrecord --rotate /sdcard/myscreenrecord.mp4

旋转90度

3.  指定分辨率(参数:–size)

$adb shell screenrecord --size 112x112 /sdcard/myscreenrecord.mp4

分辨率为112x112,建议不要指定分辨率,使用默认分辨率效果最佳;

注意,分辨率不是完全可以随意定制的,比如在我手机上录制100x100的会提示错误:

The max width/height supported by codec is1920x1088

100x100is not supported by codec, suggest to set it as112x112

4.  指定比特率(参数:–bit-rate)

$adb shell screenrecord --bit -rate 8000000 /sdcard/myscreenrecord.mp4

设置比特率为8Mbps,比特率越大,文件越大,画面越清晰;

5.  限制录制时间 (参数: –time-limit)

$adb shell screenrecord --time -limit 10 /sdcard/myscreenrecord.mp4

限制视频录制时间为10s,如果不限制,默认180s

6.  导出视频

$adb pull /sdcard/myscreenrecord.mp4

7.  注意

请关注视频文件生成大小,根据自身情况而定;

暂不支持声音;

咱时不支持模拟器录制( 模拟器录制看这里 ),出现如下提示:Unable to get output buffers (err=-38)

Encoder failed (err=-38),可认为是此原因;

8.  命令查看

adb shell screenrecord --help

Usage: screenrecord [options]

Records the device's display to a .mp4 file.

Options:

--size WIDTHxHEIGHT

Set the video size, e.g."1280x720".  Default is the device's main

display resolution (if supported),        1280x720if not.  For best

results,use a size supported by the AVC encoder.

--bit -rate RATE

Set the video bit rate, in megabits per second.  Default4Mbps.

--time -limit TIME

Set the maximum recording time, in seconds.  Default / maximum is180.

--rotate

Rotate the output90 degrees.

--verbose

Display interesting information on stdout.

--help

Showthis message.

Recording continues until Ctrl-C is hit or the time limit is reached.

Android调用系统相机实现拍照和视频录制

(1)申请权限

(2)设置布局

这里做了一个简单的布局:添加了一个按钮和一个ImageView控件用于显示拍摄的图像。

(3)为按钮添加点击事件监听

点击按钮时,调用系统相机进行拍照,并在确定后将图像显示在ImageView控件中。

(1)申请权限

(2)设置布局

添加了一个按钮和一个VideoView控件用于显示录制的视频。

(3)为按钮添加点击事件监听

同前面一样,点击按钮后调用系统相机进行录制视频,录制完成后点击确定即可将录制的视频显示在VideoView控件中。

对于Android11.0的版本,在调用系统相近进行视频录制的时候,即使在AndroidMenifest.xml中申请了CAMERA权限,还是会在程序运行时报错: Permission  Denial ,   . .... ....  with revoked permission android.permission.CAMERA

解决方法是在程序中动态申请权限:

写在最后:文章是在学习过程中做的学习笔记,同时与志同道合者分享,文章内容均经过我自己实验证实可行,如有问题欢迎留言,很高兴一起交流讨论,共同进步!

Android录制视频并添加水印

最近有需求,录制视频的时候要添加水印,怎么搞?最后决定,opengles作为相机预览并在上面绘制水印,使用mediacodec进行编码,使用mediamuxer输出mp4文件,有需要的拿走。

本想写篇博客,发现这些无论拿出哪个点都得写半天,我最近也对opengles十分感兴趣,以后有时间详细分析一下.

用法比较简单

waterX和waterY是水印左下角坐标的位置,范围为[-1,1]

效果如下:

最后附上github地址

github


分享文章:android录制视频,android录制视频VBR
网址分享:http://pwwzsj.com/article/dsipjjg.html