0

我似乎无法让 FFMpeg 使用该库。每次我尝试将 asf 文件转换为 wmv。我在运行时遇到以下问题:

[wmv1 @ 0x81ee000]错误,分片代码为 2 [wmv1 @ 0x81ee000]标头损坏

这是我的代码:

static void audio_decode_example(const char *outfilename, const char *filename)
{
    AVCodec *codec;
    AVCodecContext *c= NULL;
    int out_size, len, in_size;
    FILE *f, *outfile;
    uint8_t *outbuf;
    uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
    AVPacket avpkt;

    av_init_packet(&avpkt);

    printf("Audio decoding\n");

    /* find the mpeg audio decoder */
    codec = avcodec_find_decoder(CODEC_ID_WMV1);
    if (!codec) {
        fprintf(stderr, "codec not found\n");
        return;
    }

    c= avcodec_alloc_context2(CODEC_TYPE_AUDIO);

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

    outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
    f = fopen(filename, "rb");
    if (!f) {
        fprintf(stderr, "could not open %s\n", filename);
        return;
    }
    outfile = fopen(outfilename, "wb");
    if (!outfile) {
        av_free(c);
        return;
    }

    /* decode until eof */
    avpkt.data = inbuf;
    len = avpkt.size = fread(inbuf, 1, INBUF_SIZE, f);
    NSLog(@"%d", avpkt.size); 

    while (avpkt.size > 0) {
        out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
    len = avcodec_decode_audio2(c, (short *)outbuf, &out_size, inbuf,len);// avpkt.size);
    NSLog(@"%d", len);
    if (len < 0) {
        fprintf(stderr, "Error while decoding\n");
        fclose(outfile);
        return;
    }
    if (out_size > 0) {
        /* if a frame has been decoded, output it */
        fwrite(outbuf, 1, out_size, outfile);
    }
    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,
                    INBUF_SIZE - avpkt.size, f);
        if (len > 0)
            avpkt.size += len;
    }
}

fclose(outfile);
fclose(f);
free(outbuf);
avcodec_close(c);
av_free(c);
}

我已经尝试了命令行实用程序,它成功地转换了文件。任何帮助都会有所帮助。谢谢

4

1 回答 1

0

犯打开错误文件的错误

于 2011-11-15T18:14:26.100 回答