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

Thomas Worth dev at rarevision.com
Wed Jun 15 14:03:55 CEST 2011


On Tue, Jun 14, 2011 at 6:48 AM, Mike Scheutzow
<mike.scheutzow at alcatel-lucent.com> wrote:
> Thomas Worth wrote:
>>
>> On Wed, Jun 8, 2011 at 2:13 AM, Thomas Worth <dev at rarevision.com> wrote:
>>>
>>> I'd like to know if there's a way to tell if an MTS file is
>>> interlaced, preferably without having to decode it first. The problem
>>> I have is that libav always returns 59.94 for the frame rate of
>>> interlaced NTSC streams, even though we know it's 29.97. And of
>>> course, r_frame_rate always returns 0 with the "mpegts" format so I am
>>> left to calculate the frame count manually. I need the correct frame
>>> rate to do this, however and there's no way of telling ahead of time
>>> whether the input video will be interlaced or not. Any ideas?
>>>
>>
>> Sorry to nag, but I didn't get a response to this. All I need is a way
>> to determine whether an input MTS file (with an H.264 stream) is
>> interlaced or not. I thought this could be accomplished by reading
>> values from the MTS format context, but I've had no luck. I even tried
>> decoding an AVFrame and reading the avframe->interlaced_frame value,
>> but it did not report the frame as interlaced even though the video is
>> indeed interlaced (comments in avcodec.h say this value is set by the
>> decoder).
>>
>> Obviously VLC is playing the file back at its intended frame rate even
>> though the frame rate reported by avformat is 59.94 (the actual frame,
>> not field rate should be 29.97). Where is it getting this information?
>> It doesn't seem to be getting it from r_frame_rate, since that is
>> always double the playback rate with MTS it seems.
>
>
> It sounds as if you are trying to decode a file with video field pictures
> (as opposed to frame pictures.) The ffmpeg rate-estimation code always makes
> a mistake and doubles the frame rate in this situation.

Yes, this is exactly what I'm trying to do. I decode an interlaced
(field-based) MTS stream, and avcodec is reporting the frame rate as
double of what it should be.

>> 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). 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. 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.


More information about the ffmpeg-user mailing list