帧区间处理
This commit is contained in:
parent
ed7bd25157
commit
81d21ecfff
284
avs2bdnxml.c
284
avs2bdnxml.c
@ -803,6 +803,7 @@ int main (int argc, char *argv[])
|
||||
, {NULL, NULL, 0, 0, 0, 0}
|
||||
};
|
||||
char *avs_filename = NULL;
|
||||
char *ranges_filename = NULL;
|
||||
char *track_name = "Undefined";
|
||||
char *language = "und";
|
||||
char *video_format = "1080p";
|
||||
@ -820,15 +821,14 @@ int main (int argc, char *argv[])
|
||||
char *even_y_string = "0";
|
||||
char *auto_crop_image = "1";
|
||||
char *ugly_option = "0";
|
||||
char *seek_string = "0";
|
||||
char *allow_empty_string = "0";
|
||||
char *stricter_string = "0";
|
||||
char *count_string = "2147483647";
|
||||
char *in_img = NULL, *old_img = NULL, *tmp = NULL, *out_buf = NULL;
|
||||
char *intc_buf = NULL, *outtc_buf = NULL;
|
||||
char *drop_frame = NULL;
|
||||
char *mark_forced_string = "0";
|
||||
char png_dir[MAX_PATH + 1] = {0};
|
||||
FILE* ranges_fp;
|
||||
crop_t crops[2];
|
||||
pic_t pic;
|
||||
uint32_t *pal = NULL;
|
||||
@ -868,6 +868,11 @@ int main (int argc, char *argv[])
|
||||
event_list_t *events = event_list_new();
|
||||
event_t *event;
|
||||
FILE *fh;
|
||||
int range_frame_count = 0;
|
||||
char range_line_str[100];
|
||||
char range_start_str[50];
|
||||
char range_end_str[50];
|
||||
int before_range_frame_count = 0;
|
||||
|
||||
/* Get args */
|
||||
if (argc < 2)
|
||||
@ -879,8 +884,7 @@ int main (int argc, char *argv[])
|
||||
{
|
||||
static struct option long_options[] =
|
||||
{ {"output", required_argument, 0, 'o'}
|
||||
, {"seek", required_argument, 0, 'j'}
|
||||
, {"count", required_argument, 0, 'c'}
|
||||
, {"ranges-file", required_argument, 0, 'r'}
|
||||
, {"trackname", required_argument, 0, 't'}
|
||||
, {"language", required_argument, 0, 'l'}
|
||||
, {"video-format", required_argument, 0, 'v'}
|
||||
@ -902,7 +906,7 @@ int main (int argc, char *argv[])
|
||||
};
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long(argc, argv, "o:j:c:t:l:v:f:x:y:d:b:s:m:e:p:a:u:n:z:F:", long_options, &option_index);
|
||||
c = getopt_long(argc, argv, "o:r:t:l:v:f:x:y:d:b:s:m:e:p:a:u:n:z:F:", long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
switch (c)
|
||||
@ -916,11 +920,8 @@ int main (int argc, char *argv[])
|
||||
exit(0);
|
||||
}
|
||||
break;
|
||||
case 'j':
|
||||
seek_string = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
count_string = optarg;
|
||||
case 'r':
|
||||
ranges_filename = optarg;
|
||||
break;
|
||||
case 't':
|
||||
track_name = optarg;
|
||||
@ -988,7 +989,7 @@ int main (int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* Both input and output filenames are required */
|
||||
if (avs_filename == NULL)
|
||||
if (avs_filename == NULL || ranges_filename == NULL)
|
||||
{
|
||||
print_usage();
|
||||
return 0;
|
||||
@ -1036,8 +1037,6 @@ int main (int argc, char *argv[])
|
||||
ugly = parse_int(ugly_option, "ugly", NULL);
|
||||
allow_empty = parse_int(allow_empty_string, "null-xml", NULL);
|
||||
stricter = parse_int(stricter_string, "stricter", NULL);
|
||||
init_frame = parse_int(seek_string, "seek", NULL);
|
||||
count_frames = parse_int(count_string, "count", NULL);
|
||||
min_split = parse_int(minimum_split, "min-split", NULL);
|
||||
if (!min_split)
|
||||
min_split = 1;
|
||||
@ -1106,151 +1105,177 @@ int main (int argc, char *argv[])
|
||||
crops[0].w = pic.w;
|
||||
crops[0].h = pic.h;
|
||||
|
||||
/* Get frame number */
|
||||
/* Get total frame number */
|
||||
frames = get_frame_total_avis(avis_hnd);
|
||||
if (count_frames + init_frame > frames)
|
||||
{
|
||||
count_frames = frames - init_frame;
|
||||
}
|
||||
last_frame = count_frames + init_frame;
|
||||
|
||||
ranges_fp = fopen(ranges_filename, "r");
|
||||
|
||||
/* No frames mean nothing to do */
|
||||
if (count_frames < 1)
|
||||
{
|
||||
fprintf(stderr, "No frames found.\n");
|
||||
return 0;
|
||||
if (fscanf(ranges_fp, "%s", range_line_str) != EOF) {
|
||||
fprintf(stderr, "%s\n", range_line_str);
|
||||
range_frame_count = parse_int(range_line_str, "range_frame_count", NULL);
|
||||
}
|
||||
|
||||
/* Set progress step */
|
||||
if (count_frames < 1000)
|
||||
{
|
||||
if (count_frames > 200)
|
||||
progress_step = 50;
|
||||
else if (count_frames > 50)
|
||||
progress_step = 10;
|
||||
else
|
||||
progress_step = 1;
|
||||
if (range_frame_count <= 0) {
|
||||
fprintf(stderr, "Error: Error reading range_frame_count.\n");
|
||||
fclose(ranges_fp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Open SUP writer, if applicable */
|
||||
if (sup_output)
|
||||
if (sup_output) {
|
||||
sw = new_sup_writer(sup_output_fn, pic.w, pic.h, fps_num, fps_den);
|
||||
}
|
||||
|
||||
/* Process frames */
|
||||
for (i = init_frame; i < last_frame; i++)
|
||||
while (fscanf(ranges_fp, "%s %s", range_start_str, range_end_str) != EOF)
|
||||
{
|
||||
if (read_frame_avis(in_img, avis_hnd, i))
|
||||
{
|
||||
fprintf(stderr, "Error reading frame.\n");
|
||||
return 1;
|
||||
}
|
||||
checked_empty = 0;
|
||||
int range_start = parse_int(range_start_str, "range_start", NULL);
|
||||
int range_end = parse_int(range_end_str, "range_end", NULL);
|
||||
|
||||
/* Progress indicator */
|
||||
if (i % (count_frames / progress_step) == 0)
|
||||
{
|
||||
fprintf(stderr, "\rProgress: %d/%d - Lines: %d", i - init_frame, count_frames, num_of_events);
|
||||
}
|
||||
init_frame = range_start;
|
||||
count_frames = range_end - range_start + 1;
|
||||
|
||||
/* If we are outside any lines, check for empty frames first */
|
||||
if (!have_line)
|
||||
/* Get frame number */
|
||||
if (count_frames + init_frame > frames)
|
||||
{
|
||||
if (is_empty(s_info, in_img))
|
||||
continue;
|
||||
else
|
||||
checked_empty = 1;
|
||||
count_frames = frames - init_frame;
|
||||
}
|
||||
last_frame = count_frames + init_frame;
|
||||
|
||||
/* Check for duplicate, unless first frame */
|
||||
if ((i != init_frame) && have_line && is_identical(s_info, in_img, old_img))
|
||||
/* No frames mean nothing to do */
|
||||
if (count_frames < 1)
|
||||
{
|
||||
fprintf(stderr, "No frames found.\n");
|
||||
continue;
|
||||
/* Mark frames that were not used as new image in comparison to have transparent pixels zeroed */
|
||||
else if (!(i && have_line))
|
||||
must_zero = 1;
|
||||
}
|
||||
|
||||
/* Not a dup, write end-of-line, if we had a line before */
|
||||
/* Set progress step */
|
||||
if (count_frames < 1000)
|
||||
{
|
||||
if (count_frames > 200)
|
||||
progress_step = 50;
|
||||
else if (count_frames > 50)
|
||||
progress_step = 10;
|
||||
else
|
||||
progress_step = 1;
|
||||
}
|
||||
|
||||
/* Process frames */
|
||||
for (i = init_frame; i < last_frame; i++)
|
||||
{
|
||||
if (read_frame_avis(in_img, avis_hnd, i))
|
||||
{
|
||||
fprintf(stderr, "Error reading frame.\n");
|
||||
return 1;
|
||||
}
|
||||
checked_empty = 0;
|
||||
|
||||
/* Progress indicator */
|
||||
if (i % (count_frames / progress_step) == 0)
|
||||
{
|
||||
fprintf(stderr, "\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 (!have_line)
|
||||
{
|
||||
if (is_empty(s_info, in_img))
|
||||
continue;
|
||||
else
|
||||
checked_empty = 1;
|
||||
}
|
||||
|
||||
/* Check for duplicate, unless first frame */
|
||||
if ((i != init_frame) && have_line && is_identical(s_info, in_img, old_img))
|
||||
continue;
|
||||
/* Mark frames that were not used as new image in comparison to have transparent pixels zeroed */
|
||||
else if (!(i && have_line))
|
||||
must_zero = 1;
|
||||
|
||||
/* Not a dup, write end-of-line, if we had a line before */
|
||||
if (have_line)
|
||||
{
|
||||
if (sup_output)
|
||||
{
|
||||
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);
|
||||
if (!xml_output)
|
||||
free(pal);
|
||||
pal = NULL;
|
||||
}
|
||||
if (xml_output)
|
||||
add_event_xml(events, split_at, min_split, start_frame + to, i + to, n_crop, crops, mark_forced);
|
||||
end_frame = i;
|
||||
have_line = 0;
|
||||
}
|
||||
|
||||
/* Check for empty frame, if we didn't before */
|
||||
if (!checked_empty && is_empty(s_info, in_img))
|
||||
continue;
|
||||
|
||||
/* Zero transparent pixels, if needed */
|
||||
if (must_zero)
|
||||
zero_transparent(s_info, in_img);
|
||||
must_zero = 0;
|
||||
|
||||
/* Not an empty frame, start line */
|
||||
have_line = 1;
|
||||
start_frame = i;
|
||||
swap_rb(s_info, in_img, out_buf);
|
||||
if (buffer_opt)
|
||||
n_crop = auto_split(pic, crops, ugly, even_y);
|
||||
else if (autocrop)
|
||||
{
|
||||
crops[0].x = 0;
|
||||
crops[0].y = 0;
|
||||
crops[0].w = pic.w;
|
||||
crops[0].h = pic.h;
|
||||
auto_crop(pic, crops);
|
||||
}
|
||||
if ((buffer_opt || autocrop) && even_y)
|
||||
enforce_even_y(crops, n_crop);
|
||||
if ((pal_png || sup_output) && pal == NULL)
|
||||
pal = palletize(out_buf, s_info->i_width, s_info->i_height);
|
||||
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]);
|
||||
if (pal_png && xml_output && !sup_output)
|
||||
{
|
||||
free(pal);
|
||||
pal = NULL;
|
||||
}
|
||||
num_of_events++;
|
||||
if (first_frame == -1)
|
||||
first_frame = i;
|
||||
|
||||
/* Save image for next comparison. */
|
||||
tmp = in_img;
|
||||
in_img = old_img;
|
||||
old_img = tmp;
|
||||
}
|
||||
|
||||
before_range_frame_count += i - init_frame;
|
||||
fprintf(stderr, "\rProgress: %d/%d - Lines: %d\n", before_range_frame_count, range_frame_count, num_of_events);
|
||||
|
||||
/* Add last event, if available */
|
||||
if (have_line)
|
||||
{
|
||||
if (sup_output)
|
||||
{
|
||||
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, i - 1 + to, split_at, min_split, stricter, mark_forced);
|
||||
if (!xml_output)
|
||||
free(pal);
|
||||
pal = NULL;
|
||||
}
|
||||
if (xml_output)
|
||||
add_event_xml(events, split_at, min_split, start_frame + to, i + to, n_crop, crops, mark_forced);
|
||||
end_frame = i;
|
||||
have_line = 0;
|
||||
}
|
||||
|
||||
/* Check for empty frame, if we didn't before */
|
||||
if (!checked_empty && is_empty(s_info, in_img))
|
||||
continue;
|
||||
|
||||
/* Zero transparent pixels, if needed */
|
||||
if (must_zero)
|
||||
zero_transparent(s_info, in_img);
|
||||
must_zero = 0;
|
||||
|
||||
/* Not an empty frame, start line */
|
||||
have_line = 1;
|
||||
start_frame = i;
|
||||
swap_rb(s_info, in_img, out_buf);
|
||||
if (buffer_opt)
|
||||
n_crop = auto_split(pic, crops, ugly, even_y);
|
||||
else if (autocrop)
|
||||
{
|
||||
crops[0].x = 0;
|
||||
crops[0].y = 0;
|
||||
crops[0].w = pic.w;
|
||||
crops[0].h = pic.h;
|
||||
auto_crop(pic, crops);
|
||||
}
|
||||
if ((buffer_opt || autocrop) && even_y)
|
||||
enforce_even_y(crops, n_crop);
|
||||
if ((pal_png || sup_output) && pal == NULL)
|
||||
pal = palletize(out_buf, s_info->i_width, s_info->i_height);
|
||||
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]);
|
||||
if (pal_png && xml_output && !sup_output)
|
||||
{
|
||||
free(pal);
|
||||
pal = NULL;
|
||||
}
|
||||
num_of_events++;
|
||||
if (first_frame == -1)
|
||||
first_frame = i;
|
||||
|
||||
/* Save image for next comparison. */
|
||||
tmp = in_img;
|
||||
in_img = old_img;
|
||||
old_img = tmp;
|
||||
}
|
||||
|
||||
fprintf(stderr, "\rProgress: %d/%d - Lines: %d - Done\n", i - init_frame, count_frames, num_of_events);
|
||||
|
||||
/* Add last event, if available */
|
||||
if (have_line)
|
||||
{
|
||||
if (sup_output)
|
||||
{
|
||||
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);
|
||||
if (!xml_output)
|
||||
{
|
||||
add_event_xml(events, split_at, min_split, start_frame + to, i - 1 + to, n_crop, crops, mark_forced);
|
||||
free(pal);
|
||||
pal = NULL;
|
||||
pal = NULL;
|
||||
}
|
||||
auto_cut = 1;
|
||||
end_frame = i - 1;
|
||||
}
|
||||
if (xml_output)
|
||||
{
|
||||
add_event_xml(events, split_at, min_split, start_frame + to, i - 1 + to, n_crop, crops, mark_forced);
|
||||
free(pal);
|
||||
pal = NULL;
|
||||
}
|
||||
auto_cut = 1;
|
||||
end_frame = i - 1;
|
||||
}
|
||||
|
||||
if (sup_output)
|
||||
@ -1338,6 +1363,7 @@ int main (int argc, char *argv[])
|
||||
|
||||
/* Cleanup */
|
||||
close_file_avis(avis_hnd);
|
||||
fclose(ranges_fp);
|
||||
|
||||
/* Give runtime */
|
||||
if (0)
|
||||
|
Loading…
Reference in New Issue
Block a user