-
Notifications
You must be signed in to change notification settings - Fork 89
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
passing bitrate while muxing audio video ( replacing audio of video with new audio ) #206
Comments
When creating a |
Can you please help where I can pass bitrate in the below method? private fun videoAudioCompress() {
|
To replace an audio track and transcode a video track you have to form a list of two
Both will need to know which track to take (index) from the source file and which track to put it to in target file. Here is what it should look like: // common target
val mediaTarget = MediaMuxerMediaTarget(outputFilePath, 2, 0, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4)
val videoMediaSource = MediaExtractorMediaSource(context, videoSourceUri)
val audioMediaSource = MediaExtractorMediaSource(context, audioSourceUri)
// video track config
val targetVideoFormat = MediaFormat.createVideoFormat("video/avc", 1280, 720) // assuming 720p landscape video
.apply{
setInteger(MediaFormat.KEY_BIT_RATE, 5_000_000)
setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 3)
setInteger(MediaFormat.KEY_FRAME_RATE, 30)
setInteger(KEY_ROTATION, 0)
}
// video track transform
val videoTrackTransform = TrackTransform.Builder(videoMediaSource, 0, mediaTarget) // assuming that video track index in source file is 0
.setTargetTrack(0)
.setDecoder(MediaCodecDecoder())
.setEncoder(MediaCodecEncoder())
.setRenderer(GlVideoRenderer())
.setTargetFormat(targetVideoFormat)
.build()
// audio track transform
val audioTrackTransform = TrackTransform.Builder(audioMediaSource, 0, mediaTarget) // assuming that audio track index in source file is 0
.setTargetTrack(1)
.setTargetFormat(null)
.build()
mediaTransformer.transform(
UUID.randomUUID.toString(),
mutableListOf(videoTrackTransform, audioTrackTransform),
listener,
MediaTransformer. GRANULARITY_DEFAULT) Feel free to make modifications. Let me know how it works out. |
we are mixing audio and video with litr and replacing the existing audio with the new audio but the video size is very large and we want to compress the size of the video. How can we pass the video bitrate during track mixing? You already have a demo for that please help.
The text was updated successfully, but these errors were encountered: