# Dynamic Scene Segmentation and Sentiment Analysis for Danmaku
## 3 Method
### Video Scene Segmentation  
When performing video scene segmentation, the integration of temporal and spatial features, such as color histogram similarity, is crucial for achieving more accurate segmentation.  
Figure 1: The framework of scene segmentation based sentiment analysis for Danmaku.  
From the perspective of temporal features, the model conducts a detailed analysis of video data frame by frame. Specifically, it monitors the content changes in each frame compared to the previous one. Significant changes over several consecutive frames might indicate a scene transition.  
Regarding spatial features, color histogram similarity plays a vital role. When calculating the color histogram, the model uses the common RGB color space, dividing each color channel (R, G, B) into 256 bins, and then counts the number of pixels within each bin to generate the color histogram for that frame. For two adjacent frames, the similarity of their color histograms is computed to assess the degree of similarity in their color distributions.  
Here, different segments in the video are identified based on changes in visual content, with a complete video being divided into a series of scene segments. By combining temporal and color histogram similarities, the model can more accurately identify and merge visually similar consecutive scenes, thereby reducing incorrect scene switch predictions.  
Firstly, a prediction array is received, which contains the model's prediction of whether each frame is a scene switch point. These prediction values are binary: 1 is indicated for a scene switch point while 0 for a non-switch point.  
Secondly, this array is iterated to determine scene boundaries based on changes in the prediction values (from 0 to 1 or from 1 to 0). Whenever a change from the middle of a scene to the end of a scene (from 1 to 0) is detected, it marks the beginning of a new scene. Conversely, when a change from the end of a scene to the beginning of a new one (from 0 to 1) is detected, the end of the current scene is recorded, and the scene is added to the scene list.  
Assuming a scene has \(\mathbf{M}\) frames, the average histogram of the scene is shown in **Formula (1)**.  
\[\overline{H}=\frac{1}{M}\sum_{i=1}^{M}H_{i} \tag{1}\]  
Once all scenes are preliminarily segmented, the length \(\mathbf{L}\) (number of frames) of each scene is compared with the predefined threshold parameter. If the length of the scene is less than the minimum length defined by the min-scene-length parameter, the scene is considered too brief and is merged with either the previous or the next scene. We calculate the similarity of the average color histograms \(\overline{H_{1}}\) and \(\overline{H_{2}}\) of two adjacent scenes. The similarity \(\mathbf{S}\) is shown in **Formula (2)**.  
\[S=\frac{\sum_{i=1}^{N}\left(H_{1,i}-\overline{H_{1}}\right)\left(H_{2,i}- \overline{H_{2}}\right)}{\sqrt{\sum_{i=1}^{N}\left(H_{1,i}-\overline{H_{1}} \right)^{2}\sum_{i=1}^{N}\left(H_{2,i}-\overline{H_{2}}\right)^{2}}} \tag{2}\]  
where \(H_{1,i}\) and \(H_{2,i}\) are the \(i\)-th bin values of the histograms \(\overline{H_{1}}\) and \(\overline{H_{2}}\), respectively. \(\mathbf{N}\) is the number of bins of the histogram. If the color histogram similarity \(\mathbf{S}\) between two adjacent scenes exceeds the defined threshold, the scenes are considered similar in color and are merged into a single scene. Using the above method, the model can accurately identify and merge visually similar consecutive scenes, thereby reducing incorrect scene switch predictions and achieving effective video scene segmentation.