2010-12-20 7 views
4

나는 ffmpeg에 익숙하지 않고 api-example.c를 사용하여 wma 파일을 디코딩하려고 시도했다. 그러나 프로그램을 실행할 때 오류 메시지가 나타납니다ffmpeg로 Wma 디코딩

"frame_len overflow". 누구든지이 오류를 수정하는 방법을 알고 있습니까?

extern "C" { 
#include <avcodec.h> 
#include "../libavcodec/avcodec.h" 
#include <avformat.h> 
} 

#include <iostream> 
#include <assert.h> 
#include <windows.h> 
#include <mmsystem.h> 
#define INBUF_SIZE 4096 
#define AUDIO_INBUF_SIZE 20480 
#define AUDIO_REFILL_THRESH 4096 

int main(int argc, char *argv[]) { 
    avcodec_init(); 
    avcodec_register_all(); 
    //avdevice_register_all(); 
    av_register_all(); 

    AVCodec *codec; 
    AVCodecContext *c= NULL; 

    AVCodec *ocodec; 
    AVCodecContext *oc= NULL; 

    int out_size, len,out_size2; 
    FILE *f, *outfile; 
    uint8_t *outbuf; 
    uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; 

    AVPacket avpkt; 
    char* outfilename="test.wma"; 
    char* filename="Beethoven's.wma"; 
    AVFormatContext *pFormatCtx; 

    WAVEFORMATEX* wfx=new WAVEFORMATEX; 

    int ret; 
    ret=av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL); 

    if(ret!=0) 
    { 
     std::cout<<"cannot open file!"<<std::endl; 
     exit(1); 
    } 

    if(av_find_stream_info(pFormatCtx)<0) 
    { 
     std::cout<<"cannot find stream!"<<std::endl; 
     exit(1); 
    } 

    int audioStream; 
    AVCodecContext *pCodecCtx; 
    // Find the first video stream 
    audioStream=-1; 
    for(int i=0; i<pFormatCtx->nb_streams; i++) 
     if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_AUDIO) 
     { 
      audioStream=i; 
      break; 
     } 
    if(audioStream==-1) 
    { 
     std::cout<<"cannot find audio!"<<std::endl; 
    } 

    // Get a pointer to the codec context for the audio stream 
    pCodecCtx=pFormatCtx->streams[audioStream]->codec; 
    av_init_packet(&avpkt); 

    printf("Audio decoding\n"); 

    /* find the suitable audio decoder */ 
    codec = avcodec_find_decoder(pCodecCtx->codec_id); 

    if (!codec) { 
     fprintf(stderr, "codec not found\n"); 
     exit(1); 
    } 

    if(codec->capabilities & CODEC_CAP_TRUNCATED) 
     pCodecCtx->flags|=CODEC_FLAG_TRUNCATED; 

    //open the codec (for decoding) 
    int test = avcodec_open(pCodecCtx, codec); 
    if (test < 0) { 
     fprintf(stderr, "could not open codec\n"); 
     exit(1); 
    } 

    //find mp3 encoder 
    ocodec = avcodec_find_encoder(CODEC_ID_MP3); 
    if (!ocodec) { 
     fprintf(stderr, "codec not found\n"); 
     exit(1); 
    } 

    //allocate context 
    oc= avcodec_alloc_context(); 
    /* put sample parameters */ 
    oc->bit_rate = 64000; 
    oc->sample_rate = 44100; 
    oc->channels = 1; 
    /* open it */ 
    if (avcodec_open(oc, ocodec) < 0) { 
     fprintf(stderr, "could not open encoding codec\n"); 
     exit(1); 
    } 

    //buffer 
    outbuf = (uint8_t*)malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); 

    //open inputfile 
    f = fopen(filename, "rb"); 
    if (!f) { 
     fprintf(stderr, "could not open %s\n", filename); 
     exit(1); 
    } 

    //open outputfile 
    outfile = fopen(outfilename, "wb"); 

    if (!outfile) { 
     av_free(c); 
     exit(1); 
    } 

    /* decode until eof */ 
    avpkt.data = inbuf; 
    avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f); 

    //while there is still data 
    while (avpkt.size > 0) { 
     std::cout<<"decoding..."<<std::endl; 
     out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; 
     //decode 
     len = avcodec_decode_audio3(pCodecCtx, (short *)outbuf, &out_size, &avpkt); 

     if (len < 0) { 
      fprintf(stderr, "Error while decoding\n"); 
      exit(1); 
     } 

     if (out_size > 0) { 
      /* if a frame has been decoded, output it */ 
      std::cout<<"1 frame decoded!"<<std::endl; 
      out_size2 = avcodec_encode_audio(oc, outbuf, out_size, (short*)outbuf); 
      fwrite(outbuf, 1, out_size2, outfile); 
     } 

     //subtract data from whatever decode function returns 

     avpkt.size -= len; 

     avpkt.data += len; 

     if (avpkt.size < AUDIO_REFILL_THRESH) { 

      /* Refill the input buffer, to avoid trying to decode 

      * incomplete frames. Instead of this, one could also use 

      * a parser, or use a proper container format through 

      * libavformat. */ 

      memmove(inbuf, avpkt.data, avpkt.size); 

      avpkt.data = inbuf; 

      len = fread(avpkt.data + avpkt.size, 1, 

         AUDIO_INBUF_SIZE - avpkt.size, f); 

      if (len > 0) 

       avpkt.size += len; 

     } 



    } 

    fclose(outfile); 

    fclose(f); 

    free(outbuf); 

    avcodec_close(c); 

    av_free(c); 



} 

나는 꽤 오랜 시간이에 붙어되었습니다

여기 내 코드입니다. 도와주세요. 누구든지 내 코드에 무슨 문제가 있는지 알고 있습니까?

감사합니다,

Izak

+0

올바른 들여 쓰기 및 공백을 사용하여 읽기 쉽도록하십시오. "frame_len overflow"는 어디에서 얻습니까? – ronag

+0

프로그램을 실행할 때 "frame_len overflow"라는 오류를 반환합니다. – Izak

+0

주로 WMA를 해독하거나 ffmpeg 사용 방법을 배우고 싶습니까? WMA의 경우 Windows에서 실행중인 ffmpeg 대신 좋은 대안이 있습니다. –

답변

0

사용 디버그 메시지는 실패 지점을 결정합니다. 동일한 버퍼 및 해당 버퍼 크기를 사용하고 있기 때문에 인코딩하는 동안이 오류가 발생한다고 생각합니다.