[FFmpeg-devel] [PATCH 2/2] MxPEG decoder

Michael Niedermayer michaelni
Thu Nov 4 01:02:41 CET 2010


On Wed, Nov 03, 2010 at 11:29:55PM +0300, Anatoly Nenashev wrote:
> On 03.11.2010 21:04, Reimar D?ffinger wrote:
>> On Wed, Nov 03, 2010 at 08:54:44PM +0300, Anatoly Nenashev wrote:
>>    
>>> On 03.11.2010 18:11, Anatoly Nenashev wrote:
>>>      
>>>> I have additional question. This patch works fine with ffplay, so
>>>> this command
>>>>         ./ffplay stream.mxg
>>>> works fine and I see well syncronized video.
>>>>
>>>> But if I run
>>>>         ./ffmpeg -i stream.mxg -f rawvideo /dev/null
>>>> there are a lot of messages:
>>>>         [rawvideo @ 0x30f4d10] st:0 error, non monotone timestamps 1>= 1
>>>>
>>>> After some researches I found that right command line must be
>>>> ./ffmpeg -i stream.mxg -r 25 -f rawvideo /dev/null
>>>>
>>>> So it meens that user must manually define output FPS, otherwise
>>>> it will be 1/time_base. In case of mxg demuxer it is 1000000.
>>>> I think that it isn't so user friendly way. What can I do with
>>>> this issue?
>>>>
>>>>        
>>> I have found only one decision for this issue. I have changed
>>> time_base in demuxer  for video stream from 1/1000000 to 1/100 and
>>> rescale output pts from it.
>>>      
>> You can't just mangle the time stamps just because the one
>> source you have at hand sets them to values you don't like.
>> Your source isn't 30 fps, and it needs a 1/1000000 time base
>> to be represented accurately.
>>    
>
> Ok. I've removed dts transformation.
> Also parsing dts for audio packets are added. See attachment.
>
>> If you want FFmpeg to try harder to chose some "close enough
>> but not correct" time-base for non-VFR formats then that belongs
>> into the main FFmpeg code (e.g. the tb_unreliable handling),
>> but certainly not in a demuxer.
>>
>>    
>
> May be done later in another patchset.
>
>

>  Makefile     |    1 
>  allformats.c |    1 
>  mxg.c        |  199 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 201 insertions(+)
> 892aefbd0ac1976effc78f2c0fae17717d9afb6e  mxg_v9.patch
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index e62a5ea..d3e3cd0 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -147,6 +147,7 @@ OBJS-$(CONFIG_MTV_DEMUXER)               += mtv.o
>  OBJS-$(CONFIG_MVI_DEMUXER)               += mvi.o
>  OBJS-$(CONFIG_MXF_DEMUXER)               += mxfdec.o mxf.o
>  OBJS-$(CONFIG_MXF_MUXER)                 += mxfenc.o mxf.o audiointerleave.o
> +OBJS-$(CONFIG_MXG_DEMUXER)               += mxg.o
>  OBJS-$(CONFIG_NC_DEMUXER)                += ncdec.o
>  OBJS-$(CONFIG_NSV_DEMUXER)               += nsvdec.o
>  OBJS-$(CONFIG_NULL_MUXER)                += nullenc.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index e35f4f8..4afbef5 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -142,6 +142,7 @@ void av_register_all(void)
>      REGISTER_DEMUXER  (MVI, mvi);
>      REGISTER_MUXDEMUX (MXF, mxf);
>      REGISTER_MUXER    (MXF_D10, mxf_d10);
> +    REGISTER_DEMUXER  (MXG, mxg);
>      REGISTER_DEMUXER  (NC, nc);
>      REGISTER_DEMUXER  (NSV, nsv);
>      REGISTER_MUXER    (NULL, null);
> diff --git a/libavformat/mxg.c b/libavformat/mxg.c
> new file mode 100644
> index 0000000..1ae3cf3
> --- /dev/null
> +++ b/libavformat/mxg.c
> @@ -0,0 +1,199 @@
> +/*
> + * MxPEG clip file demuxer
> + * Copyright (c) 2010 Anatoly Nenashev
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "libavutil/intreadwrite.h"
> +#include "avformat.h"
> +#include "avio.h"
> +
> +#define VIDEO_STREAM_INDEX 0
> +#define AUDIO_STREAM_INDEX 1
> +#define DEFAULT_PACKET_SIZE 1024
> +
> +typedef struct MXGContext {
> +    uint8_t *buffer;
> +    unsigned int buffer_size;
> +    unsigned int current_pos;
> +    uint16_t state;
> +    int vop_found;
> +    int64_t dts;
> +} MXGContext;
> +
> +static int mxg_read_header(AVFormatContext *s, AVFormatParameters *ap)
> +{
> +    AVStream *video_st = 0, *audio_st = 0;
> +    MXGContext *mxg = s->priv_data;
> +
> +    /* video parameters will be extracted from the compressed bitstream */
> +    video_st = av_new_stream(s, VIDEO_STREAM_INDEX);
> +    if (!video_st)
> +        return AVERROR(ENOMEM);
> +    video_st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
> +    video_st->codec->codec_id = CODEC_ID_MXPEG;
> +    av_set_pts_info(video_st, 64, 1, 1000000);
> +
> +    audio_st = av_new_stream(s, AUDIO_STREAM_INDEX);
> +    if (!audio_st)
> +        return AVERROR(ENOMEM);
> +    audio_st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
> +    audio_st->codec->codec_id = CODEC_ID_PCM_ALAW;
> +    audio_st->codec->channels = 1;
> +    audio_st->codec->sample_rate = 8000;
> +    audio_st->codec->bits_per_coded_sample = 8;
> +    audio_st->codec->block_align = 1;
> +    av_set_pts_info(audio_st, 64, 1, 1000000);
> +
> +    mxg->buffer = av_malloc(DEFAULT_PACKET_SIZE);
> +    if (!mxg->buffer)
> +        return AVERROR(ENOMEM);
> +
> +    mxg->buffer_size = DEFAULT_PACKET_SIZE;
> +    mxg->current_pos = 0;
> +    mxg->state = 0;
> +    mxg->vop_found = 0;
> +    mxg->dts = AV_NOPTS_VALUE;
> +
> +    return 0;
> +}
> +
> +static int mxg_read_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> +    int ret, size;
> +    MXGContext *mxg = s->priv_data;
> +
> +    while (!url_feof(s->pb) && !url_ferror(s->pb)) {
> +        const uint8_t data = get_byte(s->pb);
> +        unsigned int found_frame_end = 0, current_pad;
> +        mxg->state = (mxg->state << 8) | data;
> +        mxg->buffer[mxg->current_pos++] = data;
> +
> +        if (mxg->state == 0xffd9) {
> +            found_frame_end = mxg->current_pos;
> +        } else if (mxg->state == 0xffd8) {
> +            if (mxg->vop_found) {
> +                //emulating frame end
> +                url_fseek(s->pb, -2, SEEK_CUR);
> +                mxg->current_pos -= 2;
> +                found_frame_end = mxg->current_pos;
> +            } else {
> +                mxg->vop_found = 1;
> +            }
> +        } else if (mxg->state == 0xfffe) {

these numeric things need comments that say what each is

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

I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101104/09a5396d/attachment.pgp>



More information about the ffmpeg-devel mailing list