[MPlayer-cvslog] r19583 - trunk/libmpcodecs/ve_x264.c

michael subversion at mplayerhq.hu
Mon Aug 28 21:32:53 CEST 2006


Author: michael
Date: Mon Aug 28 21:32:53 2006
New Revision: 19583

Modified:
   trunk/libmpcodecs/ve_x264.c

Log:
"global header" support, this is pretty much just copy and pasted code from 
libavcodec/x264.c and libmpcodecs/ve_lavc.c, with it -ovc x264 can be used 
together with lavf to make working .psp files amongth other things
feel free to reverse, flame, ...


Modified: trunk/libmpcodecs/ve_x264.c
==============================================================================
--- trunk/libmpcodecs/ve_x264.c	(original)
+++ trunk/libmpcodecs/ve_x264.c	Mon Aug 28 21:32:53 2006
@@ -119,6 +119,7 @@
 static char *cqm4pc = NULL;
 static char *cqm8iy = NULL;
 static char *cqm8py = NULL;
+static int globalheader=0;
 
 m_option_t x264encopts_conf[] = {
     {"bitrate", &bitrate, CONF_TYPE_INT, CONF_RANGE, 0, 24000000, NULL},
@@ -204,6 +205,7 @@
     {"turbo", &turbo, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL},
     {"visualize", &visualize, CONF_TYPE_FLAG, 0, 0, 1, NULL},
     {"novisualize", &visualize, CONF_TYPE_FLAG, 0, 1, 0, NULL},
+    {"global", &globalheader, CONF_TYPE_FLAG, 0, 0, 1, NULL},
     {NULL, NULL, 0, 0, 0, 0, NULL}
 };
 
@@ -224,6 +226,20 @@
     return 0;
 }
 
+static int encode_nals(uint8_t *buf, int size, x264_nal_t *nals, int nnal){
+    uint8_t *p = buf;
+    int i;
+
+    for(i = 0; i < nnal; i++){
+        int s = x264_nal_encode(p, &size, 1, nals + i);
+        if(s < 0)
+            return -1;
+        p += s;
+    }
+
+    return p - buf;
+}
+
 static int put_image(struct vf_instance_s *vf, mp_image_t *mpi, double pts);
 static int encode_frame(struct vf_instance_s *vf, x264_picture_t *pic_in);
 
@@ -324,6 +340,7 @@
     mod->param.vui.i_sar_width = d_width*height;
     mod->param.vui.i_sar_height = d_height*width;
     mod->param.i_threads = threads;
+    if(globalheader) mod->param.b_repeat_headers = 0;
 
     if(cqm != NULL)
     {
@@ -441,6 +458,25 @@
         mp_msg(MSGT_MENCODER, MSGL_ERR, "x264_encoder_open failed.\n");
         return 0;
     }
+
+    if(globalheader){
+        uint8_t *extradata;
+        x264_nal_t *nal;
+        int extradata_size, nnal, i, s = 0;
+
+        x264_encoder_headers(mod->x264, &nal, &nnal);
+
+        /* 5 bytes NAL header + worst case escaping */
+        for(i = 0; i < nnal; i++)
+            s += 5 + nal[i].i_payload * 4 / 3;
+
+        extradata = malloc(s);
+        extradata_size = encode_nals(extradata, s, nal, nnal);
+
+        mod->mux->bih= realloc(mod->mux->bih, sizeof(BITMAPINFOHEADER) + extradata_size);
+        memcpy(mod->mux->bih + 1, extradata, extradata_size);
+        mod->mux->bih->biSize= sizeof(BITMAPINFOHEADER) + extradata_size;
+    }
     
     if (mod->param.i_bframe > 1 && mod->param.b_bframe_pyramid)
         mod->mux->decoder_delay = 2;



More information about the MPlayer-cvslog mailing list