[xiph-commits] r16012 - trunk/ffmpeg2theora/src

j at svn.xiph.org j at svn.xiph.org
Mon May 18 08:54:52 PDT 2009


Author: j
Date: 2009-05-18 08:54:51 -0700 (Mon, 18 May 2009)
New Revision: 16012

Modified:
   trunk/ffmpeg2theora/src/avinfo.c
   trunk/ffmpeg2theora/src/avinfo.h
   trunk/ffmpeg2theora/src/ffmpeg2theora.c
   trunk/ffmpeg2theora/src/theorautils.c
   trunk/ffmpeg2theora/src/theorautils.h
Log:
compute and include oshash of source as comment and output in --info

Modified: trunk/ffmpeg2theora/src/avinfo.c
===================================================================
--- trunk/ffmpeg2theora/src/avinfo.c	2009-05-17 20:07:44 UTC (rev 16011)
+++ trunk/ffmpeg2theora/src/avinfo.c	2009-05-18 15:54:51 UTC (rev 16012)
@@ -269,6 +269,40 @@
     }
 }
 
+/* 
+ * os hash
+ * based on public domain example from
+ * http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes   
+ * -works only on little-endian procesor DEC, Intel and compatible
+ * -sizeof(unsigned long long) must be 8
+ */
+unsigned long long gen_oshash(char const *filename) {
+    FILE *file;
+    int i;
+    unsigned long long t1=0;
+    unsigned long long buffer1[8192*2];
+
+
+    file = fopen(filename, "rb");
+    if (file) {
+        fread(buffer1, 8192, 8, file);
+        fseek(file, -65536, SEEK_END);
+        fread(&buffer1[8192], 8192, 8, file); 
+        for (i=0; i < 8192*2; i++)
+            t1+=buffer1[i];
+        t1+= ftell(file); //add filesize
+        fclose(file);
+    }
+    return t1;
+}
+
+void json_oshash(FILE *output, char const *filename) {
+    char hash[16];
+    sprintf(hash,"%qx", gen_oshash(filename));
+    json_add_key_value(output, "oshash", (void *)hash, JSON_STRING, 0);
+}
+
+
 /* "user interface" functions */
 void json_format_info(FILE* output, AVFormatContext *ic, const char *url) {
     int i;
@@ -299,9 +333,11 @@
             json_stream_format(output, ic, i);
         }
     }
+    json_oshash(output, url);
     json_add_key_value(output, "path", (void *)url, JSON_STRING, 0);
     filesize = get_filesize(url);
     json_add_key_value(output, "size", &filesize, JSON_LONG, 1);
+
     fprintf(output, "}\n");
 }
 

Modified: trunk/ffmpeg2theora/src/avinfo.h
===================================================================
--- trunk/ffmpeg2theora/src/avinfo.h	2009-05-17 20:07:44 UTC (rev 16011)
+++ trunk/ffmpeg2theora/src/avinfo.h	2009-05-18 15:54:51 UTC (rev 16012)
@@ -1,6 +1,7 @@
 #ifndef _F2T_AVINFO_H_
 #define _F2T_AVINFO_H_
 
+unsigned long long gen_oshash(char const *filename);
 void json_format_info(FILE* output, AVFormatContext *ic, const char *url);
 
 #endif

Modified: trunk/ffmpeg2theora/src/ffmpeg2theora.c
===================================================================
--- trunk/ffmpeg2theora/src/ffmpeg2theora.c	2009-05-17 20:07:44 UTC (rev 16011)
+++ trunk/ffmpeg2theora/src/ffmpeg2theora.c	2009-05-18 15:54:51 UTC (rev 16012)
@@ -2132,6 +2132,7 @@
     }
     if (av_open_input_file(&convert->context, inputfile_name, input_fmt, 0, formatParams) >= 0) {
         if (av_find_stream_info(convert->context) >= 0) {
+                sprintf(info.oshash,"%qx", gen_oshash(inputfile_name));
 #ifdef WIN32
                 if (!strcmp(outputfile_name,"-") || !strcmp(outputfile_name,"/dev/stdout")) {
                     _setmode(_fileno(stdout), _O_BINARY);

Modified: trunk/ffmpeg2theora/src/theorautils.c
===================================================================
--- trunk/ffmpeg2theora/src/theorautils.c	2009-05-17 20:07:44 UTC (rev 16011)
+++ trunk/ffmpeg2theora/src/theorautils.c	2009-05-18 15:54:51 UTC (rev 16012)
@@ -282,6 +282,9 @@
 
         vorbis_comment_init (&info->vc);
         vorbis_comment_add_tag (&info->vc, "ENCODER",PACKAGE_STRING);
+        if (strcmp(info->oshash,"0") > 0) {
+            vorbis_comment_add_tag (&info->vc, "SOURCE_OSHASH", info->oshash);
+        }
         /* set up the analysis state and auxiliary encoding storage */
         vorbis_analysis_init (&info->vd, &info->vi);
         vorbis_block_init (&info->vd, &info->vb);
@@ -329,6 +332,7 @@
 
     /* first packet will get its own page automatically */
     if (!info->audio_only) {
+
         theora_encode_header (&info->td, &op);
         ogg_stream_packetin (&info->to, &op);
         if (ogg_stream_pageout (&info->to, &og) != 1) {
@@ -341,6 +345,9 @@
         /* create the remaining theora headers */
         /* theora_comment_init (&info->tc); is called in main() prior to parsing options */
         theora_comment_add_tag (&info->tc, "ENCODER",PACKAGE_STRING);
+        if (strcmp(info->oshash,"0") > 0) {
+            theora_comment_add_tag (&info->tc, "SOURCE_OSHASH", info->oshash);
+        }
         theora_encode_comment (&info->tc, &op);
         ogg_stream_packetin (&info->to, &op);
         _ogg_free (op.packet);

Modified: trunk/ffmpeg2theora/src/theorautils.h
===================================================================
--- trunk/ffmpeg2theora/src/theorautils.h	2009-05-17 20:07:44 UTC (rev 16011)
+++ trunk/ffmpeg2theora/src/theorautils.h	2009-05-18 15:54:51 UTC (rev 16012)
@@ -60,6 +60,7 @@
     /* the file the mixed ogg stream is written to */
     FILE *outfile;
 
+    char oshash[16];
     int audio_only;
     int video_only;
     int with_skeleton;



More information about the commits mailing list