Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video & Audio Record #518

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0-beta04'
classpath 'com.android.tools.build:gradle:4.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// TODO: Close JCenter on May 1st https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ VERSION_NAME=2.1.0
VERSION_CODE=14

COMPILE_SDK_VERSION=30
TARGET_SDK_VERSION=30
MIN_SDK_VERSION=14
TARGET_SDK_VERSION=29
MIN_SDK_VERSION=18

android.useAndroidX=true
android.enableJetifier=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package jp.co.cyberagent.android.gpuimage;

import android.annotation.TargetApi;
import android.opengl.EGL14;

import java.io.IOException;
import java.nio.FloatBuffer;

import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;

import jp.co.cyberagent.android.gpuimage.encoder.EglCore;
import jp.co.cyberagent.android.gpuimage.encoder.MediaAudioEncoder;
import jp.co.cyberagent.android.gpuimage.encoder.MediaEncoder;
import jp.co.cyberagent.android.gpuimage.encoder.MediaMuxerWrapper;
import jp.co.cyberagent.android.gpuimage.encoder.MediaVideoEncoder;
import jp.co.cyberagent.android.gpuimage.encoder.WindowSurface;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageFilter;

@TargetApi(18)
public class GPUImageMovieWriter extends GPUImageFilter {
private MediaMuxerWrapper mMuxer;
private MediaVideoEncoder mVideoEncoder;
private MediaAudioEncoder mAudioEncoder;
private WindowSurface mCodecInput;

private EGLSurface mEGLScreenSurface;
private EGL10 mEGL;
private EGLDisplay mEGLDisplay;
private EGLContext mEGLContext;
private EglCore mEGLCore;

private boolean mIsRecording = false;

@Override
public void onInit() {
super.onInit();
mEGL = (EGL10) EGLContext.getEGL();
mEGLDisplay = mEGL.eglGetCurrentDisplay();
mEGLContext = mEGL.eglGetCurrentContext();
mEGLScreenSurface = mEGL.eglGetCurrentSurface(EGL10.EGL_DRAW);
}

@Override
public void onDraw(int textureId, FloatBuffer cubeBuffer, FloatBuffer textureBuffer) {
// Draw on screen surface
super.onDraw(textureId, cubeBuffer, textureBuffer);

if (mIsRecording) {
// create encoder surface
if (mCodecInput == null) {
mEGLCore = new EglCore(EGL14.eglGetCurrentContext(), EglCore.FLAG_RECORDABLE);
mCodecInput = new WindowSurface(mEGLCore, mVideoEncoder.getSurface(), false);
}

// Draw on encoder surface
mCodecInput.makeCurrent();
super.onDraw(textureId, cubeBuffer, textureBuffer);
mCodecInput.swapBuffers();
mVideoEncoder.frameAvailableSoon();
}

// Make screen surface be current surface
mEGL.eglMakeCurrent(mEGLDisplay, mEGLScreenSurface, mEGLScreenSurface, mEGLContext);
}

@Override
public void onDestroy() {
super.onDestroy();
releaseEncodeSurface();
}

public void startRecording(final String outputPath, final int width, final int height) {
runOnDraw(new Runnable() {
@Override
public void run() {
if (mIsRecording) {
return;
}

try {
mMuxer = new MediaMuxerWrapper(outputPath);

// for video capturing
mVideoEncoder = new MediaVideoEncoder(mMuxer, mMediaEncoderListener, width, height);
// for audio capturing
mAudioEncoder = new MediaAudioEncoder(mMuxer, mMediaEncoderListener);

mMuxer.prepare();
mMuxer.startRecording();

mIsRecording = true;
} catch (IOException e) {
e.printStackTrace();
}
}
});
}

public void stopRecording() {
runOnDraw(new Runnable() {
@Override
public void run() {
if (!mIsRecording) {
return;
}

mMuxer.stopRecording();
mIsRecording = false;
releaseEncodeSurface();
}
});
}

private void releaseEncodeSurface() {
if (mEGLCore != null) {
mEGLCore.makeNothingCurrent();
mEGLCore.release();
mEGLCore = null;
}

if (mCodecInput != null) {
mCodecInput.release();
mCodecInput = null;
}
}

/**
* callback methods from encoder
*/
private final MediaEncoder.MediaEncoderListener mMediaEncoderListener = new MediaEncoder.MediaEncoderListener() {
@Override
public void onPrepared(final MediaEncoder encoder) {
}

@Override
public void onStopped(final MediaEncoder encoder) {
}

@Override
public void onMuxerStopped() {
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ private void adjustImageScaling() {
addDistance(textureCords[6], distHorizontal), addDistance(textureCords[7], distVertical),
};
} else {
if (rotation == Rotation.ROTATION_270 || rotation == Rotation.ROTATION_90) {
ratioWidth = ratioWidth + ratioHeight;
ratioHeight = ratioWidth - ratioHeight;
ratioWidth = ratioWidth - ratioHeight;
}
cube = new float[]{
CUBE[0] / ratioHeight, CUBE[1] / ratioWidth,
CUBE[2] / ratioHeight, CUBE[3] / ratioWidth,
Expand Down
Loading