ffmpeg decoder problem mpeg2 vs mpeg4

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

ffmpeg decoder problem mpeg2 vs mpeg4

Jordan Dressman
What I am trying to do is decode frames from a buffer that has encoded
frame data, more specifically the data that avcodec_encode_video
returns (not from a _FILE_).  I can only successfully decode iframes
when I use mpeg2video codec, but when I switch the codec to mpeg4 it
successfully decodes every single frame.

Would it be the same code to decode both mpeg2 and mpeg4, am I missing
something?  The only difference is that mpeg2 is stream based and mpeg4
is frame based.  I am feeding the decoder full encoded frames so it
should still work for both even if mpeg2 is stream based...

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: ffmpeg decoder problem mpeg2 vs mpeg4

Luca Abeni
Jordan Dressman wrote:
> What I am trying to do is decode frames from a buffer that has encoded
> frame data, more specifically the data that avcodec_encode_video
> returns (not from a _FILE_).

Try apiexample.c, and if it does what you need you can be inspired by
its code (in particular, look at video_decode_example()).

[...]
> Would it be the same code to decode both mpeg2 and mpeg4, am I missing
> something?

AFAIK, the same code (if correctly written) should be able to decode both
mpeg2 and mpeg4 (by simply changing CODEC_ID_*).



                                Luca
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: ffmpeg decoder problem mpeg2 vs mpeg4

Jordan Dressman
Quoting Luca Abeni <[hidden email]>:
> Try apiexample.c, and if it does what you need you can be inspired by
> its code (in particular, look at video_decode_example()).

Luca that is the code I'm using, video_decode_example(), except it is
slightly modified because I'm reading from a buffer not a file.  Why
does it work for mpeg4 and not mpeg2 is my question.

> AFAIK, the same code (if correctly written) should be able to decode both
> mpeg2 and mpeg4 (by simply changing CODEC_ID_*).

Is it reasonable to assume that if it works for mpeg4 then it should
work for mpeg2?  I can only decode I-frames using mpeg2.


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: ffmpeg decoder problem mpeg2 vs mpeg4

Silvain Beriault
Jordan Dressman wrote:

> Quoting Luca Abeni <[hidden email]>:
>  
>> Try apiexample.c, and if it does what you need you can be inspired by
>> its code (in particular, look at video_decode_example()).
>>    
>
> Luca that is the code I'm using, video_decode_example(), except it is
> slightly modified because I'm reading from a buffer not a file.  Why
> does it work for mpeg4 and not mpeg2 is my question.
>  
Are you doing the following:
while(!done) {
    Encode a frame
    Decode a frame
}


or are you doing the following?:
encode all frames
decode all frames


I think the first option will only work with frame-based codec. MPEG2 is
stream based so you need to encode at least few frames prior to the
decoding (I think). But don't quote me on that (I may be wrong).

Silvain

_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: ffmpeg decoder problem mpeg2 vs mpeg4

Jordan Dressman
Quoting Silvain Beriault <[hidden email]>:

> Are you doing the following:
> while(!done) {
>    Encode a frame
>    Decode a frame
> }
>
>
> or are you doing the following?:
> encode all frames
> decode all frames

Ok I just figured out what I was doing wrong I had:

...
len = avcodec_decode_video(c, frame, &got_picture, inbuf_ptr, size);
...
len = avcodec_decode_video(c, picture, &got_picture,NULL, 0);
...

in every call to my decode_video_frame function, the second call to
avcodec_decode_video is only supposed to decode the very last frame. It
must of been messing the decoder up.

So it is possible to encode then decode each frame you don't need
several frames encoded.  Thanks for the help I probably wouldn't of
found that alone.

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: ffmpeg decoder problem mpeg2 vs mpeg4

Jordan Dressman
> So it is possible to encode then decode each frame you don't need
> several frames encoded.

Actually I take that back about you don't need several frames encoded
because it doesn't actually start successfully decoding until the third
frame.

-Jordan



----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user