[英]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.