Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] Inconsistent usage of AVFieldOrder values
@ 2024-04-22 21:03 Devin Heitmueller
  2024-04-24 22:42 ` Marton Balint
  0 siblings, 1 reply; 3+ messages in thread
From: Devin Heitmueller @ 2024-04-22 21:03 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Hello,

I suspect this topic has been visited a number of times over the
years, but I figured I should re-raise it.

In the compressed domain, field ordering is represented by the
AVFieldOrder enumeration.  Among the interlaced possibilities, you've
got four combinations:  AV_FIELD_TT, AV_FIELD_BB, AV_FIELD_TB,
AV_FIELD_BT.  The last two characters indicate the coding and display
order respectively.

Only a subset of these possible values are able to be represented in
ffmpeg's AVFrame facility (specifically AV_FIELD_TT and AV_FIELD_TB).
This is because interlaced AVFrames are always represented as
interleaved with top field coded first, and the
AV_FRAME_FLAG_TOP_FIELD_FIRST flag (previously the top_field_first
member) is used to dictate the display order.  I'm not proposing we
make any change to this behavior at this time.

I'm seeing use cases (including within the ffmpeg tree) where I
suspect the developer is misunderstanding the meaning of these values,
and I want to solicit feedback on whether patches would be accepted to
correct such usage, even if it results in breaking applications that
expect the incorrect values.

For example, the decklink input module (libavdevice/decklink_dec.cpp)
sets the values on the v210 packets to either AV_FIELD_TT or
AV_FIELD_BB depending on whether the display order is top field first
or bottom field first.  While the AV_FIELD_TT values is correct, the
use of AV_FIELD_BB is incorrect since all frames delivered by the
driver are always coded as top-field-first (i.e. interlaced frames
with a display order of bottom first should be AV_FIELD_TB).

I'm seeing numerous cases such as the above, in decoders and encoders,
libavformat/libavdevice modules, as well as in third party
applications.

I guess my question is:  if I submit patches which fix such cases
where I find them, will they be rejected because they are a change in
behavior and might very well break existing applications that expect
the incorrect values?  I would like the libraries to report the
correct values in a consistent manner, but I recognize this may cause
some breakage in existing applications.

Thoughts?

Devin

-- 
Devin Heitmueller, Senior Software Engineer
LTN Global Communications
o: +1 (301) 363-1001
w: https://ltnglobal.com  e: devin.heitmueller@ltnglobal.com
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [FFmpeg-devel] Inconsistent usage of AVFieldOrder values
  2024-04-22 21:03 [FFmpeg-devel] Inconsistent usage of AVFieldOrder values Devin Heitmueller
@ 2024-04-24 22:42 ` Marton Balint
  2024-04-25  6:58   ` Tobias Rapp
  0 siblings, 1 reply; 3+ messages in thread
From: Marton Balint @ 2024-04-24 22:42 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



On Mon, 22 Apr 2024, Devin Heitmueller wrote:

> Hello,
>
> I suspect this topic has been visited a number of times over the
> years, but I figured I should re-raise it.
>
> In the compressed domain, field ordering is represented by the
> AVFieldOrder enumeration.  Among the interlaced possibilities, you've
> got four combinations:  AV_FIELD_TT, AV_FIELD_BB, AV_FIELD_TB,
> AV_FIELD_BT.  The last two characters indicate the coding and display
> order respectively.

That is how it is documented, but likely it is not how it actually works. 
The whole mess is originated from the QuickTime specification which 
contradicts with an Apple technical note. See this discussion: 
https://sourceforge.net/p/mediainfo/bugs/841/

Long story short, AV_FIELD_TB means top field first in practice, 
AV_FIELD_BT means bottom field first in practice. I think most of the code 
follows this interpretation, and not the actual documentation. 
AV_FIELD_BB and AV_FIELD_TT tries to signal field order for separate 
field encodings, but quite possibly sometimes (mis)used for ordinary field 
order signalling as well...

>
> Only a subset of these possible values are able to be represented in
> ffmpeg's AVFrame facility (specifically AV_FIELD_TT and AV_FIELD_TB).
> This is because interlaced AVFrames are always represented as
> interleaved with top field coded first, and the
> AV_FRAME_FLAG_TOP_FIELD_FIRST flag (previously the top_field_first
> member) is used to dictate the display order.  I'm not proposing we
> make any change to this behavior at this time.
>
> I'm seeing use cases (including within the ffmpeg tree) where I
> suspect the developer is misunderstanding the meaning of these values,
> and I want to solicit feedback on whether patches would be accepted to
> correct such usage, even if it results in breaking applications that
> expect the incorrect values.
>
> For example, the decklink input module (libavdevice/decklink_dec.cpp)
> sets the values on the v210 packets to either AV_FIELD_TT or
> AV_FIELD_BB depending on whether the display order is top field first
> or bottom field first.  While the AV_FIELD_TT values is correct, the
> use of AV_FIELD_BB is incorrect since all frames delivered by the
> driver are always coded as top-field-first (i.e. interlaced frames
> with a display order of bottom first should be AV_FIELD_TB).

I guess the reason for using TT/BB was that it is not contriversal... But 
TB is BFF according to docs, but it is interpreted as TFF in reality...

>
> I'm seeing numerous cases such as the above, in decoders and encoders,
> libavformat/libavdevice modules, as well as in third party
> applications.
>
> I guess my question is:  if I submit patches which fix such cases
> where I find them, will they be rejected because they are a change in
> behavior and might very well break existing applications that expect
> the incorrect values?  I would like the libraries to report the
> correct values in a consistent manner, but I recognize this may cause
> some breakage in existing applications.

Making changes out of the blue likely won't be acceptable. If a
justified plan is presented to untangle this, then maybe *some* breakage 
is acceptable, but I don't honestly know.

Some random ideas:

- Consider fixing the documentation (and the textual description of the
   field orders) instead of changing behaviour.
- Try to collect commercial samples and see what they contain for TFF/BFF
   content, separete fields or interleaved, compressed or
   uncompressed.
- Go over the codebase and see which component is using which
   interpretation in practice, make a list, see if there is a significant
   majority...

Regards,
Marton
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [FFmpeg-devel] Inconsistent usage of AVFieldOrder values
  2024-04-24 22:42 ` Marton Balint
@ 2024-04-25  6:58   ` Tobias Rapp
  0 siblings, 0 replies; 3+ messages in thread
From: Tobias Rapp @ 2024-04-25  6:58 UTC (permalink / raw)
  To: ffmpeg-devel

On 25/04/2024 00:42, Marton Balint wrote:

>
>
> On Mon, 22 Apr 2024, Devin Heitmueller wrote:
>
>> Hello,
>>
>> I suspect this topic has been visited a number of times over the
>> years, but I figured I should re-raise it.
>>
>> In the compressed domain, field ordering is represented by the
>> AVFieldOrder enumeration.  Among the interlaced possibilities, you've
>> got four combinations:  AV_FIELD_TT, AV_FIELD_BB, AV_FIELD_TB,
>> AV_FIELD_BT.  The last two characters indicate the coding and display
>> order respectively.
>
> That is how it is documented, but likely it is not how it actually 
> works. The whole mess is originated from the QuickTime specification 
> which contradicts with an Apple technical note. See this discussion: 
> https://sourceforge.net/p/mediainfo/bugs/841/
>
Recently I also stumbled over this when using the FFmpeg Matroska muxer. 
Found some discussion around the interpretation of the QuickTime spec in 
https://github.com/amiaopensource/vrecord/issues/170#issuecomment-321937668 
and http://trac.ffmpeg.org/ticket/6577#ticket.
> Long story short, AV_FIELD_TB means top field first in practice, 
> AV_FIELD_BT means bottom field first in practice. I think most of the 
> code follows this interpretation, and not the actual documentation. 
> AV_FIELD_BB and AV_FIELD_TT tries to signal field order for separate 
> field encodings, but quite possibly sometimes (mis)used for ordinary 
> field order signalling as well...
>
As I understand it the FFmpeg enum definitions follow the original 
(wrong) QuickTime spec wording. The actual usage in code then sometimes 
follows the documentation text (coded vs. displayed timing), and in 
other cases uses the enum to indicate field storage (interlaced vs. 
separate).
>> I guess my question is:  if I submit patches which fix such cases
>> where I find them, will they be rejected because they are a change in
>> behavior and might very well break existing applications that expect
>> the incorrect values?  I would like the libraries to report the
>> correct values in a consistent manner, but I recognize this may cause
>> some breakage in existing applications.
>
> Making changes out of the blue likely won't be acceptable. If a
> justified plan is presented to untangle this, then maybe *some* 
> breakage is acceptable, but I don't honestly know.
>
> Some random ideas:
>
> - Consider fixing the documentation (and the textual description of the
>   field orders) instead of changing behaviour.
> - Try to collect commercial samples and see what they contain for TFF/BFF
>   content, separete fields or interleaved, compressed or
>   uncompressed.
> - Go over the codebase and see which component is using which
>   interpretation in practice, make a list, see if there is a significant
>   majority...

I agree that fixing the mess would require some effort to clarify for 
each context (codec, muxer) where the AVFieldOrder enum is used what the 
interpretation is with different third-party applications, and whether 
it matches its own spec or not. Only relying on specs would not be 
enough, as the incorrect wording from QuickTime could be copied (see 
Matroska) but not used in practice.

It would be nice, though, to get the confusing "bottom coded first 
(swapped)" log message fixed into "top first (interlaced)"!

Regards,
Tobias

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-25  6:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-22 21:03 [FFmpeg-devel] Inconsistent usage of AVFieldOrder values Devin Heitmueller
2024-04-24 22:42 ` Marton Balint
2024-04-25  6:58   ` Tobias Rapp

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git