Opened 10 years ago

Last modified 8 years ago

#1786 new defect

unable to set xvidenc flag XVID_VOP_TOPFIELDFIRST

Reported by: jarekczek@… Owned by: reimar
Priority: normal Component: ve
Version: 1.0rc4 Severity: normal
Keywords: Cc: jarekczek@…, Dr.O.Muth@…, jaycee@…
Blocked By: Blocking:
Reproduced by developer: Analyzed by developer:


If we're using "interlacing" xvidenc flag, we should be able to specify the field order. Default in xvid is "bottom field first". We can change it with the XVID_VOP_TOPFIELDFIRST flag.

If I don't specify the TFF flag, I'm not able to play the video in my stationary dvd player (CH DVD-462). Movement is jumpy.

If I change the code in ve_xvid4.c like this:

if(xvidenc_interlaced && (selected_profile->flags & PROFILE_INTERLACE)) {

frame->vol_flags |= XVID_VOL_INTERLACING;
frame->vop_flags |= XVID_VOP_TOPFIELDFIRST; this is my new line


then the video is excellent.

Please someone make this change in a suitable manner, through the proper command line switch and with the manual update. Xvid clears the tff flag if "interlacing" is not on. Not sure if we should report an error when the users specifies non-int and tff together.

By the way, if I understood the xvid code correctly: xvid ignores this flag but passes it to the bitstream to allow the player to know which field order is used.

Attachments (2)

xvid_tff.diff (642 bytes) - added by reimar 10 years ago.
Set TFF flag for xvid the same way as for lavc
top_option_20110523.diff (2.2 KB) - added by jarekczek@… 9 years ago.
patch - manual top option for xvid

Download all attachments as: .zip

Change History (11)

comment:1 Changed 10 years ago by jarekczek@…

  • Cc jarekczek@… added

Changed 10 years ago by reimar

Set TFF flag for xvid the same way as for lavc

comment:2 Changed 10 years ago by reimar

Try this patch, it uses the same method as libavcodec (except not allowing to override via codec options).
Note I do not have xvid installed so it might not even compile as-is, but I guess you can do any necessary fixes on your own.
And you might consider just using libavcodec...

comment:3 Changed 10 years ago by jarekczek@…

Reimar, so the suitable option would be -field-dominance, right? But we would be making here a big change, because xvid's default is BFF and mplayers default is TFF (it is said so in the manual). So after applying this patch all users making interlaced encoding on xvid may fall into a big surprise.

Anyway I'll test this solution.

comment:4 Changed 10 years ago by jarekczek@…

It doesn't work in this way. Your suggestion was to rely on flags:

I see no way to set the first 2 of them. Looks like it's decoder dependent. Wouldn't it be better to make it independent of the decoder?

Somehow MP_IMGFIELD_TOP_FIRST gets lost when the 2 others or not set: when we get into set_frame_struct its value is always zero.

Could you advice me how to read directly -field-dominance parameter value in the dispatch_settings of xvid? Of course if it makes sense for you to do it this way.

comment:5 Changed 10 years ago by jarekczek@…

I'm working on this. Will join these 2 approaches and supply the diff.

comment:6 Changed 10 years ago by jarekczek@…

Well, maybe not.

That's how it goes.

  1. Decoder can set field interlacing flags (MP_IMGFIELD_ORDERED, MP_IMGFIELD_INTERLACED, MP_IMGFIELD_TOP_FIRST). A few do this. vd_raw for example does not.
  1. For the decoders that don't supply the interlacing flags, one can set the flag MP_IMGFIELD_TOP_FIRST through the field-dominance switch. There is no switch to set the 2 other flags, so the field-dominance switch is made almost useless
  1. Ffmpeg encoder has the switch "top" which has greater priority than the decoder flags. Xvidenc has no such switch.

So what to do:

  1. create a flag "top" for xvid
  2. create a decoder switch to fill the interlaced flags of the input stream - many encoders could benefit from this
  3. make xvid rely on field interlacing flags (but the priority of A. is greater, as in lavc)
  4. make it possible that mplayer shows this flags when playing back (hard to do because these flags are read only after "Starting playback"). Few tools show it and some video forum people even deny the existance of them.

I can do these things, except the fine solution for D. Just tell me and maybe give the flags' names.

If this bug entry became my own blog without being read nor answered from anyone, then I'll post only the A. fix.

comment:7 Changed 9 years ago by Dr.O.Muth@…

  • Cc Dr.O.Muth@… added

For what it's worth, I would very much appreciate solution A.

Of course it would be nice to have the decoder automagically pass on its flag to the decoder, but I guess that's more work, and most users probably have just one type of videos they encode: either bff (then they don't need the switch anyway) or tff, in which case they could simply define the new "top" flag in their standard profile.

Changed 9 years ago by jarekczek@…

patch - manual top option for xvid

comment:8 Changed 9 years ago by jarekczek@…

comment:9 Changed 8 years ago by jaycee@…

  • Cc jaycee@… added

Recently I stumbled over the same issue with my standalone dvd player and it took me ages to figure out what was wrong. Applying the patch Jarek posted on the mailing-list fixed the jittering completely for me. Hence, I strongly recommend applying some variation of this patch and changing the default behaviour of xvid encoding to copy the field dominance of the interlaced source material.

Note: See TracTickets for help on using tickets.