Revision 0a63a676

View differences:

libavformat/avc.c
60 60
    return end + 3;
61 61
}
62 62

  
63
int ff_avc_parse_nal_units(const uint8_t *buf_in, uint8_t **buf, int *size)
63
void ff_avc_parse_nal_units(ByteIOContext *pb, const uint8_t *buf_in, int size)
64 64
{
65
    ByteIOContext *pb;
66 65
    const uint8_t *p = buf_in;
67
    const uint8_t *end = p + *size;
66
    const uint8_t *end = p + size;
68 67
    const uint8_t *nal_start, *nal_end;
69
    int ret = url_open_dyn_buf(&pb);
70
    if(ret < 0)
71
        return ret;
72 68

  
73 69
    nal_start = ff_avc_find_startcode(p, end);
74 70
    while (nal_start < end) {
......
78 74
        put_buffer(pb, nal_start, nal_end - nal_start);
79 75
        nal_start = nal_end;
80 76
    }
77
}
78

  
79
static int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size)
80
{
81
    ByteIOContext *pb;
82
    int ret = url_open_dyn_buf(&pb);
83
    if(ret < 0)
84
        return ret;
85

  
86
    ff_avc_parse_nal_units(pb, buf_in, *size);
87

  
81 88
    av_freep(buf);
82 89
    *size = url_close_dyn_buf(pb, buf);
83 90
    return 0;
......
92 99
            uint32_t sps_size=0, pps_size=0;
93 100
            uint8_t *sps=0, *pps=0;
94 101

  
95
            int ret = ff_avc_parse_nal_units(data, &buf, &len);
102
            int ret = ff_avc_parse_nal_units_buf(data, &buf, &len);
96 103
            if (ret < 0)
97 104
                return ret;
98 105
            start = buf;
libavformat/avc.h
25 25
#include <stdint.h>
26 26
#include "avio.h"
27 27

  
28
int ff_avc_parse_nal_units(const uint8_t *buf_in, uint8_t **buf, int *size);
28
void ff_avc_parse_nal_units(ByteIOContext *s, const uint8_t *buf, int size);
29 29
int ff_isom_write_avcc(ByteIOContext *pb, const uint8_t *data, int len);
30 30
const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end);
31 31

  
libavformat/flvenc.c
341 341
    }
342 342

  
343 343
    if (enc->codec_id == CODEC_ID_H264) {
344
        /* check if extradata looks like mp4 formated */
345
        if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) {
346
            if (ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size) < 0)
347
                return -1;
348
            assert(pkt->size);
349
            size = pkt->size;
350
        }
351 344
        if (!flv->delay && pkt->dts < 0)
352 345
            flv->delay = -pkt->dts;
353 346
    }
......
368 361
        put_byte(pb,1); // AVC NALU
369 362
        put_be24(pb,pkt->pts - pkt->dts);
370 363
    }
364
    if (enc->codec_id == CODEC_ID_H264 &&
365
        /* check if extradata looks like mp4 formated */
366
        enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) {
367
        ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
368
    } else {
371 369
    put_buffer(pb, pkt->data, size);
370
    }
372 371
    put_be32(pb,size+flags_size+11); // previous tag size
373 372
    flv->duration = FFMAX(flv->duration, pkt->pts + flv->delay + pkt->duration);
374 373

  
libavformat/matroskaenc.c
785 785
{
786 786
    MatroskaMuxContext *mkv = s->priv_data;
787 787
    ByteIOContext *pb = s->pb;
788
    AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
788 789

  
789 790
    av_log(s, AV_LOG_DEBUG, "Writing block at offset %" PRIu64 ", size %d, "
790 791
           "pts %" PRId64 ", dts %" PRId64 ", duration %d, flags %d\n",
......
794 795
    put_byte(pb, 0x80 | (pkt->stream_index + 1));     // this assumes stream_index is less than 126
795 796
    put_be16(pb, pkt->pts - mkv->cluster_pts);
796 797
    put_byte(pb, flags);
798
    if (codec->codec_id == CODEC_ID_H264 &&
799
        codec->extradata_size > 0 && AV_RB32(codec->extradata) == 0x00000001) {
800
        /* from x264 or from bytestream h264 */
801
        /* nal reformating needed */
802
        ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
803
    } else {
797 804
    put_buffer(pb, pkt->data, pkt->size);
805
    }
798 806
}
799 807

  
800 808
static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
......
822 830
        av_md5_update(mkv->md5_ctx, pkt->data, FFMIN(200, pkt->size));
823 831
    }
824 832

  
825
    if (codec->codec_id == CODEC_ID_H264 &&
826
        codec->extradata_size > 0 && AV_RB32(codec->extradata) == 0x00000001) {
827
        /* from x264 or from bytestream h264 */
828
        /* nal reformating needed */
829
        int ret = ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size);
830
        if (ret < 0)
831
            return ret;
832
        assert(pkt->size);
833
    }
834

  
835 833
    if (codec->codec_type != CODEC_TYPE_SUBTITLE) {
836 834
        mkv_write_block(s, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe << 7);
837 835
    } else if (codec->codec_id == CODEC_ID_SSA) {
libavformat/movenc.c
1732 1732
        memcpy(trk->vosData, enc->extradata, trk->vosLen);
1733 1733
    }
1734 1734

  
1735
    if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) {
1736
        /* from x264 or from bytestream h264 */
1737
        /* nal reformating needed */
1738
        int ret = ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size);
1739
        if (ret < 0)
1740
            return ret;
1741
        assert(pkt->size);
1742
        size = pkt->size;
1743
    } else if ((enc->codec_id == CODEC_ID_DNXHD ||
1735
    if ((enc->codec_id == CODEC_ID_DNXHD ||
1744 1736
                enc->codec_id == CODEC_ID_AC3) && !trk->vosLen) {
1745 1737
        /* copy frame to create needed atoms */
1746 1738
        trk->vosLen = size;
......
1777 1769
    trk->sampleCount += samplesInChunk;
1778 1770
    mov->mdat_size += size;
1779 1771

  
1772
    if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) {
1773
        /* from x264 or from bytestream h264 */
1774
        /* nal reformating needed */
1775
        ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
1776
    } else {
1780 1777
    put_buffer(pb, pkt->data, size);
1778
    }
1781 1779

  
1782 1780
    put_flush_packet(pb);
1783 1781
    return 0;

Also available in: Unified diff