Objective c WMV转换器在FFMpeg中失败
我似乎无法让FFMpeg使用该库。每次我尝试将asf文件转换为wmv时。我在运行时遇到以下问题: [wmv1@0x81ee000]错误,切片代码为2 [wmv1@0x81ee000]收割台损坏 这是我的代码:Objective c WMV转换器在FFMpeg中失败,objective-c,ffmpeg,wmv,Objective C,Ffmpeg,Wmv,我似乎无法让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_si
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);
}
静态无效音频解码示例(常量字符*输出文件名,常量字符*文件名)
{
AVCodec*编解码器;
AVCodecContext*c=NULL;
int out_size、len、in_size;
文件*f,*outfile;
uint8_t*f;
uint8\u t inbuf[音频inbuf\u大小+FF\u输入缓冲区\u填充大小];
avpkt;
av_init_数据包(&avpkt);
printf(“音频解码”);
/*查找mpeg音频解码器*/
codec=avcodec\u find\u解码器(codec\u ID\u WMV1);
如果(!编解码器){
fprintf(stderr,“找不到编解码器”);
返回;
}
c=avcodec_alloc_context2(编解码器_类型_音频);
/*打开它*/
如果(avcodec_打开(c,codec)<0){
fprintf(stderr,“无法打开编解码器”\n);
返回;
}
exputf=malloc(AVCODEC\u MAX\u AUDIO\u FRAME\u SIZE);
f=fopen(文件名,“rb”);
如果(!f){
fprintf(stderr,“无法打开%s\n”,文件名);
返回;
}
outfile=fopen(outfilename,“wb”);
如果(!outfile){
无AVU(c);
返回;
}
/*解码到eof*/
avpkt.data=inbuf;
len=avpkt.size=fread(inbuf,1,inbuf_size,f);
NSLog(@“%d”,avpkt.size);
而(avpkt.size>0){
out_size=AVCODEC_MAX_AUDIO_FRAME_size;
len=avcodec_decode_audio2(c,(short*)突发和传出大小,inbuf,len);//avpkt.size);
NSLog(@“%d”,len);
if(len<0){
fprintf(stderr,“解码时出错\n”);
fclose(输出文件);
返回;
}
如果(输出大小>0){
/*如果一帧已解码,则将其输出*/
fwrite(突出,1,超出尺寸,超出文件);
}
avpkt.size-=len;
avpkt.data+=len;
if(avpkt.size<音频\重新填充\阈值){
/*重新填充输入缓冲区,以避免尝试解码
*不完整的框架。除此之外,还可以使用
*解析器,或通过
*libav格式*/
memmove(inbuf,avpkt.data,avpkt.size);
avpkt.data=inbuf;
len=fread(avpkt.data+avpkt.size,1,
INBUF_尺寸-平均尺寸,f);
如果(len>0)
avpkt.size+=len;
}
}
fclose(输出文件);
fclose(f);
免费(免费);
avcodec_close(c);
无AVU(c);
}
我尝试了命令行实用程序,它成功地转换了文件。任何帮助都是有益的。谢谢错误地打开了错误的文件你在代码中是在哪里写这个方法的,我不能在目标c文件上写