[Ffmpeg-devel] [PATCH] DVR-MS probe audio format - was DVR-MS bug (MP2 decoding)

Michael Niedermayer michaelni
Wed Mar 14 00:48:53 CET 2007


Hi

On Tue, Mar 13, 2007 at 10:56:42AM -0500, John Donaghy wrote:
> >>
> >> since the options are so few and telling which stream is which is easy,
> >> you can do a scan
> >> on a short amount of data and keep a scoreboard of the valid syncwords 
> >found
> >
> >and you can use mp3_demuxer.read_probe() to do this, no need to duplicate
> >it
> >
> Here's a patch that works for all samples tested so far. It reads a
> few audio frames at the end of the asf_read_header function and tests
> if the stream is mp2 or not. If not, it assumes ac3 since those are
> the only 2 audio codecs used in dvr-ms.
> 
> Let me know if you need a sample uploaded. I still have the original
> clip that failed.
> 
> John

> Index: asf.c
> ===================================================================
> --- asf.c	(revision 8386)
> +++ asf.c	(working copy)
> @@ -256,6 +256,11 @@
>              st->codec->codec_type = type;
>              if (type == CODEC_TYPE_AUDIO) {
>                  get_wav_header(pb, st->codec, type_specific_size);
> +                if (test_for_ext_stream_audio) {
> +                    // codec_id is unreliable in dvr_ms files
> +                    // set it later by probing stream
> +                    st->codec->codec_id = -1;

wont this break EVERY audio format except mp3 and ac3?


[...]
>              AVCodecContext *codec= s->streams[stream_num]->codec;
[...]
> +                codec= s->streams[stream_num]->codec;

redundant


[...]
> +static int set_dvr_audio_format(AVFormatContext *s, int stream_num)
> +{
> +    ASFContext *asf = s->priv_data;
> +    AVPacket pkt[5], *ppkt;
> +    int64_t pos;
> +    int packet_count=0;
> +    int pd_buf_index=0;
> +    AVProbeData pd;
> +    int i;
> +
> +    pos=url_ftell(&s->pb);
> +
> +    // read the first 5 packets
> +    do
> +    {
> +        ppkt = pkt+packet_count;
> +        if (asf_read_packet(s, ppkt) < 0)
> +            return 0;
> +
> +        if (ppkt->stream_index == stream_num) {
> +            pd.buf_size += ppkt->size;
> +            packet_count++;
> +        } else {
> +            av_free_packet(ppkt);
> +        }
> +    }
> +    while (packet_count < 5);
> +
> +    // put the data into the AVProbeData struct
> +    pd.filename = "none";
> +    pd.buf = av_malloc(pd.buf_size);
> +    for (i=0; i<packet_count; i++) {
> +        ppkt = pkt+i;
> +        memcpy(pd.buf+pd_buf_index, ppkt->data, ppkt->size);
> +        pd_buf_index += ppkt->size;
> +        av_free_packet(ppkt);
> +    }
> +
> +    // test if the stream is MP2 - if not assume AC3
> +    if (mp3_read_probe(&pd) > 1) {
> +        s->streams[stream_num]->codec->codec_id = CODEC_ID_MP3;
> +        s->streams[stream_num]->codec->frame_size = MPA_FRAME_SIZE;
> +    } else {
> +        s->streams[stream_num]->codec->codec_id = CODEC_ID_AC3;
> +        s->streams[stream_num]->codec->frame_size = 1;
> +    }
> +    s->streams[stream_num]->codec->codec_tag = 0;
> +    av_free(pd.buf);
> +
> +    url_fseek(&s->pb, pos, SEEK_SET);
> +    asf_reset_header(s);

uhm, i dont think this will work ...
try ffmpeg -f asf - test.avi <in.asf

you could call a probe routine like that from av_find_stream_info() which
will take care of buffering all packets for you


[...]
>  /* mp3 read */
> -
> -static int mp3_read_probe(AVProbeData *p)
> +int mp3_read_probe(AVProbeData *p)
>  {

this needs a ff_ prefix and such renameing should be a seperate patch

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Freedom in capitalist society always remains about the same as it was in
ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070314/4bde9642/attachment.pgp>



More information about the ffmpeg-devel mailing list