comparison libx264.c @ 10233:f397ad0fa67d libavcodec

Add support for new x264 API.
author darkshikari
date Wed, 23 Sep 2009 09:03:26 +0000
parents 38cfe222e1a4
children 9e43db5ad7ef
comparison
equal deleted inserted replaced
10232:1792a26c0bbb 10233:f397ad0fa67d
50 50
51 av_vlog(p, level_map[level], fmt, args); 51 av_vlog(p, level_map[level], fmt, args);
52 } 52 }
53 53
54 54
55 static int 55 static int encode_nals(AVCodecContext *ctx, uint8_t *buf, int size, x264_nal_t *nals, int nnal, int skip_sei)
56 encode_nals(AVCodecContext *ctx, uint8_t *buf, int size, x264_nal_t *nals, int nnal, int skip_sei)
57 { 56 {
58 X264Context *x4 = ctx->priv_data; 57 X264Context *x4 = ctx->priv_data;
59 uint8_t *p = buf; 58 uint8_t *p = buf;
60 int i, s; 59 int i;
61 60
62 /* Write the SEI as part of the first frame. */ 61 /* Write the SEI as part of the first frame. */
63 if(x4->sei_size > 0 && nnal > 0) 62 if(x4->sei_size > 0 && nnal > 0){
64 {
65 memcpy(p, x4->sei, x4->sei_size); 63 memcpy(p, x4->sei, x4->sei_size);
66 p += x4->sei_size; 64 p += x4->sei_size;
67 x4->sei_size = 0; 65 x4->sei_size = 0;
68 } 66 }
69 67
70 for(i = 0; i < nnal; i++){ 68 for(i = 0; i < nnal; i++){
71 /* Don't put the SEI in extradata. */ 69 /* Don't put the SEI in extradata. */
72 if(skip_sei && nals[i].i_type == NAL_SEI) 70 if(skip_sei && nals[i].i_type == NAL_SEI){
73 { 71 x4->sei_size = nals[i].i_payload;
74 x4->sei = av_malloc( 5 + nals[i].i_payload * 4 / 3 ); 72 x4->sei = av_malloc(x4->sei_size);
75 if(x264_nal_encode(x4->sei, &x4->sei_size, 1, nals + i) < 0) 73 memcpy(x4->sei, nals[i].p_payload, nals[i].i_payload);
76 return -1;
77 continue; 74 continue;
78 } 75 }
79 s = x264_nal_encode(p, &size, 1, nals + i); 76 memcpy(p, nals[i].p_payload, nals[i].i_payload);
80 if(s < 0) 77 p += nals[i].i_payload;
81 return -1;
82 p += s;
83 } 78 }
84 79
85 return p - buf; 80 return p - buf;
86 } 81 }
87 82
95 x264_picture_t pic_out; 90 x264_picture_t pic_out;
96 91
97 x4->pic.img.i_csp = X264_CSP_I420; 92 x4->pic.img.i_csp = X264_CSP_I420;
98 x4->pic.img.i_plane = 3; 93 x4->pic.img.i_plane = 3;
99 94
100 if (frame) { 95 if(frame){
101 for(i = 0; i < 3; i++){ 96 for(i = 0; i < 3; i++){
102 x4->pic.img.plane[i] = frame->data[i]; 97 x4->pic.img.plane[i] = frame->data[i];
103 x4->pic.img.i_stride[i] = frame->linesize[i]; 98 x4->pic.img.i_stride[i] = frame->linesize[i];
104 } 99 }
105 100
106 x4->pic.i_pts = frame->pts; 101 x4->pic.i_pts = frame->pts;
107 x4->pic.i_type = X264_TYPE_AUTO; 102 x4->pic.i_type = X264_TYPE_AUTO;
108 } 103 }
109 104
110 if(x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, 105 if(x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
111 &pic_out))
112 return -1; 106 return -1;
113 107
114 bufsize = encode_nals(ctx, buf, bufsize, nal, nnal, 0); 108 bufsize = encode_nals(ctx, buf, bufsize, nal, nnal, 0);
115 if(bufsize < 0) 109 if(bufsize < 0)
116 return -1; 110 return -1;
294 288
295 avctx->coded_frame = &x4->out_pic; 289 avctx->coded_frame = &x4->out_pic;
296 290
297 if(avctx->flags & CODEC_FLAG_GLOBAL_HEADER){ 291 if(avctx->flags & CODEC_FLAG_GLOBAL_HEADER){
298 x264_nal_t *nal; 292 x264_nal_t *nal;
299 int nnal, i, s = 0; 293 int nnal, s;
300 294
301 x264_encoder_headers(x4->enc, &nal, &nnal); 295 s = x264_encoder_headers(x4->enc, &nal, &nnal);
302
303 /* 5 bytes NAL header + worst case escaping */
304 for(i = 0; i < nnal; i++)
305 s += 5 + nal[i].i_payload * 4 / 3;
306 296
307 avctx->extradata = av_malloc(s); 297 avctx->extradata = av_malloc(s);
308 avctx->extradata_size = encode_nals(avctx, avctx->extradata, s, nal, nnal, 1); 298 avctx->extradata_size = encode_nals(avctx, avctx->extradata, s, nal, nnal, 1);
309 } 299 }
310 300