Skip to content

Commit

Permalink
add common writer FFMediaRecorder and test demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
CainKernel committed Sep 8, 2019
1 parent 719b8db commit 1f2dc17
Show file tree
Hide file tree
Showing 116 changed files with 13,810 additions and 5,643 deletions.
32 changes: 24 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@
package="com.cgfay.caincamera">
<!-- 高通GPU调试权限 -->
<uses-permission android:name="com.qti.permission.PROFILER" />
<uses-permission android:name="android.permission.INTERNET" /> <!-- 存储权限 -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- 存储权限 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- 相机权限 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<!-- 相机权限 -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FLASHLIGHT" /> <!-- 位置权限 -->
<uses-permission android:name="android.permission.FLASHLIGHT" />

<!-- 位置权限 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- 录音权限 -->
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <!-- 获取设备信息权限 -->

<!-- 录音权限 -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<!-- 获取设备信息权限 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" /> <!-- opengles版本控制 -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- opengles版本控制 -->
<uses-feature
android:glEsVersion="0x00030000"
android:required="true" />
Expand All @@ -34,9 +46,13 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.VideoGifMakeActivity" />
<activity android:name=".activity.MusicMergeActivity" />
<activity android:name=".activity.SpeedRecordActivity" android:theme="@style/NoActionBarTheme"/>
<activity
android:name=".activity.SpeedRecordActivity"
android:theme="@style/NoActionBarTheme" />
<activity
android:name=".activity.FFMediaRecordActivity"
android:theme="@style/NoActionBarTheme" />

<!-- 全面屏兼容逻辑 -->
<meta-data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.cgfay.caincamera.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.cgfay.caincamera.R;
import com.cgfay.caincamera.fragment.FFMediaRecordFragment;

public class FFMediaRecordActivity extends AppCompatActivity {

private static final String FRAGMENT_FFMEDIA_RECORD = "FRAGMENT_FFMEDIA_RECORD";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ffmedia_record);
if (null == savedInstanceState) {
FFMediaRecordFragment fragment = new FFMediaRecordFragment();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_container, fragment, FRAGMENT_FFMEDIA_RECORD)
.commit();
}
}

}
50 changes: 10 additions & 40 deletions app/src/main/java/com/cgfay/caincamera/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

Expand Down Expand Up @@ -59,7 +58,7 @@ private void initView() {
findViewById(R.id.btn_edit_picture).setOnClickListener(this);
findViewById(R.id.btn_speed_record).setOnClickListener(this);
findViewById(R.id.btn_edit_music_merge).setOnClickListener(this);
findViewById(R.id.btn_edit_gif_make).setOnClickListener(this);
findViewById(R.id.btn_ff_media_record).setOnClickListener(this);
}

@Override
Expand Down Expand Up @@ -93,7 +92,6 @@ public void onClick(View v) {
case R.id.btn_speed_record: {
Intent intent = new Intent(MainActivity.this, SpeedRecordActivity.class);
startActivity(intent);
finish();
break;
}

Expand All @@ -102,8 +100,8 @@ public void onClick(View v) {
break;
}

case R.id.btn_edit_gif_make: {
videoConvertGif();
case R.id.btn_ff_media_record: {
ffmpegRecord();
break;
}
}
Expand All @@ -113,13 +111,10 @@ public void onClick(View v) {
* 初始化动态贴纸、滤镜等资源
*/
private void initResources() {
new Thread(new Runnable() {
@Override
public void run() {
ResourceHelper.initAssetsResource(MainActivity.this);
FilterHelper.initAssetsFilter(MainActivity.this);
MakeupHelper.initAssetsMakeup(MainActivity.this);
}
new Thread(() -> {
ResourceHelper.initAssetsResource(MainActivity.this);
FilterHelper.initAssetsFilter(MainActivity.this);
MakeupHelper.initAssetsMakeup(MainActivity.this);
}).start();
}

Expand Down Expand Up @@ -233,34 +228,9 @@ public void onSelected(List<Uri> uriList, List<String> pathList, boolean isVideo
}

/**
* 视频转GIF
* 备注:目前so没有把gif的encoder 和 muxer编译进去,这里没做完整的测试
* 使用FFmpeg 录制视频
*/
private void videoConvertGif() {
MediaScanEngine.from(this)
.setMimeTypes(MimeType.ofAll())
.ImageLoader(new GlideMediaLoader())
.spanCount(4)
.showCapture(true)
.showImage(false)
.showVideo(true)
.enableSelectGif(false)
.setCaptureListener(new OnCaptureListener() {
@Override
public void onCapture() {
previewCamera();
}
})
.setMediaSelectedListener(new OnMediaSelectedListener() {
@Override
public void onSelected(List<Uri> uriList, List<String> pathList, boolean isVideo) {
if (isVideo) {
Intent intent = new Intent(MainActivity.this, VideoGifMakeActivity.class);
intent.putExtra(VideoGifMakeActivity.PATH, pathList.get(0));
startActivity(intent);
}
}
})
.scanMedia();
private void ffmpegRecord() {
startActivity(new Intent(MainActivity.this, FFMediaRecordActivity.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,19 @@ protected void onCreate(Bundle savedInstanceState) {
fragment.addOnMusicSelectedListener(listener);
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_content, fragment)
.addToBackStack(FRAGMENT_MUSIC_MERGE)
.add(R.id.fragment_container, fragment)
.commit();
}
}

@Override
public void onBackPressed() {
// 判断fragment栈中的个数,如果只有一个,则表示当前只处于视频编辑主页面点击返回
int backStackEntryCount = getSupportFragmentManager().getBackStackEntryCount();
if (backStackEntryCount == 1) {
finish();
} else {
super.onBackPressed();
}
}

private MusicSelectFragment.OnMusicSelectedListener listener = new MusicSelectFragment.OnMusicSelectedListener() {
@Override
public void onMusicSelected(Music music) {
MusicMergeFragment fragment = MusicMergeFragment.newInstance();
fragment.setVideoPath(mVideoPath);
fragment.setMusicPath(music.getSongUrl(), music.getDuration());
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_content, fragment, FRAGMENT_MUSIC_MERGE)
.addToBackStack(FRAGMENT_MUSIC_MERGE)
.commit();
}
private MusicSelectFragment.OnMusicSelectedListener listener = (music) -> {
MusicMergeFragment fragment = MusicMergeFragment.newInstance();
fragment.setVideoPath(mVideoPath);
fragment.setMusicPath(music.getSongUrl(), music.getDuration());
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, fragment, FRAGMENT_MUSIC_MERGE)
.commit();
};

}

This file was deleted.

Loading

0 comments on commit 1f2dc17

Please sign in to comment.