Compare commits

...

1 Commits

Author SHA1 Message Date
Hardcore Sushi 464349dca9
Video rotation #1 2 months ago
  1. 6
      app/src/main/java/sushi/hardcore/droidfs/video_recording/MediaMuxer.kt
  2. 1
      app/src/main/java/sushi/hardcore/droidfs/video_recording/VideoCapture.java
  3. 9
      app/src/main/native/libmux.c

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);

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

@ -68,14 +68,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;
stream->metadata = NULL;
av_dict_set_int(&stream->metadata, "rotate", orientation_hint, 0);
return stream->index;
}

Loading…
Cancel
Save