some camera orientation stuff, maybe toss?
This commit is contained in:
parent
e82f068b21
commit
fb42545890
@ -12,7 +12,6 @@ import com.mrousavy.camera.types.Orientation
|
|||||||
import com.mrousavy.camera.types.RecordVideoOptions
|
import com.mrousavy.camera.types.RecordVideoOptions
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
import kotlinx.coroutines.*
|
|
||||||
|
|
||||||
class ChunkedRecordingManager(private val encoder: MediaCodec, private val outputDirectory: File, private val orientationHint: Int, private val iFrameInterval: Int) :
|
class ChunkedRecordingManager(private val encoder: MediaCodec, private val outputDirectory: File, private val orientationHint: Int, private val iFrameInterval: Int) :
|
||||||
MediaCodec.Callback() {
|
MediaCodec.Callback() {
|
||||||
@ -23,22 +22,20 @@ class ChunkedRecordingManager(private val encoder: MediaCodec, private val outpu
|
|||||||
size: Size,
|
size: Size,
|
||||||
enableAudio: Boolean,
|
enableAudio: Boolean,
|
||||||
fps: Int? = null,
|
fps: Int? = null,
|
||||||
orientation: Orientation,
|
cameraOrientation: Orientation,
|
||||||
bitRate: Int,
|
bitRate: Int,
|
||||||
options: RecordVideoOptions,
|
options: RecordVideoOptions,
|
||||||
outputDirectory: File,
|
outputDirectory: File,
|
||||||
iFrameInterval: Int = 3
|
iFrameInterval: Int = 3
|
||||||
): ChunkedRecordingManager {
|
): ChunkedRecordingManager {
|
||||||
val mimeType = options.videoCodec.toMimeType()
|
val mimeType = options.videoCodec.toMimeType()
|
||||||
var width = size.width
|
val orientationDegrees = cameraOrientation.toDegrees()
|
||||||
var height = size.height
|
val (width, height) = if (cameraOrientation.isLandscape()) {
|
||||||
|
size.height to size.width
|
||||||
val orientationDegrees = orientation.toDegrees()
|
} else {
|
||||||
|
size.width to size.height
|
||||||
if (orientationDegrees == 90 || orientationDegrees == 270) {
|
|
||||||
width = size.height
|
|
||||||
height = size.width
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val format = MediaFormat.createVideoFormat(mimeType, width, height)
|
val format = MediaFormat.createVideoFormat(mimeType, width, height)
|
||||||
|
|
||||||
val codec = MediaCodec.createEncoderByType(mimeType)
|
val codec = MediaCodec.createEncoderByType(mimeType)
|
||||||
@ -56,11 +53,11 @@ class ChunkedRecordingManager(private val encoder: MediaCodec, private val outpu
|
|||||||
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, iFrameInterval)
|
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, iFrameInterval)
|
||||||
format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate)
|
format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate)
|
||||||
|
|
||||||
Log.i(TAG, "Video Format: $format")
|
Log.i(TAG, "Video Format: $format, orientation $cameraOrientation")
|
||||||
// Create a MediaCodec encoder, and configure it with our format. Get a Surface
|
// Create a MediaCodec encoder, and configure it with our format. Get a Surface
|
||||||
// we can use for input and wrap it with a class that handles the EGL work.
|
// we can use for input and wrap it with a class that handles the EGL work.
|
||||||
codec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE)
|
codec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE)
|
||||||
return ChunkedRecordingManager(codec, outputDirectory, orientationDegrees, iFrameInterval)
|
return ChunkedRecordingManager(codec, outputDirectory, 0, iFrameInterval)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ class RecordingSession(
|
|||||||
private val enableAudio: Boolean,
|
private val enableAudio: Boolean,
|
||||||
private val fps: Int? = null,
|
private val fps: Int? = null,
|
||||||
private val hdr: Boolean = false,
|
private val hdr: Boolean = false,
|
||||||
private val orientation: Orientation,
|
private val cameraOrientation: Orientation,
|
||||||
private val options: RecordVideoOptions,
|
private val options: RecordVideoOptions,
|
||||||
private val callback: (video: Video) -> Unit,
|
private val callback: (video: Video) -> Unit,
|
||||||
private val onError: (error: CameraError) -> Unit
|
private val onError: (error: CameraError) -> Unit
|
||||||
@ -48,7 +48,7 @@ class RecordingSession(
|
|||||||
size,
|
size,
|
||||||
enableAudio,
|
enableAudio,
|
||||||
fps,
|
fps,
|
||||||
orientation,
|
cameraOrientation,
|
||||||
bitRate,
|
bitRate,
|
||||||
options,
|
options,
|
||||||
outputPath
|
outputPath
|
||||||
@ -124,7 +124,7 @@ class RecordingSession(
|
|||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
val audio = if (enableAudio) "with audio" else "without audio"
|
val audio = if (enableAudio) "with audio" else "without audio"
|
||||||
return "${size.width} x ${size.height} @ $fps FPS ${options.videoCodec} ${options.fileType} " +
|
return "${size.width} x ${size.height} @ $fps FPS ${options.videoCodec} ${options.fileType} " +
|
||||||
"$orientation ${bitRate / 1_000_000.0} Mbps RecordingSession ($audio)"
|
"$cameraOrientation ${bitRate / 1_000_000.0} Mbps RecordingSession ($audio)"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onFrame() {
|
fun onFrame() {
|
||||||
|
Loading…
Reference in New Issue
Block a user