Hi All,

I wrote that I need those values in my algo. I wrote patch, but I'm not
sure that is correct. Especially about place, because dst frame referenced
before. And i think I get memory leak.

It will be very nice if u can help me with it.


diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index c4ce278..fd69bc6 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1675,13 +1675,40 @@ static int get_consumed_bytes(int pos, int buf_size)
     return pos;
 }

-static int output_frame(H264Context *h, AVFrame *dst, AVFrame *src)
+static int output_frame(H264Context *h, AVFrame *dst, H264Picture *src)
 {
     int i;
-    int ret = av_frame_ref(dst, src);
+ int ret = av_frame_ref(dst, &src->f);
     if (ret < 0)
         return ret;

+ if (src->mb_type_buf && src->mb_type_buf->data) {
+ AVFrameSideData *mb_type_sd = NULL;
+
+ mb_type_sd = av_frame_new_side_data(dst, AV_FRAME_DATA_MB_TYPE,
src->mb_type_buf->size);
+
+ if (mb_type_sd) {
+ memcpy(mb_type_sd->data, src->mb_type_buf->data, src->mb_type_buf->size);
+ }
+ }
+
+    if (src->motion_val_buf[0] && src->motion_val_buf[0]->data &&
+        src->motion_val_buf[1] && src->motion_val_buf[1]->data) {
+ int size = 0;
+ AVFrameSideData *motion_val_sd = NULL;
+
+ size = src->motion_val_buf[0]->size;
+ motion_val_sd = av_frame_new_side_data(dst, AV_FRAME_DATA_MOTION_VAL,
size * 2);
+
+ if (motion_val_sd) {
+ for (i = 0; i < 2; ++i) {
+    uint8_t *s = src->motion_val_buf[i]->data;
+    uint8_t *d = &(motion_val_sd->data[i * size]);
+ memcpy(d, s, size);
+ }
+ }
+ }
+
     if (!h->sps.crop)
         return 0;

@@ -1735,7 +1762,7 @@ out:
             h->delayed_pic[i] = h->delayed_pic[i + 1];

         if (out) {
-            ret = output_frame(h, pict, &out->f);
+            ret = output_frame(h, pict, out);
             if (ret < 0)
                 return ret;
             *got_frame = 1;
@@ -1773,7 +1800,7 @@ out:
             if (!h->next_output_pic->recovered)
                 h->next_output_pic->f.flags |= AV_FRAME_FLAG_CORRUPT;

-            ret = output_frame(h, pict, &h->next_output_pic->f);
+            ret = output_frame(h, pict, h->next_output_pic);
             if (ret < 0)
                 return ret;
             *got_frame = 1;
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 958cd26..f518e24 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -81,6 +81,14 @@ enum AVFrameSideDataType {
      * See libavutil/display.h for a detailed description of the data.
      */
     AV_FRAME_DATA_DISPLAYMATRIX,
+ /**
+ * H264 macroblock type as copy of H264Picture.mb_type_buf
+ */
+ AV_FRAME_DATA_MB_TYPE,
+ /**
+ * H264 motion value as serialized copy of H264Picture.motion_val_buf
+ */
+ AV_FRAME_DATA_MOTION_VAL,
 };

 typedef struct AVFrameSideData {


Regards,
R. Savchenko
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to