[FFmpeg-user] Detect if an MTS file is interlaced or not?

Mike Scheutzow mike.scheutzow at alcatel-lucent.com
Wed Jun 15 16:06:26 CEST 2011


Thomas Worth wrote:
>>> On Wed, Jun 8, 2011 at 2:13 AM, Thomas Worth <dev at rarevision.com> wrote:
>>> It doesn't seem to be getting it from r_frame_rate, since that is
>>> always double the playback rate with MTS it seems.

>> The double rate is not an artifact of the container. The container knows
>> nothing about the frame rate.
> 
> The container, or at least the streams should be flagged as
> field-based and have some type of field order flag (top first / bottom
> first). 

For a transport stream container, this is not the case. There is no 
field/frame info at the container level. There is no field/frame info at 
the global stream level. For H.264, this information is placed at the 
Frame level.

For H.264, you have to examine the Slice NAL to determine field/frame 
and top/bottom status. This is because H.264 is very flexible, and 
allows mixing field pictures and frame pictures in the same elementary 
stream.

> Otherwise, a playback device wouldn't know how to play it
> back. It is this information I need to interpret, but I just can't
> seem to get it. I know the information is there, I just need to know
> how to retrieve it from avcodec.

There are two fields, but they don't tell you what you seem to want.

See AVFrame.interlaced_frame and AVFrame.top_field_first in avcodec.h. 
These fields are part of the AVFrame information returned by 
avcodec_decode_video2().

Be careful though: these fields do NOT tell you whether the input to the 
decoder was 2 field pictures or 1 frame picture, because a frame picture 
can also can also contain interlaced top/bottom content (this is very 
common.)

As far as I know, FFmpeg does not provide an easy way to determine if a 
particular AVPacket holds 1 field or 1 frame.

> I don't know much about how avcodec
> handles MTS files, so I was hoping this would be an easy answer for
> one of the devs that's worked on the MTS demuxer.


Mike Scheutzow


More information about the ffmpeg-user mailing list