[xiph-commits] r10563 - trunk/ffmpeg2theora

j at svn.xiph.org j at svn.xiph.org
Wed Dec 7 11:04:07 PST 2005


Author: j
Date: 2005-12-07 11:04:05 -0800 (Wed, 07 Dec 2005)
New Revision: 10563

Modified:
   trunk/ffmpeg2theora/theorautils.c
   trunk/ffmpeg2theora/theorautils.h
Log:
rework the manual ogg page flushing again:
  dont create theora pages with more than 23 packets.
this is only relevant for monochrom/static scenes, like back with little txt.
resuling files are a bit bigger, but seeking is faster.
tested with: 
  vlc, totem-gstreamer, wmp9(illi's ds filters)



Modified: trunk/ffmpeg2theora/theorautils.c
===================================================================
--- trunk/ffmpeg2theora/theorautils.c	2005-12-07 15:11:48 UTC (rev 10562)
+++ trunk/ffmpeg2theora/theorautils.c	2005-12-07 19:04:05 UTC (rev 10563)
@@ -30,6 +30,8 @@
 
 #include "theorautils.h"
 
+
+
 static double rint(double x)
 {
   if (x < 0.0)
@@ -50,6 +52,12 @@
     info->videopage_buffer_length = 0;
     info->audiopage = NULL;
     info->videopage = NULL;
+    info->v_pkg=0;
+    info->a_pkg=0;
+#ifdef OGGMUX_DEBUG
+    info->a_page=0;
+    info->v_page=0;
+#endif
 }
 
 void oggmux_init (oggmux_info *info){
@@ -178,6 +186,7 @@
     theora_encode_YUVin (&info->td, yuv);
     while(theora_encode_packetout (&info->td, e_o_s, &op)) {
       ogg_stream_packetin (&info->to, &op);
+      info->v_pkg++;
     }
 }
     
@@ -216,6 +225,7 @@
         /* weld packets into the bitstream */
         while (vorbis_bitrate_flushpacket (&info->vd, &op)){
             ogg_stream_packetin (&info->vo, &op);
+            info->a_pkg++;
         }
     }
 }
@@ -242,6 +252,12 @@
     info->audio_bytesout += ret;
   }
   info->audiopage_valid = 0;
+  info->a_pkg -=ogg_page_packets((ogg_page *)&info->audiopage);
+#ifdef OGGMUX_DEBUG
+  info->a_page++;
+  info->v_page=0;
+  fprintf(stderr,"\naudio page %d (%d pkgs) | pkg remaining %d\n",info->a_page,ogg_page_packets((ogg_page *)&info->audiopage),info->a_pkg);
+#endif
 
   info->akbps = rint (info->audio_bytesout * 8. / info->audiotime * .001);
   if(info->akbps<0)
@@ -261,7 +277,14 @@
     info->video_bytesout += ret;
   }
   info->videopage_valid = 0;
+  info->v_pkg -= ogg_page_packets((ogg_page *)&info->videopage);
+#ifdef OGGMUX_DEBUG
+  info->v_page++;
+  info->a_page=0;
+  fprintf(stderr,"\nvideo page %d (%d pkgs) | pkg remaining %d\n",info->v_page,ogg_page_packets((ogg_page *)&info->videopage),info->v_pkg);
+#endif
 
+
   info->vkbps = rint (info->video_bytesout * 8. / info->videotime * .001);
   if(info->vkbps<0)
     info->vkbps=0;
@@ -277,12 +300,16 @@
     while(1) {
       /* Get pages for both streams, if not already present, and if available.*/
       if(!info->audio_only && !info->videopage_valid) {
-
-        // flush a page each frame;
-        // this way seeking is much better, possibly there is a way to 
-        // do this better, but for now this works.
-//        if(ogg_stream_pageout(&info->to, &og) > 0) {
-        if(ogg_stream_flush(&info->to, &og) > 0) {
+        // this way seeking is much better,
+        // not sure if 23 packets  is a good value. it works though
+        int v_next=0;
+        if(info->v_pkg>22 && ogg_stream_flush(&info->to, &og) > 0) {
+          v_next=1;
+        }
+        else if(ogg_stream_pageout(&info->to, &og) > 0) {
+          v_next=1;
+        }
+        if(v_next) {
           len = og.header_len + og.body_len;
           if(info->videopage_buffer_length < len) {
             info->videopage = realloc(info->videopage, len);

Modified: trunk/ffmpeg2theora/theorautils.h
===================================================================
--- trunk/ffmpeg2theora/theorautils.h	2005-12-07 15:11:48 UTC (rev 10562)
+++ trunk/ffmpeg2theora/theorautils.h	2005-12-07 19:04:05 UTC (rev 10563)
@@ -24,6 +24,7 @@
 #include "vorbis/vorbisenc.h"
 #include "ogg/ogg.h"
 
+// #define OGGMUX_DEBUG
 
 typedef struct
 {
@@ -73,6 +74,14 @@
     int akbps;
     ogg_int64_t audio_bytesout;
     ogg_int64_t video_bytesout;
+
+    //to do some manual page flusing
+    int v_pkg;
+    int a_pkg;
+#ifdef OGGMUX_DEBUG
+    int a_page;
+    int v_page;
+#endif
 }
 oggmux_info;
 



More information about the commits mailing list