Method, apparatus and electronic device for adjusting width of background color block based on multi-line subtitles
By obtaining the video width of the ASS subtitle file, segmenting and adjusting the subtitle text, setting the xbord value to adjust the background color block width, the problem of inconsistent background color blocks of multiple lines is solved, and the overall coordination of subtitle display is achieved.
Patent Information
- Application Number
- CN202510466166.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-15
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2045-04-15
AI Technical Summary
The background color block width inconsistency of multiple lines of subtitles leads to inconsistent subtitles display.
By obtaining the video width in the ASS subtitle file, split the subtitle text into multiple lines of subtitle text, and calculate the subpixel width difference of each line, write the xbord value in reverse order to adjust the background color block width.
The consistency of the width of the background color blocks of multiple lines of subtitles is achieved, and the overall coordination of subtitles is improved.
Smart Images

Figure CN120151458B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of subtitle adjustment, and particularly to a method, device and electronic device for adjusting the width of background color blocks based on multi-line subtitles. Background Art
[0002] In most subtitle productions, the ASS (Advanced SubStation Alpha, a commonly used subtitle format) file format is often used. Currently, among the existing attribute elements for setting background color blocks in ASS subtitles, when long subtitles in the same time period are automatically line-wrapped into multi-line subtitles, the widths of the background color blocks of the multi-line subtitles obtained by line-wrapping are not exactly the same, resulting in a low consistency in the widths of the background color blocks of multi-line subtitles. Summary of the Invention
[0003] The purpose of the present invention is to provide a method, device and electronic device for adjusting the width of background color blocks based on multi-line subtitles, so as to solve the technical problem of low consistency in the widths of background color blocks of multi-line subtitles.
[0004] In a first aspect, this application provides a method for adjusting the width of background color blocks based on multi-line subtitles, and the method includes:
[0005] Obtain an ASS subtitle file, and determine the maximum width of the background color block corresponding to the subtitle line of the ASS subtitle file in the graphical user interface based on the video width occupied by the video configured in the ASS subtitle file in the graphical user interface;
[0006] Based on the font, font size, character spacing of the original subtitle text in the ASS subtitle file and the maximum width, divide the original subtitle text into multi-line sub-subtitle texts, so that the occupied width of each line of the sub-subtitle text in the graphical user interface is less than or equal to the maximum width, and the occupied width corresponding to each line of the sub-subtitle text except the last line among the multi-line sub-subtitle texts is close to the maximum width;
[0007] Determine the actual sub-pixel width occupied by each line of the sub-subtitle text in the graphical user interface according to the font, font size and character spacing of each line of the sub-subtitle text, select the maximum sub-pixel width from the multiple sub-pixel widths corresponding to the multi-line sub-subtitle texts, and calculate the difference between the sub-pixel width corresponding to each line of the sub-subtitle text and the maximum sub-pixel width respectively;
[0008] Write the multiple lines of the sub - subtitle text in reverse order into the configuration of the ASS subtitle file, and set the xbord (horizontal border width) value respectively under the inline tag of the Dialogue of each line of the sub - subtitle text in the reverse - writing mode. Wherein, the xbord value is the result of taking the integer after dividing the difference corresponding to each line of the sub - subtitle text by two;
[0009] Adjust the initial width of the background color block of the corresponding subtitle line through the set xbord value, so that the adjusted background color block widths corresponding to each subtitle line are the same.
[0010] In a possible implementation, the splitting of the original subtitle text in the ASS subtitle file into multiple lines of sub - subtitle text based on the font, font size, character spacing of the original subtitle text in the ASS subtitle file and the maximum width includes:
[0011] Calculate the total pixel width occupied by the string corresponding to the original subtitle text in the graphical user interface according to the font, font size and character spacing of the original subtitle text in the ASS subtitle file;
[0012] By judging whether the pixel width is greater than the maximum width, split the string corresponding to the original subtitle text into multiple substrings with approximately the same occupied pixel width.
[0013] In a possible implementation, the splitting of the string corresponding to the original subtitle text into multiple substrings with approximately the same occupied pixel width by judging whether the pixel width is greater than the maximum width includes:
[0014] Modify the line - breaking method of the original ASS subtitle file corresponding to the original subtitle text in the graphical user interface to a non - line - breaking and target border - drawing method;
[0015] Under the target method, traverse and read each Dialogue item in the Events module of the original ASS subtitle file. For the current subtitle text in the current Dialogue item being read, judge whether the current pixel width occupied by the current subtitle text in the graphical user interface exceeds the maximum width;
[0016] If the current pixel width does not exceed the maximum width, read the next Dialogue item corresponding to the current Dialogue item in the reading method of the current Dialogue item;
[0017] If the current pixel width exceeds the maximum width, the corresponding string of the current subtitle text is segmented into multiple substrings with approximately the same occupied pixel width according to the font, font size, character spacing of the current subtitle text, and the maximum width; wherein, the width occupied by each of the multiple substrings except the last one in the graphical user interface is less than or equal to the maximum width.
[0018] In a possible implementation, writing the multiple lines of the sub-subtitle text into the configuration of the ASS subtitle file in a reverse order, and respectively setting the xbord value under the inline tag of Dialogue of each line of the sub-subtitle text in the reverse writing method, includes:
[0019] After calculating the difference, delete the current Dialogue item, and traverse the string array corresponding to the multiple substrings in a reverse order, and sequentially add Dialogue items according to the attributes of the deleted Dialogue item, wherein the value of the subtitle text of the newly added Dialogue item is the current string being traversed;
[0020] Set the xbord value under the inline tag of Dialogue of the currently newly added Dialogue item until all items in the string array are traversed.
[0021] In a possible implementation, modifying the line break method of the original ASS subtitle file corresponding to the original subtitle text in the graphical user interface to a non-line break and border drawing target method, includes:
[0022] Set the value of WrapStyle under the Script Info module corresponding to the original ASS subtitle file to 2;
[0023] Set the value of BorderStyle in the specified Style item under the V4+Styles module corresponding to the original ASS subtitle file to 3.
[0024] In a possible implementation, determining whether the current pixel width occupied by the current subtitle text in the graphical user interface exceeds the maximum width includes:
[0025] Determine the current pixel width occupied by the current subtitle text in the graphical user interface according to the font, font size, and character spacing of the current subtitle text;
[0026] Judge whether the current pixel width exceeds the maximum width.
[0027] In a possible implementation, splitting the original subtitle text into multiple lines of sub-subtitle text based on the font, font size, character spacing of the original subtitle text in the ASS subtitle file, and the maximum width includes:
[0028] Set an empty string x, traverse the string corresponding to the original subtitle text in the ASS subtitle file, read the traversal results in sequence, and append the currently read current character to the end of the string x to update the value of the string x;
[0029] Calculate the width occupied by the string x according to the font, font size, and character spacing of the string corresponding to the original subtitle text, and determine whether the width occupied by the string x exceeds the maximum width;
[0030] If the width occupied by the string x does not exceed the maximum width, record the pixel width of the current string x and read the next character of the current character;
[0031] If the width occupied by the string x exceeds the maximum width, remove the current character at the end of the string x, copy the string x as a new substring, store it in an ordered array, and record the width occupied by the new substring;
[0032] Replace the value of the string x with the current character and read the next character of the current character until the string corresponding to the original subtitle text is traversed, obtaining an ordered string array storing a series of new substrings, and the corresponding relationship between the substrings and the widths they occupy.
[0033] In a second aspect, the present application provides a background color block width adjustment device based on multi-line subtitles, including:
[0034] An acquisition module, configured to acquire an ASS subtitle file, and determine the maximum width of the background color block of the subtitle line corresponding to the ASS subtitle file in the graphical user interface based on the video width occupied by the video configured in the ASS subtitle file in the graphical user interface;
[0035] A splitting module, configured to split the original subtitle text into multiple lines of sub-subtitle text based on the font, font size, character spacing of the original subtitle text in the ASS subtitle file, and the maximum width, so that the occupied width of each line of the sub-subtitle text in the graphical user interface is less than or equal to the maximum width, and the occupied width corresponding to each line of the sub-subtitle text except the last line among the multiple lines of sub-subtitle text is close to the maximum width;
[0036] A determination module, configured to determine the sub-pixel width actually occupied by each line of the sub-title text in the graphical user interface according to the font, font size, and character spacing of each line of the sub-title text, select the maximum sub-pixel width from the multiple sub-pixel widths corresponding to multiple lines of the sub-title text, and calculate the difference between the sub-pixel width corresponding to each line of the sub-title text and the maximum sub-pixel width respectively;
[0037] A setting module, configured to write multiple lines of the sub-title text into the configuration of the ASS subtitle file in a reverse order, and respectively set an xbord value under the inline tag of Dialogue of each line of the sub-title text in the reverse writing method, where the xbord value is the result of rounding up the quotient of the difference corresponding to each line of the sub-title text divided by two;
[0038] An adjustment module, configured to adjust the initial width of the background color block corresponding to the subtitle line through the set xbord value, so that the adjusted background color block widths corresponding to each subtitle line are the same.
[0039] In a third aspect, the present application further provides an electronic device, including a memory and a processor, where a computer program executable on the processor is stored in the memory, and when the processor executes the computer program, the method described in the first aspect above is implemented.
[0040] In a fourth aspect, the present application further provides a computer-readable storage medium, where computer-executable instructions are stored, and when the computer-executable instructions are called and run by a processor, the computer-executable instructions cause the processor to run the method described in the first aspect above.
[0041] The present application brings the following beneficial effects:
[0042] A method, apparatus, and electronic device for adjusting the width of background color blocks based on multi-line subtitles provided by the present application can obtain an ASS subtitle file, and determine the maximum width of the background color block corresponding to the subtitle line in the graphical user interface based on the video width occupied by the video configured in the ASS subtitle file in the graphical user interface; based on the font, font size, and character spacing of the original subtitle text in the ASS subtitle file and the maximum width, divide the original subtitle text into multi-line sub-subtitle texts, so that the occupied width of each line of the sub-subtitle text in the graphical user interface is less than or equal to the maximum width, and the occupied width corresponding to each line of the sub-subtitle text except the last line among the multi-line sub-subtitle texts is close to the maximum width; determine the actual sub-pixel width occupied by each line of the sub-subtitle text in the graphical user interface according to the font, font size, and character spacing of each line of the sub-subtitle text, select the maximum sub-pixel width from the multiple sub-pixel widths corresponding to the multi-line sub-subtitle texts, and calculate the difference between the sub-pixel width corresponding to each line of the sub-subtitle text and the maximum sub-pixel width respectively; write the multi-line sub-subtitle texts into the configuration of the ASS subtitle file in reverse order, and set the xbord value under the inline tag of the Dialogue of each line of the sub-subtitle text in the reverse writing method, where the xbord value is the result of taking the integer after dividing the difference corresponding to each line of the sub-subtitle text by two; adjust the initial width of the background color block corresponding to the subtitle line through the set xbord value, so that the adjusted background color block widths corresponding to each subtitle line are the same. In this solution, by reasonably dividing the original long subtitle into multiple lines, calculating the pixel width occupied by the divided subtitles, and then directly setting the ASS subtitle attributes according to the pixel width occupied by the corresponding subtitle line, the width of the background color block of the multi-line subtitles after division is reasonably adjusted to achieve the effect that the background color block widths of each line of subtitles are the same, so that when the ASS long subtitle in the same time period is automatically wrapped into multi-line subtitles, the background color block widths of each line of subtitles can be the same, achieving an overall coordinated effect, and solving the technical problem of low consistency of the background color block widths of multi-line subtitles.
[0043] To make the above objects, features, and advantages of the present application more obvious and understandable, the following specific preferred embodiments are given and described in detail in conjunction with the accompanying drawings as follows. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] To more clearly illustrate the specific embodiments of the present application or the technical solutions in the prior art, the following will briefly introduce the accompanying drawings required for the description of the specific embodiments or the prior art. Obviously, the accompanying drawings in the following description are some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can also be obtained based on these drawings.
[0045] Figure 1 A flowchart showing the method for adjusting the width of the background color block based on multi-line subtitles provided by an embodiment of the present application;
[0046] Figure 2 An example in the method for adjusting the width of the background color block based on multi-line subtitles provided by an embodiment of the present application;
[0047] Figure 3 A structural diagram showing a device for adjusting the width of the background color block based on multi-line subtitles provided by an embodiment of the present application;
[0048] Figure 4 A structural diagram showing an electronic device provided by an embodiment of the present application is shown. Specific embodiments
[0049] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the following will clearly and completely describe the technical solutions of the present application in conjunction with the accompanying drawings. Obviously, the described embodiments are some, but not all, of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of the present application.
[0050] The terms "including" and "having" and any variations thereof mentioned in the embodiments of the present application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but optionally further includes other steps or units not listed, or optionally further includes other steps or units inherent to these processes, methods, products, or devices.
[0051] Currently, the width consistency of the background color blocks for multi-line subtitles is relatively low. Based on this, the embodiments of the present application provide a method, device, and electronic device for adjusting the width of the background color block based on multi-line subtitles, which can solve the technical problem of relatively low width consistency of the background color blocks for multi-line subtitles.
[0052] The following further introduces the embodiments of the present invention in conjunction with the accompanying drawings.
[0053] Figure 1This is a schematic flowchart of a method for adjusting the width of background color blocks based on multi-line subtitles provided by an embodiment of the present application. As Figure 1 shown, the method includes:
[0054] Step S110, obtain an ASS subtitle file, and determine the maximum width of the background color block corresponding to the subtitle line in the graphical user interface based on the video width occupied by the video configured in the ASS subtitle file.
[0055] In a possible implementation manner, read the original ASS (Advanced SubStation Alpha, a common subtitle format) subtitle file. Among them, the unit of the video width configured in the ASS subtitle file is pixels, and the value is taken from the value of PlayResX (the screen width of the subtitle) under the Script Info (script information during editing) module in the ASS subtitle file. In a standard ASS subtitle file, this value is usually the same as the video width. In this step, according to the video width configured in the ASS subtitle file, set the maximum width (in pixels) of the background color block of a subtitle line according to specific needs. The pixel calculation formula for the width occupied by the background color block is: video width (PlayResX) * percentage of the video width occupied by the background color block = width of the background color block. Exemplarily, assuming that the width of the background color block is set according to 95% of the video width, if the video width is 1920, then the width of the background color block is: 1920 * 0.95 = 1824.
[0056] Among them, PlayResX is a parameter in the ASS subtitle file, indicating the screen width of the subtitle. In the ASS subtitle file, PlayResX and PlayResY respectively represent the screen width and height of the subtitle file. These two parameters define the display area of the subtitle and usually need to match the resolution of the video to ensure the correct display of the subtitle.
[0057] Step S120, based on the font, font size, character spacing, and maximum width of the original subtitle text in the ASS subtitle file, split the original subtitle text into multi-line sub-subtitle texts, so that the occupied width of each line of sub-subtitle text in the graphical user interface is less than or equal to the maximum width, and the occupied width corresponding to each line of sub-subtitle text except the last line in the multi-line sub-subtitle texts is close to the maximum width.
[0058] As an example, this step S120 may specifically include the following steps: Calculate the total pixel width occupied by the corresponding string of the original subtitle text in the graphical user interface according to the font, font size, and character spacing of the original subtitle text in the ASS subtitle file; By judging whether the pixel width is greater than the maximum width, split the corresponding string of the original subtitle text into multiple substrings with approximately the same occupied pixel width. Through this processing method, the splitting accuracy of splitting the original subtitle text into multiple lines of sub-subtitle text is improved.
[0059] For the above step of calculating the total pixel width occupied by the corresponding string of the original subtitle text in the graphical user interface according to the font, font size, and character spacing of the original subtitle text in the ASS subtitle file, specifically, calculate the total pixel width (in pixels) occupied by the specified string through the font, font size, and character spacing (in pixels). This can be implemented with the help of the open-source framework pillow (a third-party open-source image processing library). The brief steps are as follows: Step 1. Install the specified development library, Pillow; Step 2. Import the required module ImageFont. Here, ImageFont is an object composed of a font file and related attributes in a programming language, and these attributes include font size, style, color, etc.; Step 3. Set the font path, font size, and character spacing information; Step 4. Use ImageFont to load the font and font size set in Step 3; Step 5. Measure the width occupied by the specified string and record the number of characters; Step 6. According to the set character spacing and the number of characters calculated in the above Step 5, calculate the width of the overall character spacing. The calculation method is: overall character spacing width = specified character spacing * (number of characters - 1); Step 7. Calculate how much the specified string occupies in total under the premise of the specified font, font size, and character spacing according to the width of the overall string obtained in the above Step 5 and the width of the overall character spacing obtained in the above Step 6. The calculation method is: total width occupied by the string = width of the overall string + width of the overall character spacing.
[0060] In some embodiments, step S120 above may specifically include the following steps: Set an empty string x, and traverse the string corresponding to the original subtitle text in the ASS subtitle file. Read the traversal results in sequence, and append the currently read current character to the end of the string x, so that the value of the string x is updated; Calculate the width occupied by the string x according to the font, font size, and character spacing of the string corresponding to the original subtitle text, and determine whether the width occupied by the string x exceeds the maximum width; If the width occupied by the string x does not exceed the maximum width, record the pixel width of the current string x, and read the next character of the current character; If the width occupied by the string x exceeds the maximum width, remove the current character at the end of the string x, copy the string x as a new substring, store it in an ordered array, and record the width occupied by the new substring; Replace the value of the string x with the current character, and read the next character of the current character until the string corresponding to the original subtitle text is traversed, to obtain an ordered string array storing a series of new substrings, and the corresponding relationship between the substrings and the widths they occupy respectively.
[0061] Through the above processing method, a method for splitting an original string into multiple sub-strings by specifying the maximum width, font, font size, and character spacing occupied by the specified string in total is implemented, and it is ensured that except for the last segment, the width occupied by each of the split sub-strings is as close as possible but not greater than the above maximum width, thereby improving the data splitting accuracy. Exemplarily, the brief steps are as follows: Step 1. Set a temporary empty string (denoted as "string x"), and traverse the specified string. Step 2. Read the traversal results in sequence, and append the currently read character (denoted as "character x") to the end of "string x", at this time the value of "string x" is updated. Step 3. Use the function implemented in Step 2 to calculate the width occupied by "string x". Step 4. Determine whether the width of "string x" exceeds the specified maximum width. Step 5. If not, record the currently calculated width (denoted as "the pixel width of string x"), and repeat Step 2. Step 6. If it exceeds, remove "character x" at the end of "string x", copy "string x" as a new substring, store it in an ordered array, and record the width occupied by this new substring, with the value being "the width of string x". Step 7. Replace the value of "string x" with "character x", and repeat Step 2. Step 8. Until the specified string is traversed, finally obtain an ordered string array storing a series of new substrings and the corresponding relationship between these substrings and the widths they occupy respectively.
[0062] The process of splitting the corresponding string of the original subtitle text into multiple substrings with similar pixel widths by determining whether the pixel width is greater than the maximum width may specifically include the following steps: modifying the line break method of the original ASS subtitle file corresponding to the original subtitle text in the graphical user interface to no line break and the target method of border drawing; traversing and reading each Dialogue item under the Events module in the original ASS subtitle file in the target method, and for the current subtitle text in the current Dialogue item being read, determining whether the current pixel width occupied by the current subtitle text in the graphical user interface exceeds the maximum width; if the current pixel width does not exceed the maximum width, reading the next Dialogue item corresponding to the current Dialogue item according to the reading method of the current Dialogue item; if the current pixel width exceeds the maximum width, splitting the corresponding string of the current subtitle text into multiple substrings with similar pixel widths according to the font, font size, character spacing of the current subtitle text and the maximum width; wherein, the width occupied by each substring except the last one among the multiple substrings in the graphical user interface is less than or equal to the maximum width. Through this processing method, the data accuracy and splitting efficiency of multiple substrings with similar pixel widths are improved.
[0063] Exemplarily, step 1. Read the original ASS subtitle file; step 2. Traverse and read each line of Dialogue under the Events module; step 3. Read the Text item (i.e., the specific subtitle text) in the Dialogue; step 4. Use the method in step 2 to determine whether the current Text item exceeds the above maximum width; step 5. If not, read the next line of Dialogue and continue with step 2; step 6. If it exceeds, use the method in step 3 to split the Text item into multiple substrings to obtain a series of substrings and the widths corresponding to these substrings.
[0064] Modifying the line break method of the original ASS subtitle file corresponding to the original subtitle text in the graphical user interface to no line break and the target border drawing method can specifically include the following steps: Set the value of WrapStyle (WrapStyle is a method of the multi-line area class for displaying plain text and belongs to the javax.swing package. The WrapStyle method is used to set the line break policy in the text area) under the Script Info (script information during editing) module of the original ASS subtitle file to 2; Set the value of BorderStyle (border style) in the specified Style (style) item under the V4+Styles (V4+Styles is a part of the ASS subtitle format used to define subtitle styles. V4+Styles is the part of the ASS format used to define various subtitle styles) module of the original ASS subtitle file to 3. By reading the original ASS subtitle file in this way and modifying the line break method of the subtitle text to no line break and border drawing method, the modification and adjustment efficiency of the line break method of the subtitle text is improved.
[0065] Judging whether the current pixel width occupied by the current subtitle text in the graphical user interface exceeds the maximum width can specifically include the following steps: Determine the current pixel width occupied by the current subtitle text in the graphical user interface according to the font, font size, and character spacing of the current subtitle text; Judge whether the current pixel width exceeds the maximum width. Through this processing method, the accuracy of data judgment is improved.
[0066] Step S130, determine the sub-pixel width actually occupied by each line of sub-subtitle text in the graphical user interface according to the font, font size, and character spacing of each line of sub-subtitle text, select the maximum sub-pixel width from the multiple sub-pixel widths corresponding to the multi-line sub-subtitle text, and calculate the difference between the sub-pixel width corresponding to each line of sub-subtitle text and the maximum sub-pixel width respectively.
[0067] For example, according to the ordered string array obtained in step three and the widths occupied by each sub-string therein, calculate the maximum width among them. The brief steps are as follows: Step 1. Set a variable (denoted as "maximum value x") with a value of 0. Step 2. Traverse the ordered string array obtained in step three. Step 3. According to the value traversed in step 2, combined with the "width of string x" stored in step three, obtain the width occupied by the current string. Step 4. Compare "maximum value x" with the width occupied by the current string obtained in step 3. If "maximum value x" is less than the width occupied by the current string obtained in step 3, then set "maximum value x" to the width occupied by the current string obtained in step 3. Step 5. Until the string array obtained in step three is traversed, the value of "maximum value x" is the maximum pixel width.
[0068] As an example, according to the obtained ordered string array and the pixel widths occupied by each segment of the string, calculate the difference between the width occupied by each segment of the subtitle and the maximum width extracted respectively. The brief steps are as follows: Traverse the string array obtained in step three; subtract the width occupied by the current string obtained in step three from the maximum width obtained above to get the current difference.
[0069] Step S140, write the multi-line sub-subtitle text into the configuration of the ASS subtitle file in reverse order, and set the xbord value respectively under the inline tag of Dialogue for each line of sub-subtitle text in the reverse writing method.
[0070] Among them, the xbord (horizontal border width) value is the result of taking the integer after dividing the difference corresponding to each line of sub-subtitle text by two.
[0071] In an alternative embodiment, the process of writing the multi-line sub-subtitle text into the configuration of the ASS subtitle file in reverse order and setting the xbord value respectively under the inline tag of Dialogue for each line of sub-subtitle text in the reverse writing method may specifically include the following steps:
[0072] After calculating the difference, delete the current Dialogue item, and traverse the string array corresponding to the multi-segment substring in reverse order, and add Dialogue items in sequence according to the attributes of the deleted Dialogue item. Among them, the value of the subtitle text of the added Dialogue item is the current string traversed currently; set the xbord value under the inline tag of Dialogue of the currently added Dialogue item until all items in the string array are traversed. Through this processing method, the setting efficiency of the xbord value is improved.
[0073] Exemplarily, after calculating the difference, delete the current Dialogue item. On this basis, traverse the obtained string array in reverse order, and add Dialogue items in sequence according to the attributes of the deleted Dialogue item. The value of the Text item of the added Dialogue item is the current string traversed, and under the inline tag of Dialogue of the currently added Dialogue item, set the xbord (horizontal border width), and the xbord value is the difference obtained above divided by 2 and then take the integer. Until all items in the string array are processed. It should be noted that xbord is used to adjust the display width of each line of subtitle, and the background color of each line can be represented by 3c.
[0074] Step S150: Adjust the initial width of the background color block corresponding to the subtitle line by the set xbord value, so that the adjusted background color block widths corresponding to each subtitle line are the same.
[0075] As Figure 2 shown in the original effect and the effect after being adjusted by the solution of the embodiment of the present application, through the adjustment of the algorithm provided by the embodiment of the present application, when a background color block needs to be added to the subtitle in the ASS subtitle and long subtitles automatically wrap, the background color block widths of each line of subtitles are consistent.
[0076] In the embodiment of the present application, when the ASS long subtitles in the same time period are automatically wrapped into multiple lines of subtitles, by reasonably splitting the original long subtitles into multiple lines and calculating the pixel widths occupied by the split subtitles, according to the pixel widths occupied by the corresponding subtitle lines obtained by splitting, the background color block widths of the multiple lines of subtitles obtained by splitting are reasonably adjusted by directly setting the ASS subtitle attributes, so as to achieve the effect that the background color block widths of each line of subtitles are the same, so as to achieve the overall coordinated effect.
[0077] Figure 3 A structural schematic diagram of a device for adjusting the background color block width based on multiple lines of subtitles is provided. As Figure 3 shown, the device 300 for adjusting the background color block width based on multiple lines of subtitles includes:
[0078] An acquisition module 301, configured to acquire an ASS subtitle file, and determine the maximum width of the background color block of the corresponding subtitle line of the ASS subtitle file in the graphical user interface based on the video width occupied by the video configured in the ASS subtitle file in the graphical user interface;
[0079] A splitting module 302, configured to split the original subtitle text into multiple lines of sub-subtitle text based on the font, font size, character spacing of the original subtitle text in the ASS subtitle file and the maximum width, so that the occupied width of each line of the sub-subtitle text in the graphical user interface is less than or equal to the maximum width, and the occupied width corresponding to each line of the sub-subtitle text except the last line in the multiple lines of sub-subtitle text is close to the maximum width;
[0080] A determination module 303, configured to determine the actual sub-pixel width occupied by each line of the sub-subtitle text in the graphical user interface according to the font, font size and character spacing of each line of the sub-subtitle text, select the maximum sub-pixel width from the multiple sub-pixel widths corresponding to the multiple lines of sub-subtitle text, and calculate the difference between the sub-pixel width corresponding to each line of the sub-subtitle text and the maximum sub-pixel width respectively;
[0081] A setting module 304 is configured to write the multiple lines of the sub-caption text into the configuration of the ASS caption file in a reverse order, and respectively set a 3bord value under the inline tag of Dialogue of each line of the sub-caption text in the reverse writing mode, where the 3bord value is the result of taking the integer after dividing the difference corresponding to each line of the sub-caption text by two;
[0082] An adjustment module 305 is configured to adjust the initial width of the background color block of the corresponding caption line through the set 3bord value, so that the adjusted background color block widths corresponding to each caption line are the same.
[0083] The device for adjusting the width of the background color block based on multiple lines of captions provided by the embodiment of the present application has the same technical features as the method for adjusting the width of the background color block based on multiple lines of captions provided by the above embodiment, so it can also solve the same technical problems and achieve the same technical effects.
[0084] An electronic device provided by an embodiment of the present application, as Figure 4 shown, the electronic device 400 includes a processor 402 and a memory 401. A computer program that can run on the processor is stored in the memory. When the processor executes the computer program, the steps of the method provided by the above embodiment are implemented.
[0085] See Figure 4 , the electronic device further includes: a bus 403 and a communication interface 404. The processor 402, the communication interface 404, and the memory 401 are connected through the bus 403; the processor 402 is configured to execute an executable module stored in the memory 401, such as a computer program.
[0086] Among them, the memory 401 may include a high-speed random access memory (Random Access Memory, abbreviated as RAM), and may also include a non-volatile memory, such as at least one disk memory. Through at least one communication interface 404 (which can be wired or wireless), a communication connection between the system network element and at least one other network element is realized, and the Internet, wide area network, local area network, metropolitan area network, etc. can be used.
[0087] The bus 403 may be an ISA bus, a PCI bus, an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of representation, Figure 4 only a bidirectional arrow is used in
[0088] Among them, the memory 401 is used to store a program. After receiving an execution instruction, the processor 402 executes the program. The method executed by the device defined by any of the processes disclosed in the foregoing embodiments of the present application can be applied to the processor 402 or implemented by the processor 402.
[0089] The processor 402 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the integrated logic circuit in the hardware of the processor 402 or by instructions in the form of software. The above-mentioned processor 402 may be a general-purpose processor, including a central processing unit (CPU for short), a network processor (NP for short), etc.; it may also be a digital signal processor (DSP for short), an application specific integrated circuit (ASIC for short), a field-programmable gate array (FPGA for short), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. It can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of the present application can be directly embodied as being executed by a hardware decoding processor or completed by a combination of hardware and software modules in the decoding processor. The software module may be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. This storage medium is located in the memory 401, and the processor 402 reads the information in the memory 401 and combines its hardware to complete the steps of the above method.
[0090] Corresponding to the above method for adjusting the width of the background color block based on multi-line subtitles, an embodiment of the present application also provides a computer-readable storage medium. The computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and run by a processor, the computer-executable instructions cause the processor to run the steps of the above method for adjusting the width of the background color block based on multi-line subtitles.
[0091] The device for adjusting the width of the background color block based on multi-line subtitles provided in the embodiments of the present application may be specific hardware on the device, or software or firmware installed on the device, etc. For the device provided in the embodiments of the present application, its implementation principle and the technical effects produced are the same as those of the foregoing method embodiments. For the sake of brief description, for the parts not mentioned in the device embodiments, reference may be made to the corresponding content in the foregoing method embodiments. Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the foregoing-described systems, devices, and units can all refer to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0092] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division, and there may be other division methods in actual implementation. For another example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some communication interfaces. The indirect couplings or communication connections of the devices or units can be in electrical, mechanical or other forms.
[0093] For another example, the flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions, and operations of devices, methods, and computer program products according to multiple embodiments of the present application. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code, and the module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and the combinations of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.
[0094] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0095] In addition, each functional unit in the embodiments provided in the present application may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit.
[0096] If the above-mentioned function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method for adjusting the width of the background color block based on multi-line subtitles described in various embodiments of the present application. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROM for short), random access memories (RAM for short), magnetic disks, or optical discs that can store program codes.
[0097] It should be noted that similar reference numerals and letters represent similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. In addition, the terms "first", "second", "third", etc. are only used for distinguishing descriptions and cannot be understood as indicating or implying relative importance.
[0098] Finally, it should be noted that the above-mentioned embodiments are only specific implementation manners of the present application, used to illustrate the technical solutions of the present application, rather than limiting them. The protection scope of the present application is not limited thereto. Although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: any person skilled in the art within the technical scope disclosed in the present application can still modify the technical solutions recorded in the foregoing embodiments, or can easily think of changes, or perform equivalent replacements on some of the technical features; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application. All should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A method for adjusting the width of background color blocks based on multi-line subtitles, characterized in that, The method includes: Obtaining an ASS subtitle file, and determining the maximum width of the background color block of the corresponding subtitle line of the ASS subtitle file in the graphical user interface based on the video width occupied by the video configured in the ASS subtitle file; Based on the font, font size, character spacing of the original subtitle text in the ASS subtitle file, and the maximum width, splitting the original subtitle text into multiple lines of sub-subtitle text, so that the occupied width of each line of the sub-subtitle text in the graphical user interface is less than or equal to the maximum width, and the occupied width corresponding to each line of the sub-subtitle text except the last line among the multiple lines of sub-subtitle text is close to the maximum width; Determining the actual sub-pixel width occupied by each line of the sub-subtitle text in the graphical user interface according to the font, font size, and character spacing of each line of the sub-subtitle text, selecting the maximum sub-pixel width from the multiple sub-pixel widths corresponding to the multiple lines of sub-subtitle text, and respectively calculating the difference between the sub-pixel width corresponding to each line of the sub-subtitle text and the maximum sub-pixel width; Writing the multiple lines of sub-subtitle text into the configuration of the ASS subtitle file in reverse order, and respectively setting the xbord value under the inline tag of Dialogue of each line of the sub-subtitle text in the reverse writing method, where the xbord value is the result of rounding the difference obtained by dividing the difference corresponding to each line of the sub-subtitle text by two; Adjusting the initial width of the background color block of the corresponding subtitle line through the set xbord value, so that the adjusted background color block widths corresponding to each subtitle line are the same.
2. The method according to claim 1, characterized in that The splitting the original subtitle text into multiple lines of sub-subtitle text based on the font, font size, character spacing of the original subtitle text in the ASS subtitle file, and the maximum width includes: Calculating the total pixel width occupied by the corresponding string of the original subtitle text in the graphical user interface according to the font, font size, and character spacing of the original subtitle text in the ASS subtitle file; By determining whether the pixel width is greater than the maximum width, splitting the corresponding string of the original subtitle text into multiple sub-strings with approximately the same occupied pixel width.
3. The method according to claim 2, wherein The splitting the corresponding string of the original subtitle text into multiple sub-strings with approximately the same occupied pixel width by determining whether the pixel width is greater than the maximum width includes: Modifying the line break method of the original ASS subtitle file corresponding to the original subtitle text in the graphical user interface to a non-line break and target border drawing method; Traversing and reading each Dialogue item under the Events module of the original ASS subtitle file in the target method, and for the current subtitle text in the current Dialogue item currently read, determining whether the current pixel width occupied by the current subtitle text in the graphical user interface exceeds the maximum width; If the current pixel width does not exceed the maximum width, read the next Dialogue item corresponding to the current Dialogue item in the reading manner of the current Dialogue item; If the current pixel width exceeds the maximum width, according to the font, font size, character spacing of the current subtitle text and the maximum width, split the string corresponding to the current subtitle text into multiple substrings with approximately the same occupied pixel width; wherein, the width occupied by each of the multiple substrings except the last one in the graphical user interface is less than or equal to the maximum width.
4. The method according to claim 3, wherein Writing the multiple lines of the sub-subtitle text into the configuration of the ASS subtitle file in a reverse order, and respectively setting the xbord value under the inline tag of the Dialogue of each line of the sub-subtitle text in the reverse writing manner, includes: After calculating the difference, delete the current Dialogue item, and traverse the string array corresponding to the multiple substrings in a reverse order, and sequentially add Dialogue items according to the attributes of the deleted Dialogue item, wherein the value of the subtitle text of the added Dialogue item is the current string being traversed; Set the xbord value under the inline tag of the Dialogue of the currently added Dialogue item until all items in the string array are traversed.
5. The method according to claim 3, wherein Modifying the line break manner corresponding to the original subtitle text in the graphical user interface of the original ASS subtitle file to a non-line break and target border drawing manner, includes: Set the value of WrapStyle under the Script Info module corresponding to the original ASS subtitle file to 2; Set the value of BorderStyle in the specified Style item under the V4+Styles module corresponding to the original ASS subtitle file to 3.
6. The method according to claim 3, characterized in that Judging whether the current pixel width occupied by the current subtitle text in the graphical user interface exceeds the maximum width, includes: Determine the current pixel width occupied by the current subtitle text in the graphical user interface according to the font, font size and character spacing of the current subtitle text; Judge whether the current pixel width exceeds the maximum width.
7. The method according to claim 1, characterized in that Based on the font, font size, character spacing of the original subtitle text in the ASS subtitle file and the maximum width, splitting the original subtitle text into multiple lines of sub-subtitle text, includes: Set an empty string x, and traverse the string corresponding to the original subtitle text in the ASS subtitle file, sequentially read the traversal result, and append the currently read current character to the end of the string x, so that the value of the string x is updated; Calculate the width occupied by the string x according to the font, font size and character spacing of the string corresponding to the original subtitle text, and judge whether the width occupied by the string x exceeds the maximum width; If the width occupied by the string x does not exceed the maximum width, record the pixel width of the current string x and read the next character of the current character; If the width occupied by the string x exceeds the maximum width, remove the current character at the end of the string x, copy the string x as a new substring, store it in an ordered array, and record the width occupied by the new substring; Replace the value of the string x with the current character and read the next character of the current character until the corresponding string of the original subtitle text is traversed, obtaining a string array that orderly stores a series of new substrings, and the corresponding relationship between the substrings and the widths they occupy respectively.
8. An apparatus for adjusting the width of a background color block based on multi-line subtitles, characterized in that, Comprising: An acquisition module, configured to acquire an ASS subtitle file, and determine the maximum width of the background color block corresponding to the subtitle line in the graphical user interface based on the video width occupied by the video configured in the ASS subtitle file in the graphical user interface; A segmentation module, configured to segment the original subtitle text into multiple lines of subtitle text based on the font, font size, character spacing of the original subtitle text in the ASS subtitle file and the maximum width, so that the width occupied by each line of subtitle text in the graphical user interface is less than or equal to the maximum width, and the width occupied by each line of subtitle text except the last line among the multiple lines of subtitle text is close to the maximum width; A determination module, configured to determine the sub-pixel width actually occupied by each line of subtitle text in the graphical user interface according to the font, font size and character spacing of each line of subtitle text, select the maximum sub-pixel width from the multiple sub-pixel widths corresponding to the multiple lines of subtitle text, and calculate the difference between the sub-pixel width corresponding to each line of subtitle text and the maximum sub-pixel width respectively; A setting module, configured to write the multiple lines of subtitle text into the configuration of the ASS subtitle file in a reverse order, and respectively set an xbord value under the inline tag of Dialogue of each line of subtitle text in the reverse writing method, where the xbord value is the result of taking the integer after dividing the difference corresponding to each line of subtitle text by two; An adjustment module, configured to adjust the initial width of the background color block corresponding to the subtitle line through the set xbord value, so that the adjusted background color block widths corresponding to each subtitle line are the same.
9. An electronic device, comprising a memory and a processor, wherein a computer program capable of running on the processor is stored in the memory, and is characterized in that When the processor executes the computer program, the steps of the method described in any one of claims 1 to 7 above are implemented.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are called and run by the processor, the computer-executable instructions cause the processor to run the method described in any one of claims 1 to 7.
Citation Information
Patent Citations
Video caption text extraction and identification method
CN102332096A
An encoder, a decoder and corresponding methods for local illumination compensation
CN113228632A