Android MediaMuxer Audio Issue -
I am trying to use MediaMuxer to add an audio track to the video. The following code works but prevents halfway through audio video. Both video and audio files have only one track, audio and video playback speed seems fine. Audio file is longer than video, so I think this is not an issue. I've been on this for some time now can not figure it out.
Private Zero createFinalVideo () {string outputFile = ""; {File file = new file (try the environment. Gatestile store directory () + file. Separator + "last .mp4"); File.createNewFile (); OutputFile = file.getAbsolutePath (); Media Architect Video Extractor = New Media Extractor (); VideoExtractor.setDataSource (Production); MediaExtractor Audio Extractor = New Media Extractor (); Final AssetFileDescriptor afd = context.getAssets (). OpenFd ("audio.m4a"); AudioExtractor.setDataSource (afd.getFileDescriptor (), afd.getStartOffset (), afd.getLength ()); Log D. (Tag, "Video Extractor Track Calculation" + Video Actor. GatetrackCount ()); Log D. (Tag, "Audio Extractor Track Calculation" + AudioActactor.GettaCac ()); MediaMuxer muxer = New MediaMuxer (OutputFile, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4); VideoExtractor.selectTrack (0); Media Format Video Format = VideoEctractorGetTarkFormat (0); Int videotrack = muxer.addTrack (video format); AudioExtractor.selectTrack (0); MediaFormat AudioFormat = AudioActroctorGetTarkFormat (0); Int audioTrack = muxer.addTrack (audio format); Log D. (Tag, "video format" + video format.stosting ()); Log D. (Tag, "audio format" + audio format.stosting ()); Boolean saw EOS = false; Int framecount = 0; Int offset = 100; Int sample size = 256 * 1024; ByteBuffer videoBuf = BitBufer.alocket (sampleSize); ByteBuffer audioBuf = BitFufer.alocet (sampleSize); BufferINFO video buffer = new bufferInfo (); BufferInfo audio buffinfo = new bufferInfo (); Video extractor Secato (0, MediaActroctor.SEEK_TO_CLOSEST_SYNC); AudioActroctor.Secato (0, MediaActroctor.SEEK_TO_CLOSEST_SYNC); Muxer.start (); While (! Oops!) {VideoBufferInfo.offset = offset; AudioBufferInfo.offset = offset; VideoBufferInfo.size = Video Actuctor Read sample data (videbuf, offset); AudioBufferInfo.size = AudioActactor Read sample data (audiube offset); If (Video buffer Infosys & lt; 0 || AUDIO BUFFERIFF & lt; 0) {LOG D. (Tag, "input eos seen."); Seen EOS = true; VideoBufferInfo.size = 0; AudioBufferInfo.size = 0; } Other {videoBufferInfo.PresentationTimeUs = videoExtractor.getSampleTime (); VideoBufferInfo.flags = Video Extractor .getSampleFlags (); Muxer.writeSampleData (VideoTrack, VideoBuf, VideoBuferInfo); VideoExtractor.advance (); AudioBufferInfo.PresentationTimeUs = AudioActactor .getSampleTime (); AudioBufferInfo.flags = audioExtractor.getSampleFlags (); Muxer.writeSampleData (audiotrack, audiobook, audiobuferinfo); AudioExtractor.advance (); FrameCount ++; Log D. (+ "Frame ++") "Video buffer inforige. Presentation Time Use +" Flag: "+ Video buffer Info.Fags +" Size (KB) + Video buffer Infoco / 1024 ); Log D. (tag, "frame (" + framecount + ") audio presentation time usage:" + audiobuffer infra presentation time use + "flag:" + audiobuferinfo.flags + "size (kb)" + audio booster info. Size / 1024);}} Muxer.stop (); muxer.release ();} Grip (IOException E) {Log D (Tag, "mixer error 1" + ejet message ()); hold (exception e) {log d. (Tag, "mixer error 2" + e. Megas ());} return;} Media format print out is
Video format {max-input-size = 1572864, frame-rate = 28, height = 1920, Csd-0 = Java.nio.ByteArrayBuffer [condition = 0, limit = 18, capacity = 18], width = 1072, duration = 2968688, csd-1 = java.nio.biteArrayBuffer [condition = 0, limit = 8, capacity = 8], Mime = Video / AVC, IDMCMMectector = 1} audio format {more The input-size = 1572864, encoder-padding = 708, AAC profile = 2, CSD -0 = Java. NIO Batteryrebrator [condition = 0, limit = 2, capacity = 2], sample rate = 44100, duration 1 = 1 9 783401, channel-count = 2, encoder-delay = 2112, mime = audio / mp4a-ltm, idmmmactactor = 1}
< Thanks
Any guidance will be appreciated.
Comments
Post a Comment