mediacodec

MediaCodec编码 音频pts设置

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 02:19:51
每一帧音频pcm录音,要进行mediacodec编码时,都需要为此pcm设置pts,在放入编码的input队列中。对于视频的pts来说,编码h264,一帧原始视频yuv420格式编码出的就是一帧h264,所以视频的pts可以直接取当前的时间戳就可以。但是对于音频来讲,一帧pcm数据,会编码出多帧的aac,mediacodec会根据送入编码器时设置的yuv420的pts,为每帧编码出的h264打一个pts。 音频的pts设置,就需要小心了。 首先,根据AudioRecord录音器配置的参数,根据采样率,声道数,采样位,和AudioRecord设置的输出buffer的大小,计算pts。 如下: buffer_duration_us = 1000000 * ((double) mAudioBufferSize / mAudioChanelCount / 2 / mAudioSampleRate); buffer_duration_us:每一帧pcm,需要叠加的时间间隔。 pts计算 pts = (long) (firstPresentationTimeUs + mCount * buffer_duration_us); if (getPTSUs() - pts > 300000) { firstPresentationTimeUs += getPTSUs() - pts; pts =

Fastest way to draw a MediaCodec-decoded video frame to screen?

风格不统一 提交于 2019-12-09 11:46:58
问题 I'm looking for the fastest way to take an image frame received from the MediaCodec decoder and draw it to the Android device screen. The important constraints and explanations are: Cannot use MediaPlayer. No intermediate app allowed. Must draw output frames from the MediaCodec decoder to the screen as quickly as possible (minimize latency). The available decoder output formats are as follows: ColorFormat[0] 0x00000013 COLOR_FormatYUV420Planar ColorFormat[1] 0x00000015 COLOR

IllegalStateException at MediaCodec.dequeInputBuffer / dequeOutputBuffer

孤人 提交于 2019-12-09 05:23:14
问题 I am trying to convert a PNG file to a one slice video clip, so to just to make a start-up over a project. What I had code to make it happen is :- private boolean MediaConversion() { MediaCodec codec = MediaCodec.createEncoderByType(MIMETYPE); MediaFormat mediaFormat = null; if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)){ mediaFormat = MediaFormat.createVideoFormat(MIMETYPE, 1280 , 720); } else { mediaFormat = MediaFormat.createVideoFormat(MIMETYPE, 720, 480); } mediaFormat

How to record video and audio with MediaCodec and MediaMuxer

自古美人都是妖i 提交于 2019-12-08 22:03:36
问题 I am able to record(encode) video with the help of MediaCodec and MediaMuxer. Next, I need to work on audio part and mux audio with video with help of MediaCodec and MediaMuxer. I am facing two problems: How to encode audio with MediaCodec. Do I need to encode audio and video in separate threads? How can I pass audio and video data to MediaMuxer (as writeSampleData() method takes only one type of data at a time)? I referred to MediaMuxerTest but it is using MediaExtractor. I need to use

Slow H264 1080P@60fps Decoding on Android Lollipop 5.0.2

冷暖自知 提交于 2019-12-08 06:38:25
问题 I'm developing a JAVA RTP Streaming App for a company project, which should be capable of joining the Multicast Server and receive the RTP Packets.Later I use the H264 Depacketizer to recreate the a complete frame from the NAL FU (Keep append the data until End Bit & Marker Bit set ) I want to decode and display a raw h264 video byte stream in Android and therefore I'm currently using the MediaCodec classes with Hardware Decoder configured. The Application is Up and running for the Jeallybean

Corrupted decoding of a video using MediaCodec in Android 5+

笑着哭i 提交于 2019-12-08 05:40:08
问题 Simply trying to decode frames from videos. While working with Android 4+ (<5), it worked just fine. I'm using parts of the example that can be found here: http://bigflake.com/mediacodec/ "ExtractMpegFramesTest.java (requires 4.1, API 16)" The problem is - it extracts a frame, but the result Bitmap is as can be seen here (Saved an image right after decoding it): The real video of course has "real" frames, and not "stretched" 1 column. I've saved this image right after the code line: bmp

ExtractMpegFramesTest having issue with video recorded in portrait mode in android

让人想犯罪 __ 提交于 2019-12-08 04:50:48
问题 I am following ExtractMpegFramesTest post to extract PNG frames from video. This works fine with videos that are recorded in landscape mode but doesn't work with videos that are recorded in portrait mode. Does anybody know how to generate PNG frames from portrait video using solution provided in above link ? I have tested this with 720p and 1080p videos. Couple of things i observed is, MediaExtractor gives width and height 1280 and 720 of 720p video regardless of orientation. this should be

Orientation Issue while video recording in Portrait Mode android grafika

杀马特。学长 韩版系。学妹 提交于 2019-12-07 21:48:41
问题 I set the device Orientation Landscape mode then it saves the video perfectly. if I capture a video with both sides. But I set the device orientation Portrait Mode this work weird. For Example: Below Screenshot while i Recording video : But when i save the video and see in MXPlayer then it's look like this: I use below code : Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); if (display.getRotation() == Surface.ROTATION_0) { mCamera

Illegal Exception on MediaCodec.configure

与世无争的帅哥 提交于 2019-12-07 19:51:31
问题 I am trying to learn to encode a mp4 or any sort of video file using the Camera's onPreviewFrame call back. Currently, I am trying the example codes from this post Encoding H.264 from camera with Android MediaCodec Unfortunately, I am keep getting an IllegalException on the mediaCodec.configure(mediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE); From another post IllegalStateException when MediaCodec.configure Android, I notice that are some mandatory values I have to set for the

Android decode mp3 with MediaCodec. not use MediaExtractor

社会主义新天地 提交于 2019-12-07 18:23:19
问题 I want to decode the mp3 using the MediaCodec. However, I do not want to use the MediaExtractor. Because it is because I want to get the meta data from mp3. icy (Shoutcast) stream are also taken into consideration. I tried writing the code to decode the mp3 files from FileInputStream by improving the sample of MediaExtractor. However decode caused the error is not possible. package com.test; import android.app.Activity; import android.media.AudioFormat; import android.media.AudioManager;