Audio ffmpeg android从数字容器格式提取音频

Audio ffmpeg android从数字容器格式提取音频,audio,android-ndk,ffmpeg,extract,Audio,Android Ndk,Ffmpeg,Extract,我让程序从数字容器格式DCF中提取音频。 我想获得一个经过编码的音频文件。 所以,我认为我可以只向文件写入音频流数据包 有些DCF文件工作正常,但有些文件不工作 拜托,你能帮我找个问题吗 // src -- is DCF // dest -- is going to write file int ExtractAudio(const char src[], const char dest[]) { av_register_all(); avcodec_register_all(

我让程序从数字容器格式DCF中提取音频。 我想获得一个经过编码的音频文件。 所以,我认为我可以只向文件写入音频流数据包

有些DCF文件工作正常,但有些文件不工作

拜托,你能帮我找个问题吗

// src  -- is DCF
// dest -- is going to write file
int ExtractAudio(const char src[], const char dest[]) {
    av_register_all();
    avcodec_register_all();

    __android_log_print(ANDROID_LOG_DEBUG, "test", "dest : %s", dest);
    __android_log_print(ANDROID_LOG_DEBUG, "test", "src : %s", src);

    //파일을 열고 컨텍스트에 파일 형식을 불러온다.
    AVFormatContext * pInputFormatContext = NULL;
    int err = avformat_open_input(&pInputFormatContext, src, NULL, NULL);
    if (err < 0) {
        __android_log_print( ANDROID_LOG_DEBUG, "test",
            "avformat_open_input Err! %d",err);
        return 0;
    }

    FILE *destFile = fopen(dest, "wb");
    FILE *srcFile = fopen(src, "rb");
    if (destFile == NULL || srcFile == NULL) {
        __android_log_print(ANDROID_LOG_DEBUG, "test", "fopen Err!");
        __android_log_print(ANDROID_LOG_DEBUG, "test", "fopen Err!");
        return 0;
    }

    fseek(srcFile, 0, SEEK_END);
    DCFSize = ftell(srcFile);
    fseek(srcFile, 0, SEEK_SET);

    int nAudioStreamIdx = -1;
    AVCodec *pAudioCodec = NULL;

    err = av_find_stream_info(pInputFormatContext);
    if (err < 0) {
        __android_log_print(ANDROID_LOG_DEBUG, "test",
                "av_find_stream_info Err!");
        __android_log_print(ANDROID_LOG_DEBUG, "test",
                "av_find_stream_info Err!");
        return 0;
    }

    err = av_find_best_stream(pInputFormatContext, AVMEDIA_TYPE_AUDIO, -1, -1,
            &pAudioCodec, NULL);

    //에러처리 임시
    if (err < 0) {
        nAudioStreamIdx = 1;
        if (err == AVERROR_STREAM_NOT_FOUND)
            __android_log_print(ANDROID_LOG_DEBUG, "test",
                    "AVERROR_STREAM_NOT_FOUND");
        if (err == AVERROR_DECODER_NOT_FOUND)
            __android_log_print(ANDROID_LOG_DEBUG, "test",
                    "AVERROR_DECODER_NOT_FOUND ");
    } else
        nAudioStreamIdx = err;

    AVPacket Packet;
    av_init_packet(&Packet);

    while (av_read_frame(pInputFormatContext, &Packet) >= 0) {
        if (Packet.stream_index == nAudioStreamIdx)
            {
            fwrite(Packet.data, 1, Packet.size, destFile);
            PaketPos = Packet.pos;
            //__android_log_print(ANDROID_LOG_DEBUG, "test","Extract Progress : %d",getExtractProgress());
        }
    }
    PaketPos = DCFSize;

    return 1;
}