FFmpeg的和类型的样品

FFmpeg的和类型的样品

本文介绍了FFmpeg的和类型的样品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用FFmpeg的(功能AV codec_de code_audio3),并试图通过Audiotrack重现它在Android的德codeD音频。玩的时候我听到一些咆哮。没有音乐。在论坛上获悉,随着样本的问题。问题:如何解决这个问题,如果它是与类型样本的失配相关联的? code解码:

Decoded audio using FFmpeg (function avcodec_decode_audio3) and try to reproduce it through Audiotrack in Android. When playing I hear some growling. No music. On the forums advised that the problem with the samples. Question: how to solve this problem, if it is associated with a mismatch of types of samples? Code decoding:



        while (av_read_frame(pFormatCtx, &packet)>= 0) {
            if (aCodecCtx->codec_type == AVMEDIA_TYPE_AUDIO) {
                        int data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE * 2;
                        int size=packet.size;
 int decoded = 0;
                        while(size > 0) {
                                int len = avcodec_decode_audio3(aCodecCtx, (uint16_t *) pAudioBuffer, &data_size, &packet);


                                jbyte *bytes = (*env)->GetByteArrayElements(env, array, NULL);
                                memcpy(bytes + decoded, (uint16_t *) pAudioBuffer, len);
                                (*env)->ReleaseByteArrayElements(env, array, bytes, 0);

                                (*env)->CallStaticVoidMethod(env, cls, mid, array);


                                size -= len;
                                decoded += len;
                                }
            }

     }

Java的code:

Java code:


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

         int bufSize = AudioTrack.getMinBufferSize(44100,                                AudioFormat.CHANNEL_CONFIGURATION_MONO,
                        AudioFormat.ENCODING_PCM_16BIT);
        track = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_CONFIGURATION_MONO,
                    AudioFormat.ENCODING_PCM_16BIT, bufSize, AudioTrack.MODE_STREAM);
        track.play();

            bytes = new byte[bufSize];
            int res = main(2, "/sdcard/muzika_iz_reklami_bmw_5_series_-_bmw_5_series.mp3", bytes);


            System.out.println(res);
    }
    private static void play(byte[] play) {

        track.write(play, 0, play.length);
    }

如何解决这个问题呢?附:文件本身被选中 - 标准的播放器播放。格式:MP3

How to solve this problem?P.S. The file itself is checked - the standard player plays. Format: mp3.

推荐答案

请了去codeD字节的积累与 len个计数器之后,每次调用 AV codec_de code_audio 为一个 AVPacket 。然后把它作为在Java字节数组偏移量:

Keep a counter of decoded bytes that is accumulated with len after each call to avcodec_decode_audio for a single AVPacket. Then use it as offset at the Java byte array:

int decoded = 0;
  ...
int len = avcodec_decode_audio3(aCodecCtx, (uint8_t *) pAudioBuffer, &data_size, &packet);
  ...
memcpy(bytes + decoded, (uint8_t *) pAudioBuffer, len);
  ...
size -= len;
decoded += len;

您正在改写追加的缓冲区的开始一遍又一遍吧。

You're overwriting the beginning of the buffer over and over instead of appending.

这篇关于FFmpeg的和类型的样品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 07:07