- /* Comment */
- theora_comment_init(&t_comment);
- theora_encode_comment(&t_comment, &o_packet);
- if (concatenate_packet(&offset, avc_context, &o_packet))
- return -1;
- /* Clear up theora_comment struct before we reset the packet */
- theora_comment_clear(&t_comment);
- /* And despite documentation to the contrary, theora_comment_clear
- * does not release the packet */
- ogg_packet_clear(&o_packet);
-
- /* Tables */
- theora_encode_tables(&(h->t_state), &o_packet);
- if (concatenate_packet(&offset, avc_context, &o_packet))
- return -1;
+ while (th_encode_flushheader(h->t_state, &t_comment, &o_packet))
+ if (concatenate_packet(&offset, avc_context, &o_packet))
+ return -1;
+
+ th_comment_clear(&t_comment);