forked from hardcoresushi/DroidFS
Fix recorded video rotation
This commit is contained in:
parent
dc89c02b9f
commit
497c22edc1
4
app/proguard-rules.pro
vendored
4
app/proguard-rules.pro
vendored
@ -25,3 +25,7 @@
|
|||||||
-keepclassmembers class sushi.hardcore.droidfs.explorers.ExplorerElement {
|
-keepclassmembers class sushi.hardcore.droidfs.explorers.ExplorerElement {
|
||||||
static sushi.hardcore.droidfs.explorers.ExplorerElement new(...);
|
static sushi.hardcore.droidfs.explorers.ExplorerElement new(...);
|
||||||
}
|
}
|
||||||
|
-keepclassmembers class sushi.hardcore.droidfs.video_recording.MediaMuxer {
|
||||||
|
void writePacket(byte[]);
|
||||||
|
void seek(long);
|
||||||
|
}
|
@ -6,7 +6,7 @@ import java.nio.ByteBuffer
|
|||||||
|
|
||||||
class MediaMuxer(val writer: SeekableWriter) {
|
class MediaMuxer(val writer: SeekableWriter) {
|
||||||
external fun allocContext(): Long
|
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 addAudioTrack(formatContext: Long, bitrate: Int, sampleRate: Int, channelCount: Int): Int
|
||||||
external fun writeHeaders(formatContext: Long): Int
|
external fun writeHeaders(formatContext: Long): Int
|
||||||
external fun writePacket(formatContext: Long, buffer: ByteArray, pts: Long, streamIndex: Int, isKeyFrame: Boolean)
|
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 formatContext: Long?
|
||||||
|
|
||||||
|
var orientationHint = 0
|
||||||
var realVideoTrackIndex: Int? = null
|
var realVideoTrackIndex: Int? = null
|
||||||
var audioFrameSize: Int? = null
|
var audioFrameSize: Int? = null
|
||||||
var firstPts: Long? = null
|
var firstPts: Long? = null
|
||||||
@ -63,7 +64,8 @@ class MediaMuxer(val writer: SeekableWriter) {
|
|||||||
formatContext!!,
|
formatContext!!,
|
||||||
bitrate,
|
bitrate,
|
||||||
format.getInteger("width"),
|
format.getInteger("width"),
|
||||||
format.getInteger("height")
|
format.getInteger("height"),
|
||||||
|
orientationHint
|
||||||
)
|
)
|
||||||
VIDEO_TRACK_INDEX
|
VIDEO_TRACK_INDEX
|
||||||
}
|
}
|
||||||
|
@ -464,6 +464,7 @@ public final class VideoCapture extends UseCase {
|
|||||||
|
|
||||||
synchronized (mMuxerLock) {
|
synchronized (mMuxerLock) {
|
||||||
mMuxer = new MediaMuxer(outputFileOptions.mWriter);
|
mMuxer = new MediaMuxer(outputFileOptions.mWriter);
|
||||||
|
mMuxer.setOrientationHint(getRelativeRotation(attachedCamera));
|
||||||
}
|
}
|
||||||
|
|
||||||
mEndOfVideoStreamSignal.set(false);
|
mEndOfVideoStreamSignal.set(false);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
#include <libavcodec/avcodec.h>
|
#include <libavcodec/avcodec.h>
|
||||||
#include <libavutil/channel_layout.h>
|
#include <libavutil/channel_layout.h>
|
||||||
|
#include <libavutil/display.h>
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
const size_t BUFF_SIZE = 4096;
|
const size_t BUFF_SIZE = 4096;
|
||||||
@ -68,14 +69,19 @@ Java_sushi_hardcore_droidfs_video_1recording_MediaMuxer_addAudioTrack(JNIEnv *en
|
|||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL
|
JNIEXPORT jint JNICALL
|
||||||
Java_sushi_hardcore_droidfs_video_1recording_MediaMuxer_addVideoTrack(JNIEnv *env, jobject thiz, jlong format_context, jint bitrate, jint width,
|
Java_sushi_hardcore_droidfs_video_1recording_MediaMuxer_addVideoTrack(JNIEnv *env, jobject thiz,
|
||||||
jint height) {
|
jlong format_context,
|
||||||
|
jint bitrate, jint width,
|
||||||
|
jint height,
|
||||||
|
jint orientation_hint) {
|
||||||
AVStream* stream = avformat_new_stream((AVFormatContext *) format_context, NULL);
|
AVStream* stream = avformat_new_stream((AVFormatContext *) format_context, NULL);
|
||||||
stream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
stream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
||||||
stream->codecpar->codec_id = AV_CODEC_ID_H264;
|
stream->codecpar->codec_id = AV_CODEC_ID_H264;
|
||||||
stream->codecpar->bit_rate = bitrate;
|
stream->codecpar->bit_rate = bitrate;
|
||||||
stream->codecpar->width = width;
|
stream->codecpar->width = width;
|
||||||
stream->codecpar->height = height;
|
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;
|
return stream->index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ buildscript {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
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"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user