Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize dominant_ac also for ac_wrong_modifier #161

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ http://www.kaashoek.com/comskip/
![Example Comskip image](https://github.com/essandess/etv-comskip/blob/master/example.png)
*Commercials are marked and skipped using [associated projects](https://github.com/essandess/etv-comskip).*

This fork contains small feature tweaks that optimize comskip for my specific use case. Use with care!

Applied changes:
- Let `ac_wrong_modifier` punish blocks even if `cut_on_ac_change` is disabled
- Blocks that are freed by `always_keep_(first|last)_seconds` can still be deleted by `delete_show_(before|after)_(first|last)_commercial` (Yes, that's a feature and it's very beneficial for **my** specific use case)

### Requirements

- FFmpeg with headers and shared libraries (2.4+)
Expand Down
116 changes: 106 additions & 10 deletions comskip.c
Original file line number Diff line number Diff line change
Expand Up @@ -3320,7 +3320,7 @@ int DetectCommercials(int f, double pts)
{
if (delay_logo_search == 0 ||
(delay_logo_search == 1 && F2T(frame_count) > added_recording * 60) ||
(F2T(frame_count) > delay_logo_search))
(delay_logo_search > 1 && F2T(frame_count) > delay_logo_search))
{
FillLogoBuffer();
if (logoBuffersFull)
Expand Down Expand Up @@ -4363,6 +4363,11 @@ bool BuildMasterCommList(void)
frame[frame_count].hasBright = 0;
InsertBlackFrame(frame_count,0,0,0, C_b);

if (cut_on_ac_change || ac_wrong_modifier != 0) {
FillACHistogram(true);
dominant_ac = ac_histogram[0].audio_channels;
}

if (cut_on_ac_change)
{
if (ac_block[ac_block_count].start > 0)
Expand All @@ -4372,9 +4377,6 @@ bool BuildMasterCommList(void)
ac_block_count++;
}

FillACHistogram(true);
dominant_ac = ac_histogram[0].audio_channels;

// Print out ar cblock list
Debug(4, "\nPrinting AC cblock list\n-----------------------------------------\n");
for (i = 0; i < ac_block_count; i++)
Expand Down Expand Up @@ -5506,6 +5508,33 @@ void WeighBlocks(void)
cblock[i].more |= C_AR;
}


/* Remove commercial blocks smaller than always_keep_first_seconds
so that delete_show_before_first_commercial will be able to remove
the previous show */
if (F2T(cblock[i].f_end) < always_keep_first_seconds)
{
Debug(2, "Block %i is shorter than %i seconds.\n", i, always_keep_first_seconds);
Debug(3, "Block %i score:\tBefore - %.2f\t", i, cblock[i].score);
cblock[i].score = 0;
cblock[i].cause |= C_H3;
cblock[i].cause |= C_H3;
Debug(3, "After - %.2f\n", cblock[i].score);
}

/* Remove commercial blocks smaller than always_keep_first_seconds
so that delete_show_after_last_commercial will be able to remove
the succeeding show */
if (F2L(cblock[block_count-1].f_end, cblock[i].f_start) < always_keep_last_seconds)
{
Debug(2, "Block %i is shorter than %i seconds.\n", i, always_keep_first_seconds);
Debug(3, "Block %i score:\tBefore - %.2f\t", i, cblock[i].score);
cblock[i].score = 0;
cblock[i].cause |= C_H3;
cblock[i].cause |= C_H3;
Debug(3, "After - %.2f\n", cblock[i].score);
}


}

Expand Down Expand Up @@ -7418,6 +7447,8 @@ bool OutputBlocks(void)
deleted = true;
}
}

/*
#ifdef NOTDEF
// keep first seconds
if (always_keep_first_seconds && commercial_count >= 0)
Expand Down Expand Up @@ -7463,6 +7494,7 @@ bool OutputBlocks(void)
}
}
#endif
*/

/*
// Delete too short first commercial
Expand Down Expand Up @@ -7556,22 +7588,85 @@ bool OutputBlocks(void)

if (delete_show_before_first_commercial &&
commercial_count > -1 &&
commercial[0].start_block == 1 &&
//commercial[0].start_block == 1 &&
((delete_show_before_first_commercial == 1 && cblock[commercial[0].end_block].f_end < after_start) ||
(delete_show_before_first_commercial > F2T(cblock[commercial[0].end_block].f_end)))
)
{
i = commercial[0].start_block;
commercial[0].start_block = 0;
commercial[0].start_frame = cblock[0].f_start/* + (cblock[i + 1].bframe_count / 2)*/;
commercial[0].length = F2L(commercial[0].end_frame, commercial[0].start_frame);
Debug(3, "H5 Deleting cblock %i of %i seconds because it comes before the first commercial.\n",
0, (int)cblock[0].length);
cblock[0].score = 99.99;
cblock[0].cause |= C_H5;
cblock[0].more |= C_H5;
while (i > 0)
{
Debug(3, "H5 Deleting cblock %i of %i seconds because it comes before the first commercial.\n",
i, (int)cblock[i].length);
cblock[i].score = 99.99;
cblock[i].cause |= C_H5;
cblock[i].more |= C_H5;
i--;
}

}

/* Delete shows that come before and after the current show if
the are seperated by a short commercial, shorter than min_commercialbreak
and only if the shows are shorter than added_recording or the specified
duration */
if (delete_show_before_or_after_current &&
commercial_count > -1)
{
if (((delete_show_before_or_after_current == 1 && commercial[0].start_frame < after_start) ||
(delete_show_before_or_after_current > 1 && commercial[0].start_frame < delete_show_before_or_after_current)) &&
(commercial[0].length < min_commercialbreak))
{
i = commercial[0].start_block - 1;
commercial[0].start_block = 0;
commercial[0].start_frame = cblock[0].f_start;
commercial[0].length = F2L(commercial[0].end_frame, commercial[0].start_frame);
while (i > 0)
{
Debug(3, "H5 Deleting cblock %i of %i seconds because it comes before a short first commercial.\n",
i, (int)cblock[i].length);
cblock[i].score = 99.99;
cblock[i].cause |= C_H5;
cblock[i].more |= C_H5;
i--;
}
}

k = commercial_count;
int j = block_count - 1;
if (commercial[k].length < min_commercialbreak)
{
i = commercial[k].end_block + 1;
int combined_length = 0;
while (i < j)
{
combined_length += cblock[i].length;
i++;
}
if ((delete_show_before_or_after_current == 1 && combined_length < after_start) ||
(delete_show_before_or_after_current > 1 && combined_length < delete_show_before_or_after_current))
{
i = commercial[k].start_block + 1;
commercial[k].end_block = j;
commercial[k].end_frame = cblock[j].f_end;
commercial[k].length = F2L(commercial[k].end_frame, commercial[k].start_frame);
while (i < j)
{
Debug(3, "H5 Deleting cblock %i of %i seconds because it comes after a short last commercial.\n",
i, (int)cblock[i].length);
cblock[i].score = 99.99;
cblock[i].cause |= C_H5;
cblock[i].more |= C_H5;
i++;
}
}
}
}

/*
// keep first seconds
if (always_keep_first_seconds && commercial_count >= 0)
{
Expand Down Expand Up @@ -7614,6 +7709,7 @@ bool OutputBlocks(void)
commercial[k].end_frame--;
}
}
*/



Expand Down