Commit 044dfd9b authored by Jan Gerber's avatar Jan Gerber
Browse files

compute and include oshash of source as comment and output in --info

parent c670fdb9
......@@ -269,6 +269,40 @@ static void json_stream_format(FILE *output, AVFormatContext *ic, int i) {
}
}
/*
* 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 @@ void json_format_info(FILE* output, AVFormatContext *ic, const char *url) {
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");
}
......
#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
......@@ -2132,6 +2132,7 @@ int main(int argc, char **argv) {
}
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);
......
......@@ -282,6 +282,9 @@ void oggmux_init (oggmux_info *info) {
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 @@ void oggmux_init (oggmux_info *info) {
/* 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 @@ void oggmux_init (oggmux_info *info) {
/* 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);
......
......@@ -60,6 +60,7 @@ typedef struct
/* the file the mixed ogg stream is written to */
FILE *outfile;
char oshash[16];
int audio_only;
int video_only;
int with_skeleton;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment