Mercurial > libavformat.hg
changeset 2307:d5508f387614 libavformat
add streams on the fly, swf is a streaming format and has no real header, correctly detect audio in RamboMJPEGAVP6_112K.swf now
author | bcoudurier |
---|---|
date | Sun, 05 Aug 2007 01:28:05 +0000 |
parents | d045cbcf37a3 |
children | c12d367e9246 |
files | swf.c |
diffstat | 1 files changed, 28 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/swf.c Sun Aug 05 00:47:57 2007 +0000 +++ b/swf.c Sun Aug 05 01:28:05 2007 +0000 @@ -652,14 +652,21 @@ get_le16(pb); /* frame count */ swf->samples_per_frame = 0; + s->ctx_flags |= AVFMTCTX_NOHEADER; + return 0; +} + +static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + SWFContext *swf = s->priv_data; + ByteIOContext *pb = &s->pb; + AVStream *vst = NULL, *ast = NULL, *st = 0; + int tag, len, i, frame, v; for(;;) { - offset_t tag_offset = url_ftell(pb); tag = get_swf_tag(pb, &len); - if (tag < 0 || tag == TAG_VIDEOFRAME || tag == TAG_STREAMBLOCK) { - url_fseek(pb, frame_offset == -1 ? tag_offset : frame_offset, SEEK_SET); - break; - } + if (tag < 0) + return AVERROR(EIO); if ( tag == TAG_VIDEOSTREAM && !vst) { int ch_id = get_le16(pb); get_le16(pb); @@ -670,6 +677,9 @@ vst = av_new_stream(s, ch_id); vst->codec->codec_type = CODEC_TYPE_VIDEO; vst->codec->codec_id = codec_get_id(swf_codec_tags, get_byte(pb)); + av_set_pts_info(vst, 64, 256, swf->frame_rate); + vst->codec->time_base = (AVRational){ 256, swf->frame_rate }; + len -= 10; } else if ( ( tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2 ) && !ast) { /* streaming found */ int sample_rate_code; @@ -687,35 +697,8 @@ return AVERROR(EIO); ast->codec->sample_rate = 11025 << (sample_rate_code-1); av_set_pts_info(ast, 64, 1, ast->codec->sample_rate); - if (len > 4) - url_fskip(pb,len-4); - - } else if (tag == TAG_JPEG2 && !vst) { - vst = av_new_stream(s, -2); /* -2 to avoid clash with video stream and audio stream */ - vst->codec->codec_type = CODEC_TYPE_VIDEO; - vst->codec->codec_id = CODEC_ID_MJPEG; - url_fskip(pb, len); - frame_offset = tag_offset; - } else { - url_fskip(pb, len); - } - } - if (vst) - av_set_pts_info(vst, 64, 256, swf->frame_rate); - return 0; -} - -static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) -{ - SWFContext *swf = s->priv_data; - ByteIOContext *pb = &s->pb; - AVStream *st = 0; - int tag, len, i, frame; - - for(;;) { - tag = get_swf_tag(pb, &len); - if (tag < 0) - return AVERROR(EIO); + len -= 4; + } else if (tag == TAG_VIDEOFRAME) { int ch_id = get_le16(pb); len -= 2; @@ -742,7 +725,17 @@ } else if (tag == TAG_JPEG2) { for (i=0; i<s->nb_streams; i++) { st = s->streams[i]; - if (st->id == -2) { + if (st->id == -2) + break; + } + if (i == s->nb_streams) { + vst = av_new_stream(s, -2); /* -2 to avoid clash with video stream and audio stream */ + vst->codec->codec_type = CODEC_TYPE_VIDEO; + vst->codec->codec_id = CODEC_ID_MJPEG; + av_set_pts_info(vst, 64, 256, swf->frame_rate); + vst->codec->time_base = (AVRational){ 256, swf->frame_rate }; + st = vst; + } get_le16(pb); /* BITMAP_ID */ av_new_packet(pkt, len-2); get_buffer(pb, pkt->data, 4); @@ -755,8 +748,6 @@ } pkt->stream_index = st->index; return pkt->size; - } - } } url_fskip(pb, len); }