2012-03-15 5 views
0

성공적으로 컴파일했습니다. libavcodecspeex이 활성화되었습니다. 샘플 오디오를 Speex로 인코딩하기 위해 FFMPEG docs의 예제를 수정했습니다. 그러나 결과 파일은 VLC 플레이어 (Speex 디코더가 있음)로 재생할 수 없습니다.libavcodec (FFMpeg)을 사용하여 Speex를 인코딩 하시겠습니까?

팁이 있습니까?

static void audio_encode_example(const char *filename) 
{ 
    AVCodec *codec; 
    AVCodecContext *c= NULL; 
    int frame_size, i, j, out_size, outbuf_size; 
    FILE *f; 
    short *samples; 
    float t, tincr; 
    uint8_t *outbuf; 

    printf("Audio encoding\n"); 

    /* find the MP2 encoder */ 
    codec = avcodec_find_encoder(CODEC_ID_SPEEX); 
    if (!codec) { 
     fprintf(stderr, "codec not found\n"); 
     exit(1); 
    } 

    c= avcodec_alloc_context(); 

    /* put sample parameters */ 
    c->bit_rate = 64000; 
    c->sample_rate = 32000; 
    c->channels = 2; 
    c->sample_fmt=AV_SAMPLE_FMT_S16; 

    /* open it */ 
    if (avcodec_open(c, codec) < 0) { 
     fprintf(stderr, "could not open codec\n"); 
     exit(1); 
    } 

    /* the codec gives us the frame size, in samples */ 
    frame_size = c->frame_size; 
    printf("frame size %d\n",frame_size); 
    samples =(short*) malloc(frame_size * 2 * c->channels); 
    outbuf_size = 10000; 
    outbuf =(uint8_t*) malloc(outbuf_size); 

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

    /* encode a single tone sound */ 
    t = 0; 
    tincr = 2 * M_PI * 440.0/c->sample_rate; 
    for(i=0;i<200;i++) { 
     for(j=0;j<frame_size;j++) { 
      samples[2*j] = (int)(sin(t) * 10000); 
      samples[2*j+1] = samples[2*j]; 
      t += tincr; 
     } 
     /* encode the samples */ 
     out_size = avcodec_encode_audio(c, outbuf, outbuf_size, samples); 
     fwrite(outbuf, 1, out_size, f); 
    } 
    fclose(f); 
    free(outbuf); 
    free(samples); 
    avcodec_close(c); 
    av_free(c); 
} 

int main(int argc, char **argv) 
{ 

    avcodec_register_all(); 

    audio_encode_example(argv[1]); 

    return 0; 
} 

답변

1

우연히 Speex (필자는 모르겠다)는 프레임이 삽입되는 컨테이너 형식이 필요하며 어떤 종류의 헤더가 있습니까? 인코더의 출력을 가져 와서 형식 지정을 거치지 않고 파일로 덤핑하면됩니다 (libavformat).

ffmpeg 명령 줄 유틸리티를 사용하여 동일한 데이터를 Speex로 인코딩하고 결과 파일이 재생되는지 확인하십시오.

나는 어떤 정보를 www.speex.org에서보고 있는데, 데이터가 .ogg 개의 파일에 삽입 된 것 같습니다. 사용중인 플레이어가 원시 Speex 데이터를 인식하지 못할 수도 있습니다 (.ogg에 싸인 경우에만 해당).

100 % 확실한 대답은 아니지만 약간의 도움이 되었기를 바랍니다.

+0

궁금한데, 나는 CODEC_ID_MP2를 사용했다. 결과 파일에는 컨테이너가 필요하지 않았다. 나는 OGG 컨테이너를 사용하려고 시도 할 것이다. –