视频录制框架LandscapeVideoCamera

原创 2017年01月03日 10:42:08

LandscapeVideoCamera

Build Status Codecov.io Release MethodCount License

Highly flexible Android Camera which offers granular control over the video quality and filesize, while restricting recordings to be landscape only.

Get it on Google Play

There are a number of issues with the default Android intent to capture videos (MediaStore.ACTION_VIDEO_CAPTURE) which led me to create this library project:

  1. The default intent only accepts integer quality parameters of 0 (MMS quality) or 1 (highest available quality), using the intent extra MediaStore.EXTRA_VIDEO_QUALITY.
  2. The default intent does not return the URI of the recorded file if it was specified when launching the intent.
  3. The default intent doesn't care whether users capture their video in portrait mode or landscape.

LandscapeVideoCamera in action

Features

This library provides a full and reusable custom camera, which:

  • Forces the users to rotate their device to landscape
  • Allows to specify the filename, or have the library generate one for you
  • Allows very granular control over the capture settings:
    • Resolution
    • Bitrate
    • Max filesize
    • Max video duration
    • audio/video codec
    • switch between front and rear facing camera
    • ...

How to use

1) Add the Jitpack repository to your project:

          repositories {
              maven { url "https://jitpack.io" }
          }

2) Add a dependency on the library:

          compile 'com.github.JeroenMols:LandscapeVideoCamera:1.2.2'

3) Specify the VideoCaptureActivity in your manifest:

         <activity
             android:name="com.jmolsmobile.landscapevideocapture.VideoCaptureActivity"
             android:screenOrientation="sensor" >
         </activity>

4) Request the following permissions in your manifest:

         <uses-permission android:name="android.permission.RECORD_AUDIO" />
         <uses-permission android:name="android.permission.CAMERA" />
         <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

5) Create a CaptureConfiguration - object with the desired parameters. (optional)

         CaptureConfiguration configuration = CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality);
         CaptureConfiguration configuration = CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality, int maxDurationSecs, int maxFilesizeMb);
         CaptureConfiguration configuration = CaptureConfiguration(int videoWidth, int videoHeight, int bitrate);
         CaptureConfiguration configuration = CaptureConfiguration(int videoWidth, int videoHeight, int bitrate, int maxDurationSecs, int maxFilesizeMb);
         CaptureConfiguration configuration = CaptureConfiguration(int videoWidth, int videoHeight, int bitrate, int maxDurationSecs, int maxFilesizeMb, boolean showTimer);
         CaptureConfiguration configuration = CaptureConfiguration(int videoWidth, int videoHeight, int bitrate, int maxDurationSecs, int maxFilesizeMb, boolean showTimer, boolean allowFrontCamera);

Note: When no CaptureConfiguration is specified, a default configuration will be used.

Note 2: Subclass the CaptureConfiguration class to set more advanced configurations. (codecs, audio bitrate,...)

6) Launch the VideoCaptureActivity for result, add the CaptureConfiguration as an parcelable extra EXTRA_CAPTURE_CONFIGURATION and optionally add a String extra EXTRA_OUTPUT_FILENAME.

         final Intent intent = new Intent(getActivity(), VideoCaptureActivity.class);
         intent.putExtra(VideoCaptureActivity.EXTRA_CAPTURE_CONFIGURATION, config);
         intent.putExtra(VideoCaptureActivity.EXTRA_OUTPUT_FILENAME, filename);
         startActivityForResult(intent, RESULT_CODE);

7) Check the resultcode (RESULT_OKRESULT_CANCELLED or VideoCaptureActivity.RESULT_ERROR) and in case of success get the output filename in the intent extra EXTRA_OUTPUT_FILENAME.

Questions

@molsjeroen

Thanks

Android Arsenal

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

【分享】性能比肩美拍秒拍的Android视频录制编辑特效解决方案【1】

前言 众所周知,Android平台开发分为Java层和C++层,即Android SDK和Android NDK。常规产品功能只需要涉及到Java层即可,除非特殊需要是不需要引入NDK的。但如果是进行...

Android开发之使用MediaRecorder录制视频

MediaRecorder除了可以用于录制音频,还可用于录制视频。使用MediaRecorder录制视频与录制音频的步骤基本相同。只是录制视频时不仅需要采集声音,还需要采集图像。为了让MediaRec...

Android使用MediaRecorder和Camera实现视频录制及播放功能整理

这两天产品经理向我丢来一个新需求,需要在项目里添加一个视频录制的功能,正好是我没做过的,于是研究了一番。在网上搜索了一些案例,但是都是不完整的,要不就是分辨率有问题的,要不就是声音有问题的,要不就是实...

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

Android开发短视频录制

android短视频录制
  • longsh_
  • longsh_
  • 2016年08月30日 16:07
  • 4346

Android 实现视频录制并播放

AndroidManifest.xml:
  • hzw2312
  • hzw2312
  • 2015年11月26日 10:24
  • 6171

Android在MediaMuxer和MediaCodec录制视频示例 - audio+video

在Android多媒体类,MediaMuxer和MediaCodec这是一个相对年轻,他们是JB 4.1和JB 4.3据介绍。 前者被用来产生一个混合的音频和视频的多媒体文件。的缺点是,现在可以...

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

Android系统自带的MediaRecorder结合Camera实现视频录制及播放功能。

近期,公司项目新增了需求,需要视频录制,然后保存到本地,再播放...。 看了很多其他的框架,说不出好坏,应该说各有千秋吧。但我觉得还是原生的靠谱,就是谷歌系统自带的MediaRecorder。 不多说...

Android 实现视频录制播放

android的仿微信视频录制播放,可以实现10秒中的视频录制,然后将该视频以mp4的格式存放在本地,用surfaceview播放。...
  • yilip
  • yilip
  • 2015年04月16日 15:16
  • 27388
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:视频录制框架LandscapeVideoCamera
举报原因:
原因补充:

(最多只允许输入30个字)