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

Anatoly Nenashev anatoly.nenashev
Wed Nov 3 16:11:11 CET 2010


On 03.11.2010 03:21, Anatoly Nenashev wrote:
> On 02.11.2010 22:08, Michael Niedermayer wrote:
>> On Tue, Nov 02, 2010 at 06:25:41AM +0300, Anatoly Nenashev wrote:
>>
>> [...]
>>> +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;
>>> +        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
>>> +                found_frame_end = mxg->current_pos - 2;
>>> +                url_fseek(s->pb, -2, SEEK_CUR);
>>> +            } else {
>>> +                mxg->vop_found = 1;
>>> +            }
>>> +        } else if (mxg->state == 0xfffe) {
>>> +            size = get_be16(s->pb);
>>> +            if (url_feof(s->pb) || url_ferror(s->pb))
>>> +                return AVERROR_EOF;
>> checking for eof after every byte read seems overkill to me
>>
>>
>
> Removed.
>
>>> +
>>> +            if (mxg->current_pos>  mxg->current_pos + size)
>>> +                return AVERROR(ENOMEM);
>>> +
>>> +            mxg->buffer = 
>>> av_fast_realloc(mxg->buffer,&mxg->buffer_size,
>>> +                                          mxg->current_pos + size);
>>> +            if (!mxg->buffer)
>>> +                return AVERROR(ENOMEM);
>>> +
>>> +            if (size<  2) {
>>> +                av_log(s, AV_LOG_ERROR, "wrong comment buffer 
>>> size\n");
>>> +                return AVERROR(EINVAL);
>>> +            }
>> checking size after using it
>
> It's moved above.
>
>>
>>> +            mxg->buffer[mxg->current_pos++] = size>>  8;
>>> +            mxg->buffer[mxg->current_pos++] = size&  0xff;
>>> +
>>> +            ret = get_buffer(s->pb, mxg->buffer + mxg->current_pos, 
>>> size - 2);
>>> +            if (ret<  0)
>>> +                return ret;
>>> +            if (ret>= 16&&  !strncmp(mxg->buffer + 
>>> mxg->current_pos, "MXF", 3)) {
>>> +                mxg->dts = AV_RL64(mxg->buffer + mxg->current_pos + 
>>> 8);
>>> +            }
>>> +            mxg->current_pos += ret;
>>> +            mxg->state = 0;
>>> +        } else if (mxg->state == 0xffed) {
>>> +            mxg->current_pos -= 2;
>>> +            size = get_be16(s->pb);
>>> +            if (url_feof(s->pb) || url_ferror(s->pb))
>>> +                return AVERROR_EOF;
>>> +            if (size<= 14)
>>> +                return AVERROR(EINVAL);
>>> +            url_fskip(s->pb, 12);
>>> +            if (url_feof(s->pb) || url_ferror(s->pb))
>>> +                return AVERROR_EOF;
>>> +            size -= 14;
>>> +            ret = av_get_packet(s->pb, pkt, size);
>>> +            if (ret<  0)
>>> +                return ret;
>>> +
>>> +            pkt->stream_index = AUDIO_STREAM_INDEX;
>>> +            mxg->state = 0;
>>> +
>>> +            return pkt->size;
>>> +        }
>>> +
>>> +        if (found_frame_end) {
>>> +            mxg->vop_found = 0;
>>> +            mxg->current_pos = 0;
>>> +            ret = av_new_packet(pkt, found_frame_end);
>>> +            if (ret<  0)
>>> +                return ret;
>>> +            memcpy(pkt->data, mxg->buffer, found_frame_end);
>> avoidable
>>
>>
>
> Yes. New implementation attached.
>
>
>

Fix pkt->pos value initialization.


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?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mxg_v7.patch
Type: text/x-patch
Size: 7709 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101103/c44360a2/attachment.bin>



More information about the ffmpeg-devel mailing list