[xiph-commits] r11715 - trunk/ffmpeg2theora

j at svn.xiph.org j at svn.xiph.org
Mon Jul 24 09:40:36 PDT 2006


Author: j
Date: 2006-07-24 09:40:22 -0700 (Mon, 24 Jul 2006)
New Revision: 11715

Modified:
   trunk/ffmpeg2theora/ffmpeg2theora.c
   trunk/ffmpeg2theora/theorautils.c
   trunk/ffmpeg2theora/theorautils.h
Log:
calculate and display remaning time.

Modified: trunk/ffmpeg2theora/ffmpeg2theora.c
===================================================================
--- trunk/ffmpeg2theora/ffmpeg2theora.c	2006-07-21 17:09:30 UTC (rev 11714)
+++ trunk/ffmpeg2theora/ffmpeg2theora.c	2006-07-24 16:40:22 UTC (rev 11715)
@@ -1,7 +1,7 @@
 /* -*- tab-width:4;c-file-style:"cc-mode"; -*- */
 /*
  * ffmpeg2theora.c -- Convert ffmpeg supported a/v files to  Ogg Theora / Ogg Vorbis
- * Copyright (C) 2003-2005 <j at v2v.cc>
+ * Copyright (C) 2003-2006 <j at v2v.cc>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -1275,6 +1275,9 @@
                     fprintf (stderr,"\nUnable to open output file %s\n", outputfile_name);
                     return(1);
                 }
+                if (convert->context->duration != AV_NOPTS_VALUE) {
+                  info.duration = convert->context->duration / AV_TIME_BASE;
+                }
                 ff2theora_output (convert);
                 convert->audio_index =convert->video_index = -1;
             }

Modified: trunk/ffmpeg2theora/theorautils.c
===================================================================
--- trunk/ffmpeg2theora/theorautils.c	2006-07-21 17:09:30 UTC (rev 11714)
+++ trunk/ffmpeg2theora/theorautils.c	2006-07-24 16:40:22 UTC (rev 11715)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#include <time.h>
 
 #include "theora/theora.h"
 #include "vorbis/codec.h"
@@ -53,6 +54,9 @@
     info->videopage_buffer_length = 0;
     info->audiopage = NULL;
     info->videopage = NULL;
+    info->start_time = time(NULL);
+    info->duration = -1;
+    
     info->v_pkg=0;
     info->a_pkg=0;
 #ifdef OGGMUX_DEBUG
@@ -363,14 +367,35 @@
     }
 }
 
+static double get_remaining(oggmux_info *info, double timebase) {
+  double remaining = 0;
+  double to_encode, time_so_far;
+  
+  if(info->duration != -1 && timebase > 0) {
+    time_so_far = time(NULL) - info->start_time;
+    to_encode = info->duration - timebase;
+    if(to_encode > 0) {
+      remaining = (time_so_far / timebase) * to_encode;
+    }
+  }
+  return remaining;
+}
+
 static void print_stats(oggmux_info *info, double timebase){
     int hundredths = timebase * 100 - (long) timebase * 100;
     int seconds = (long) timebase % 60;
     int minutes = ((long) timebase / 60) % 60;
     int hours = (long) timebase / 3600;
-
-    fprintf (stderr,"\r      %d:%02d:%02d.%02d audio: %dkbps video: %dkbps                  ",
-         hours, minutes, seconds, hundredths,info->akbps, info->vkbps);
+    double remaining = get_remaining(info, timebase);
+    int remaining_seconds = (long) remaining % 60;
+    int remaining_minutes = ((long) remaining / 60) % 60;
+    int remaining_hours = (long) remaining / 3600;
+    
+    fprintf (stderr,"\r      %d:%02d:%02d.%02d audio: %dkbps video: %dkbps, time remaining: %02d:%02d:%02d      ",
+         hours, minutes, seconds, hundredths,
+         info->akbps, info->vkbps,
+         remaining_hours, remaining_minutes, remaining_seconds
+         );
 }
 
 static int write_audio_page(oggmux_info *info)

Modified: trunk/ffmpeg2theora/theorautils.h
===================================================================
--- trunk/ffmpeg2theora/theorautils.h	2006-07-21 17:09:30 UTC (rev 11714)
+++ trunk/ffmpeg2theora/theorautils.h	2006-07-24 16:40:22 UTC (rev 11715)
@@ -80,10 +80,13 @@
     /* some stats */
     double audiotime;
     double videotime;
+    double duration;
+    
     int vkbps;
     int akbps;
     ogg_int64_t audio_bytesout;
     ogg_int64_t video_bytesout;
+    time_t start_time;
 
     //to do some manual page flusing
     int v_pkg;



More information about the commits mailing list