This commit is contained in:
猪小乐 2023-06-15 14:37:18 +00:00
parent bc768006b4
commit c0ffea2773

View File

@ -232,7 +232,7 @@ int open_file_avis( char *psz_filename, avis_input_t **p_handle, stream_info_t *
p_param->i_fps_den = info.dwScale; p_param->i_fps_den = info.dwScale;
p_param->i_fps_num = info.dwRate; p_param->i_fps_num = info.dwRate;
fprintf( stderr, "avis [info]: %dx%d @ %.3f fps (%d frames)\n", fprintf( stdout, "avis [info]: %dx%d @ %.3f fps (%d frames)\n",
p_param->i_width, p_param->i_height, p_param->i_width, p_param->i_height,
(double)p_param->i_fps_num / (double)p_param->i_fps_den, (double)p_param->i_fps_num / (double)p_param->i_fps_den,
(int)info.dwLength ); (int)info.dwLength );
@ -529,9 +529,9 @@ int detect_sse2 ()
detection = (edx & 0x04000000) ? 1 : 0; detection = (edx & 0x04000000) ? 1 : 0;
if (detection) if (detection)
fprintf(stderr, "CPU: Using SSE2 optimized functions.\n"); fprintf(stdout, "CPU: Using SSE2 optimized functions.\n");
else else
fprintf(stderr, "CPU: Using pure C functions.\n"); fprintf(stdout, "CPU: Using pure C functions.\n");
return detection; return detection;
} }
@ -598,7 +598,7 @@ void mk_timecode (int frame, int fps, char *buf) /* buf must have length 12 (inc
void print_usage () void print_usage ()
{ {
fprintf(stderr, fprintf(stdout,
"avs2bdnxml 2.09\n\n" "avs2bdnxml 2.09\n\n"
"Usage: avs2bdnxml [options] -o output input\n\n" "Usage: avs2bdnxml [options] -o output input\n\n"
"Input has to be an AviSynth script with RGBA as output colorspace\n\n" "Input has to be an AviSynth script with RGBA as output colorspace\n\n"
@ -909,7 +909,7 @@ int main (int argc, char *argv[])
else else
{ {
fprintf(stderr, "No more than two output filenames allowed.\nIf more than one is used, the other must have a\ndifferent output format.\n"); fprintf(stderr, "No more than two output filenames allowed.\nIf more than one is used, the other must have a\ndifferent output format.\n");
exit(0); exit(1);
} }
break; break;
case 'r': case 'r':
@ -1016,7 +1016,7 @@ int main (int argc, char *argv[])
if (sup_output > 1 || xml_output > 1) if (sup_output > 1 || xml_output > 1)
{ {
fprintf(stderr, "If more than one output filename is used, they must have\ndifferent output formats.\n"); fprintf(stderr, "If more than one output filename is used, they must have\ndifferent output formats.\n");
exit(0); exit(1);
} }
/* Set X and Y offsets, and split value */ /* Set X and Y offsets, and split value */
@ -1030,8 +1030,9 @@ int main (int argc, char *argv[])
allow_empty = parse_int(allow_empty_string, "null-xml", NULL); allow_empty = parse_int(allow_empty_string, "null-xml", NULL);
stricter = parse_int(stricter_string, "stricter", NULL); stricter = parse_int(stricter_string, "stricter", NULL);
min_split = parse_int(minimum_split, "min-split", NULL); min_split = parse_int(minimum_split, "min-split", NULL);
if (!min_split) if (!min_split) {
min_split = 1; min_split = 1;
}
mark_forced = parse_int(mark_forced_string, "forced", NULL); mark_forced = parse_int(mark_forced_string, "forced", NULL);
/* TODO: Sanity check video_format and frame_rate. */ /* TODO: Sanity check video_format and frame_rate. */
@ -1087,6 +1088,7 @@ int main (int argc, char *argv[])
/* Set up buffer (non-)optimization */ /* Set up buffer (non-)optimization */
buffer_opt = parse_int(buffer_optimize, "buffer-opt", NULL); buffer_opt = parse_int(buffer_optimize, "buffer-opt", NULL);
pic.b = out_buf; pic.b = out_buf;
pic.w = s_info->i_width; pic.w = s_info->i_width;
pic.h = s_info->i_height; pic.h = s_info->i_height;
@ -1158,62 +1160,70 @@ int main (int argc, char *argv[])
checked_empty = 0; checked_empty = 0;
/* Progress indicator */ /* Progress indicator */
fprintf(stderr, "\rProgress: %d/%d - Lines: %d", i - init_frame + before_range_frame_count, range_frame_count, num_of_events); fprintf(stdout, "\rProgress: %d/%d - Lines: %d", i - init_frame + before_range_frame_count, range_frame_count, num_of_events);
/* If we are outside any lines, check for empty frames first */ /* If we are outside any lines, check for empty frames first */
if (!have_line) if (!have_line)
{ {
if (is_empty(s_info, in_img)) if (is_empty(s_info, in_img)) {
continue; continue;
else }
else {
checked_empty = 1; checked_empty = 1;
} }
}
/* Check for duplicate, unless first frame */ /* Check for duplicate, unless first frame */
if ((i != init_frame) && have_line && is_identical(s_info, in_img, old_img)) if ((i != init_frame) && have_line && is_identical(s_info, in_img, old_img)) {
continue; continue;
}
/* Mark frames that were not used as new image in comparison to have transparent pixels zeroed */ /* Mark frames that were not used as new image in comparison to have transparent pixels zeroed */
else if (!(i && have_line)) else if (!(i && have_line)) {
must_zero = 1; must_zero = 1;
}
/* Not a dup, write end-of-line, if we had a line before */ /* Not a dup, write end-of-line, if we had a line before */
if (have_line) if (have_line)
{ {
end_frame = i - 1;
have_line = 0;
if (sup_output) if (sup_output)
{ {
assert(pal != NULL); assert(pal != NULL);
write_sup_wrapper(sw, (uint8_t *)out_buf, n_crop, crops, pal, start_frame + to, i + to, split_at, min_split, stricter, mark_forced); write_sup_wrapper(sw, (uint8_t *)out_buf, n_crop, crops, pal, start_frame + to, end_frame + to, split_at, min_split, stricter, mark_forced);
if (!xml_output)
{
free(pal);
pal = NULL;
}
} }
if (xml_output) if (xml_output)
{ {
add_event_xml(events, split_at, min_split, start_frame + to, i + to, n_crop, crops, mark_forced); add_event_xml(events, split_at, min_split, start_frame + to, end_frame + to, n_crop, crops, mark_forced);
}
if (pal != NULL) {
free(pal); free(pal);
pal = NULL; pal = NULL;
} }
end_frame = i;
have_line = 0;
} }
/* Check for empty frame, if we didn't before */ /* Check for empty frame, if we didn't before */
if (!checked_empty && is_empty(s_info, in_img)) if (!checked_empty && is_empty(s_info, in_img)) {
continue; continue;
}
/* Zero transparent pixels, if needed */ /* Zero transparent pixels, if needed */
if (must_zero) if (must_zero) {
zero_transparent(s_info, in_img); zero_transparent(s_info, in_img);
}
must_zero = 0; must_zero = 0;
/* Not an empty frame, start line */ /* Not an empty frame, start line */
have_line = 1; have_line = 1;
start_frame = i; start_frame = i;
swap_rb(s_info, in_img, out_buf); swap_rb(s_info, in_img, out_buf);
if (buffer_opt) if (buffer_opt) {
n_crop = auto_split(pic, crops, ugly, even_y); n_crop = auto_split(pic, crops, ugly, even_y);
}
else if (autocrop) else if (autocrop)
{ {
crops[0].x = 0; crops[0].x = 0;
@ -1222,21 +1232,26 @@ int main (int argc, char *argv[])
crops[0].h = pic.h; crops[0].h = pic.h;
auto_crop(pic, crops); auto_crop(pic, crops);
} }
if ((buffer_opt || autocrop) && even_y) if ((buffer_opt || autocrop) && even_y) {
enforce_even_y(crops, n_crop); enforce_even_y(crops, n_crop);
if ((pal_png || sup_output) && pal == NULL) }
if ((pal_png || sup_output) && pal == NULL) {
pal = palletize(out_buf, s_info->i_width, s_info->i_height); pal = palletize(out_buf, s_info->i_width, s_info->i_height);
if (xml_output) }
for (j = 0; j < n_crop; j++) if (xml_output) {
for (j = 0; j < n_crop; j++) {
write_png(png_dir, start_frame, (uint8_t *)out_buf, s_info->i_width, s_info->i_height, j, pal, crops[j]); write_png(png_dir, start_frame, (uint8_t *)out_buf, s_info->i_width, s_info->i_height, j, pal, crops[j]);
if (pal_png && xml_output && !sup_output) }
}
if (pal_png && xml_output && !sup_output && pal != NULL)
{ {
free(pal); free(pal);
pal = NULL; pal = NULL;
} }
num_of_events++; num_of_events++;
if (first_frame == -1) if (first_frame <= 0) {
first_frame = i; first_frame = i;
}
/* Save image for next comparison. */ /* Save image for next comparison. */
tmp = in_img; tmp = in_img;
@ -1245,33 +1260,33 @@ int main (int argc, char *argv[])
} }
before_range_frame_count += i - init_frame; before_range_frame_count += i - init_frame;
fprintf(stderr, "\rProgress: %d/%d - Lines: %d", before_range_frame_count, range_frame_count, num_of_events); fprintf(stdout, "\rProgress: %d/%d - Lines: %d", before_range_frame_count, range_frame_count, num_of_events);
/* Add last event, if available */ /* Add last event, if available */
if (have_line) if (have_line)
{ {
auto_cut = 1;
end_frame = i - 1;
if (sup_output) if (sup_output)
{ {
assert(pal != NULL); assert(pal != NULL);
write_sup_wrapper(sw, (uint8_t *)out_buf, n_crop, crops, pal, start_frame + to, i - 1 + to, split_at, min_split, stricter, mark_forced); write_sup_wrapper(sw, (uint8_t *)out_buf, n_crop, crops, pal, start_frame + to, end_frame + to, split_at, min_split, stricter, mark_forced);
if (!xml_output)
{
free(pal);
pal = NULL;
}
} }
if (xml_output) if (xml_output)
{ {
add_event_xml(events, split_at, min_split, start_frame + to, i - 1 + to, n_crop, crops, mark_forced); add_event_xml(events, split_at, min_split, start_frame + to, end_frame + to, n_crop, crops, mark_forced);
}
if (pal != NULL) {
free(pal); free(pal);
pal = NULL; pal = NULL;
} }
auto_cut = 1;
end_frame = i - 1;
} }
} }
fprintf(stderr, "\n"); fprintf(stdout, "\n");
if (sup_output) if (sup_output)
{ {
@ -1281,12 +1296,12 @@ int main (int argc, char *argv[])
if (xml_output) if (xml_output)
{ {
/* Check if we actually have any events */ /* Check if we actually have any events */
if (first_frame == -1) if (first_frame <= 0)
{ {
if (!allow_empty) if (!allow_empty)
{ {
fprintf(stderr, "No events detected. Cowardly refusing to write XML file.\n"); fprintf(stderr, "No events detected. Cowardly refusing to write XML file.\n");
return 0; return 1;
} }
else else
{ {
@ -1361,8 +1376,10 @@ int main (int argc, char *argv[])
fclose(ranges_fp); fclose(ranges_fp);
/* Give runtime */ /* Give runtime */
if (0) if (0) {
fprintf(stderr, "Time elapsed: %lu\n", time(NULL) - bench_start); fprintf(stdout, "Time elapsed: %lu\n", time(NULL) - bench_start);
}
return 0; return 0;
} }