Browse Source

Fix recorded video rotation

new-home-ui
Hardcore Sushi 9 months ago
parent
commit
497c22edc1
Signed by: hardcoresushi
GPG Key ID: 007F84120107191E
  1. 4
      app/proguard-rules.pro
  2. 6
      app/src/main/java/sushi/hardcore/droidfs/video_recording/MediaMuxer.kt
  3. 1
      app/src/main/java/sushi/hardcore/droidfs/video_recording/VideoCapture.java
  4. 10
      app/src/main/native/libmux.c
  5. 2
      build.gradle

4
app/proguard-rules.pro vendored

@ -25,3 +25,7 @@
-keepclassmembers class sushi.hardcore.droidfs.explorers.ExplorerElement {
static sushi.hardcore.droidfs.explorers.ExplorerElement new(...);
}
-keepclassmembers class sushi.hardcore.droidfs.video_recording.MediaMuxer {
void writePacket(byte[]);
void seek(long);
}

6
app/src/main/java/sushi/hardcore/droidfs/video_recording/MediaMuxer.kt

@ -6,7 +6,7 @@ import java.nio.ByteBuffer
class MediaMuxer(val writer: SeekableWriter) {
external fun allocContext(): Long
external fun addVideoTrack(formatContext: Long, bitrate: Int, width: Int, height: Int): Int
external fun addVideoTrack(formatContext: Long, bitrate: Int, width: Int, height: Int, orientationHint: Int): Int
external fun addAudioTrack(formatContext: Long, bitrate: Int, sampleRate: Int, channelCount: Int): Int
external fun writeHeaders(formatContext: Long): Int
external fun writePacket(formatContext: Long, buffer: ByteArray, pts: Long, streamIndex: Int, isKeyFrame: Boolean)
@ -20,6 +20,7 @@ class MediaMuxer(val writer: SeekableWriter) {
var formatContext: Long?
var orientationHint = 0
var realVideoTrackIndex: Int? = null
var audioFrameSize: Int? = null
var firstPts: Long? = null
@ -63,7 +64,8 @@ class MediaMuxer(val writer: SeekableWriter) {
formatContext!!,
bitrate,
format.getInteger("width"),
format.getInteger("height")
format.getInteger("height"),
orientationHint
)
VIDEO_TRACK_INDEX
}

1
app/src/main/java/sushi/hardcore/droidfs/video_recording/VideoCapture.java

@ -464,6 +464,7 @@ public final class VideoCapture extends UseCase {
synchronized (mMuxerLock) {
mMuxer = new MediaMuxer(outputFileOptions.mWriter);
mMuxer.setOrientationHint(getRelativeRotation(attachedCamera));
}
mEndOfVideoStreamSignal.set(false);

10
app/src/main/native/libmux.c

@ -1,6 +1,7 @@
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/channel_layout.h>
#include <libavutil/display.h>
#include <jni.h>
const size_t BUFF_SIZE = 4096;
@ -68,14 +69,19 @@ Java_sushi_hardcore_droidfs_video_1recording_MediaMuxer_addAudioTrack(JNIEnv *en
}
JNIEXPORT jint JNICALL
Java_sushi_hardcore_droidfs_video_1recording_MediaMuxer_addVideoTrack(JNIEnv *env, jobject thiz, jlong format_context, jint bitrate, jint width,
jint height) {
Java_sushi_hardcore_droidfs_video_1recording_MediaMuxer_addVideoTrack(JNIEnv *env, jobject thiz,
jlong format_context,
jint bitrate, jint width,
jint height,
jint orientation_hint) {
AVStream* stream = avformat_new_stream((AVFormatContext *) format_context, NULL);
stream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
stream->codecpar->codec_id = AV_CODEC_ID_H264;
stream->codecpar->bit_rate = bitrate;
stream->codecpar->width = width;
stream->codecpar->height = height;
uint8_t* matrix = av_stream_new_side_data(stream, AV_PKT_DATA_DISPLAYMATRIX, sizeof(int32_t) * 9);
av_display_rotation_set((int32_t *) matrix, orientation_hint);
return stream->index;
}

2
build.gradle

@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath 'com.android.tools.build:gradle:7.0.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Loading…
Cancel
Save