gpt4 book ai didi

objective-c - WMV 转换器失败 FFMpeg

转载 作者:行者123 更新时间:2023-12-04 23:31:09 25 4
gpt4 key购买 nike

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

[wmv1 @ 0x81ee000]error, slice code was 2 [wmv1 @ 0x81ee000]header damaged



这是我的代码:
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);
}

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

最佳答案

犯打开错误文件的错误

关于objective-c - WMV 转换器失败 FFMpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8071917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com