简体   繁体   English

在iOS中使用FFMPEG进行H.264编码时找不到编解码器

[英]Codec not found while H.264 encoding using FFMPEG in iOS

I am trying to encode video in h.264 format using FFMpeg in iOS. 我正在尝试在iOS中使用FFMpeg将视频编码为h.264格式。 Actually I am receiving sample buffer from iPhone Camera and then converting it AVFrame and further from AVFrame to H.264 video. 实际上,我是从iPhone相机接收样本缓冲区,然后将其转换为AVFrame,再从AVFrame转换为H.264视频。 But while h.264 encoding if I use : 但是,如果我使用h.264编码,则:

codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);

Then codec is found but if I use: 然后找到编解码器,但如果我使用:

codec = avcodec_find_encoder(CODEC_ID_H264);

Then codec is nil means codec not found. 然后编解码器为nil表示找不到编解码器。 Full code is as below: 完整代码如下:

static void encode(AVFrame *picture)
 {
     AVCodec *codec;
     AVCodecContext *c= NULL;
     int i, out_size, size,  outbuf_size;
     uint8_t *outbuf, *picture_buf;

     printf("Video encoding\n");

     /* find the mpeg1 video encoder */

     //avcodec_init() ; // Also tried this but giving warning and not worked
     avcodec_register_all();

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

     c= avcodec_alloc_context();
     picture= avcodec_alloc_frame();

     /* put sample parameters */
     c->bit_rate = 400000;
     /* resolution must be a multiple of two */
     c->width  = 352;
     c->height = 288;
     /* frames per second */
     c->time_base= (AVRational){1,25};
     c->gop_size = 10; /* emit one intra frame every ten frames */
     c->max_b_frames=1;
     c->pix_fmt = PIX_FMT_YUV420P;

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

         /* alloc image and output buffer */
     outbuf_size = 100000;
     outbuf = malloc(outbuf_size);
     size = c->width * c->height;
     picture_buf = malloc((size * 3) / 2); /* size for YUV 420 */

     out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);

     NSLog(@"NSdada===%@",[NSData dataWithBytes:(const void *)outbuf length:out_size]);

     free(picture_buf);
     free(outbuf);

     avcodec_close(c);
     av_free(c);
     av_free(picture);
     printf("\n");
 }

Your ffmpeg probably was compiled without libx264 support. 您的ffmpeg可能是在没有libx264支持的情况下编译的。 So it really can't find encoder for H.264 as there are no other H.264 encoders in ffmpeg afaik. 因此它真的找不到H.264编码器,因为ffmpeg afaik中没有其他H.264编码器。

For one thing, ffmpeg and x264 are licensed under the LGPL and GPL, so you would need to address license issues before you could include that code in your iPhone app. 一方面,ffmpeg和x264是根据LGPL和GPL许可的,因此您需要解决许可问题,然后才能在iPhone应用程序中包含该代码。 Under iOS, you would want to use the hardware h.264 encoder already supplied with the device. 在iOS下,您将要使用设备随附的硬件h.264编码器。 The AVAsset API is used to decode from and encode to h.264 in an iOS app. AVAsset API用于在iOS应用中对h.264进行解码和编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IOS6上未显示h.264流 - h.264 stream not displayed on IOS6 ffmpeg转换命令输出到iPad的h.264 - ffmpeg conversion command to output to h.264 for iPad 如何以编程方式使用 ffmpeg 解码 H.264 HL? - How to decode H.264 HL with ffmpeg programically? 直接在iPhone上编码H.264视频(或类似图像)? - encoding H.264 video (or similar) on the iPhone directly? iPhone 摄像头使用 AVCaptureSession 拍摄视频并使用 ffmpeg CMSampleBufferRef 更改 h.264 格式是问题所在。 请指教 - iPhone camera shooting video using the AVCaptureSession and using ffmpeg CMSampleBufferRef a change in h.264 format is the issue. please advice 硬件加速h.264解码到iOS中的纹理,叠加或类似 - Hardware accelerated h.264 decoding to texture, overlay or similar in iOS 在Android和IOS上加载了什么h.264格式? - What h.264 format loads on android AND IOS? 是否可以在可可或iPhone中将视频编码从H.263转换为H.264 - Is it possible to convert video encoding to H.264 from H.263 in cocoa or iPhone 无法使用AMR窄带H.264编码播放来自.net服务器的文件 - can't play file from .net server with AMR narrowband H.264 encoding 如何使用ffmpeg在ios中解码和编码h264实时流数据? - How to decode and encode the h264 live streaming data in ios using ffmpeg?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM