[PATCH] deinterlace & chapters enabled adds bogus chapte
Posted: Wed Aug 29, 2007 8:08 am
Using any of the good deinterlacers ("slow/slower/...") with chapter marks enabled can output double the number of chapter marks present in the source material with the bogus extras appearing slightly before the real chapter break. The problem is that hb_deinterlace_work can internally buffer frames. It correctly manages the buf_out new_chap flag so the flag is on the right buffer when sent upstream to the encoder but, unfortunately, work_loop doesn't know that frames are being delayed and it always blindly copies any non-zero new_chap from buf_in to buf_out. Since the buf_out returned by hb_deinterlace_work is usually an earlier delayed frame you end up with an extra chapter mark slightly ahead of the real one. [detelecine also delays frames and can potentially have the same problem but I haven't tested it.]
A quick fix (attached) is to make hb_deinterlace_work clear buf_in->new_chap when it delays frames. A better fix might be to remove the lines in work_loop that copy new_chap from buf_in to buf_out and instead explicitly copy new_chap from buf_in to buf_out in all the video encoder modules (enc{x264,avcodec,xvid}Work). Since encx264Work in particular can also delay frames (when using bidirectional b frames) this would prevent it adding bogus chapter marks if quicktime ever evolves to the point that we're routinely using bidirectional B's.
A quick fix (attached) is to make hb_deinterlace_work clear buf_in->new_chap when it delays frames. A better fix might be to remove the lines in work_loop that copy new_chap from buf_in to buf_out and instead explicitly copy new_chap from buf_in to buf_out in all the video encoder modules (enc{x264,avcodec,xvid}Work). Since encx264Work in particular can also delay frames (when using bidirectional b frames) this would prevent it adding bogus chapter marks if quicktime ever evolves to the point that we're routinely using bidirectional B's.
Code: Select all
Index: libhb/deinterlace.c
===================================================================
--- libhb/deinterlace.c (revision 889)
+++ libhb/deinterlace.c (working copy)
@@ -65,7 +65,7 @@
int height,
char * settings );
-int hb_deinterlace_work( const hb_buffer_t * buf_in,
+int hb_deinterlace_work( hb_buffer_t * buf_in,
hb_buffer_t ** buf_out,
int pix_fmt,
int width,
@@ -497,7 +497,7 @@
free( pv );
}
-int hb_deinterlace_work( const hb_buffer_t * buf_in,
+int hb_deinterlace_work( hb_buffer_t * buf_in,
hb_buffer_t ** buf_out,
int pix_fmt,
int width,
@@ -552,6 +552,9 @@
hb_buffer_copy_settings( pv->buf_settings, buf_in );
+ /* don't let 'work_loop' send a chapter mark upstream */
+ buf_in->new_chap = 0;
+
pv->yadif_ready = 1;
return FILTER_DELAY;
@@ -589,6 +592,9 @@
/* Replace buffered settings with input buffer settings */
hb_buffer_copy_settings( pv->buf_settings, buf_in );
+ /* don't let 'work_loop' send a chapter mark upstream */
+ buf_in->new_chap = 0;
+
return FILTER_OK;
}