[FFmpeg-cvslog] r16616 - in trunk/libavformat: avc.c avc.h flvenc.c matroskaenc.c movenc.c

lucabe subversion
Thu Jan 15 15:03:12 CET 2009


Author: lucabe
Date: Thu Jan 15 15:03:07 2009
New Revision: 16616

Log:
Do not reallocate AVPacket's data when muxing a packet

Modified:
   trunk/libavformat/avc.c
   trunk/libavformat/avc.h
   trunk/libavformat/flvenc.c
   trunk/libavformat/matroskaenc.c
   trunk/libavformat/movenc.c

Modified: trunk/libavformat/avc.c
==============================================================================
--- trunk/libavformat/avc.c	Thu Jan 15 13:23:03 2009	(r16615)
+++ trunk/libavformat/avc.c	Thu Jan 15 15:03:07 2009	(r16616)
@@ -60,15 +60,11 @@ const uint8_t *ff_avc_find_startcode(con
     return end + 3;
 }
 
-int ff_avc_parse_nal_units(const uint8_t *buf_in, uint8_t **buf, int *size)
+void ff_avc_parse_nal_units(ByteIOContext *pb, const uint8_t *buf_in, int size)
 {
-    ByteIOContext *pb;
     const uint8_t *p = buf_in;
-    const uint8_t *end = p + *size;
+    const uint8_t *end = p + size;
     const uint8_t *nal_start, *nal_end;
-    int ret = url_open_dyn_buf(&pb);
-    if(ret < 0)
-        return ret;
 
     nal_start = ff_avc_find_startcode(p, end);
     while (nal_start < end) {
@@ -78,6 +74,17 @@ int ff_avc_parse_nal_units(const uint8_t
         put_buffer(pb, nal_start, nal_end - nal_start);
         nal_start = nal_end;
     }
+}
+
+static int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size)
+{
+    ByteIOContext *pb;
+    int ret = url_open_dyn_buf(&pb);
+    if(ret < 0)
+        return ret;
+
+    ff_avc_parse_nal_units(pb, buf_in, *size);
+
     av_freep(buf);
     *size = url_close_dyn_buf(pb, buf);
     return 0;
@@ -92,7 +99,7 @@ int ff_isom_write_avcc(ByteIOContext *pb
             uint32_t sps_size=0, pps_size=0;
             uint8_t *sps=0, *pps=0;
 
-            int ret = ff_avc_parse_nal_units(data, &buf, &len);
+            int ret = ff_avc_parse_nal_units_buf(data, &buf, &len);
             if (ret < 0)
                 return ret;
             start = buf;

Modified: trunk/libavformat/avc.h
==============================================================================
--- trunk/libavformat/avc.h	Thu Jan 15 13:23:03 2009	(r16615)
+++ trunk/libavformat/avc.h	Thu Jan 15 15:03:07 2009	(r16616)
@@ -25,7 +25,7 @@
 #include <stdint.h>
 #include "avio.h"
 
-int ff_avc_parse_nal_units(const uint8_t *buf_in, uint8_t **buf, int *size);
+void ff_avc_parse_nal_units(ByteIOContext *s, const uint8_t *buf, int size);
 int ff_isom_write_avcc(ByteIOContext *pb, const uint8_t *data, int len);
 const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end);
 

Modified: trunk/libavformat/flvenc.c
==============================================================================
--- trunk/libavformat/flvenc.c	Thu Jan 15 13:23:03 2009	(r16615)
+++ trunk/libavformat/flvenc.c	Thu Jan 15 15:03:07 2009	(r16616)
@@ -341,13 +341,6 @@ static int flv_write_packet(AVFormatCont
     }
 
     if (enc->codec_id == CODEC_ID_H264) {
-        /* check if extradata looks like mp4 formated */
-        if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) {
-            if (ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size) < 0)
-                return -1;
-            assert(pkt->size);
-            size = pkt->size;
-        }
         if (!flv->delay && pkt->dts < 0)
             flv->delay = -pkt->dts;
     }
@@ -368,7 +361,13 @@ static int flv_write_packet(AVFormatCont
         put_byte(pb,1); // AVC NALU
         put_be24(pb,pkt->pts - pkt->dts);
     }
+    if (enc->codec_id == CODEC_ID_H264 &&
+        /* check if extradata looks like mp4 formated */
+        enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) {
+        ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
+    } else {
     put_buffer(pb, pkt->data, size);
+    }
     put_be32(pb,size+flags_size+11); // previous tag size
     flv->duration = FFMAX(flv->duration, pkt->pts + flv->delay + pkt->duration);
 

Modified: trunk/libavformat/matroskaenc.c
==============================================================================
--- trunk/libavformat/matroskaenc.c	Thu Jan 15 13:23:03 2009	(r16615)
+++ trunk/libavformat/matroskaenc.c	Thu Jan 15 15:03:07 2009	(r16616)
@@ -785,6 +785,7 @@ static void mkv_write_block(AVFormatCont
 {
     MatroskaMuxContext *mkv = s->priv_data;
     ByteIOContext *pb = s->pb;
+    AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
 
     av_log(s, AV_LOG_DEBUG, "Writing block at offset %" PRIu64 ", size %d, "
            "pts %" PRId64 ", dts %" PRId64 ", duration %d, flags %d\n",
@@ -794,7 +795,14 @@ static void mkv_write_block(AVFormatCont
     put_byte(pb, 0x80 | (pkt->stream_index + 1));     // this assumes stream_index is less than 126
     put_be16(pb, pkt->pts - mkv->cluster_pts);
     put_byte(pb, flags);
+    if (codec->codec_id == CODEC_ID_H264 &&
+        codec->extradata_size > 0 && AV_RB32(codec->extradata) == 0x00000001) {
+        /* from x264 or from bytestream h264 */
+        /* nal reformating needed */
+        ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
+    } else {
     put_buffer(pb, pkt->data, pkt->size);
+    }
 }
 
 static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
@@ -822,16 +830,6 @@ static int mkv_write_packet(AVFormatCont
         av_md5_update(mkv->md5_ctx, pkt->data, FFMIN(200, pkt->size));
     }
 
-    if (codec->codec_id == CODEC_ID_H264 &&
-        codec->extradata_size > 0 && AV_RB32(codec->extradata) == 0x00000001) {
-        /* from x264 or from bytestream h264 */
-        /* nal reformating needed */
-        int ret = ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size);
-        if (ret < 0)
-            return ret;
-        assert(pkt->size);
-    }
-
     if (codec->codec_type != CODEC_TYPE_SUBTITLE) {
         mkv_write_block(s, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe << 7);
     } else if (codec->codec_id == CODEC_ID_SSA) {

Modified: trunk/libavformat/movenc.c
==============================================================================
--- trunk/libavformat/movenc.c	Thu Jan 15 13:23:03 2009	(r16615)
+++ trunk/libavformat/movenc.c	Thu Jan 15 15:03:07 2009	(r16616)
@@ -1732,15 +1732,7 @@ static int mov_write_packet(AVFormatCont
         memcpy(trk->vosData, enc->extradata, trk->vosLen);
     }
 
-    if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) {
-        /* from x264 or from bytestream h264 */
-        /* nal reformating needed */
-        int ret = ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size);
-        if (ret < 0)
-            return ret;
-        assert(pkt->size);
-        size = pkt->size;
-    } else if ((enc->codec_id == CODEC_ID_DNXHD ||
+    if ((enc->codec_id == CODEC_ID_DNXHD ||
                 enc->codec_id == CODEC_ID_AC3) && !trk->vosLen) {
         /* copy frame to create needed atoms */
         trk->vosLen = size;
@@ -1777,7 +1769,13 @@ static int mov_write_packet(AVFormatCont
     trk->sampleCount += samplesInChunk;
     mov->mdat_size += size;
 
+    if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) {
+        /* from x264 or from bytestream h264 */
+        /* nal reformating needed */
+        ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
+    } else {
     put_buffer(pb, pkt->data, size);
+    }
 
     put_flush_packet(pb);
     return 0;




More information about the ffmpeg-cvslog mailing list