### Video clipping:

• Recently, I encountered a demand for tailoring the original film
• For the first time, the operator will cut the video (cutting the beginning and the end of the film, etc.). (The total length of the video is ignored here in units of seconds)

• `[10, 15]`
• `[20, 70]`
• The above two clips will be combined into a new video:`(15-10) + (70-20) = 55`
• When the video is clipped for the second time, the video clipped for the first time will be clipped (such as deleting the middle part, based on the opening and ending of the previous film).

• The clipping time should be calculated on the basis of the first clipping time
• The actual clipping time should be calculated from the original piece

### It’s complicated, but let me give you an example

``\$first = [ // F1 [10, 15], // F2 [20, 70], ]; \$second = [ // S1 [2, 3], // S2 [4, 9], // S3 [45, 55], ]; \$output = [\$output] \$output = [\$output] \$output = [\$output] \$output = [\$output] \$output = [\$output] \$output = [\$output] \$output 24] // The fragment obtained by S3 in F2 [60, 70]];``
• After going through the above process, get`\$output`The results, and then to the original cut.

### The following code

``\$first = [ [10, 15], [20, 70], ]; \$second = [/ / this is the first period of enough [2, 3], / / the first paragraph is not enough, in the second paragraph to completion [4, 9], / / the jump straight to the second paragraph [45, 55],]; var_dump(makeSections(\$first, \$second)); function makeSections(array \$firstCutSections, array \$secondCutSections) : If (empty(\$firstCutsections)) {return \$secondCutsections; } if (empty(\$secondCutSections)) { return \$firstCutSections; } \$newSections = []; foreach (\$secondCutSections as \$currSection) { \$usableSections = \$firstCutSections; \$start = 0; \$usableLength = 0; \$weightLength = \$currSection[1] - \$currSection[0]; // weightLength = \$weightLength; \$remainStart = \$currSection[0]; while (\$remainLength ! If (\$usableLength == 0) {\$SEC = array_shift(\$usableLength == 0) {\$SEC = array_shift(\$usableLength == 0); If (is_null(\$SEC)) {throw new Exception(\$SEC); } \$usableLength = \$sec[1] - \$sec[0]; \$start = \$sec[0]; continue; } // If the coordinates are not aligned, \$remainStart bb0 0) {if (\$remainStart > \$remainStart) {\$remainStart -= \$remainStart; \$start += \$usableLength; \$usableLength = 0; } else { \$usableLength -= \$remainStart; \$start += \$remainStart; \$remainStart = 0; } continue; \$contentLength = 0; \$contentLength = 0; if (\$remainLength > \$usableLength) { \$contentLength = \$usableLength; \$remainLength -= \$usableLength; \$usableLength = 0; } else { \$contentLength = \$remainLength; \$usableLength -= \$remainLength; \$remainLength = 0; } var_dump(\$contentLength); \$newSections[] = [\$start, \$start + \$contentLength,]; } } return \$newSections; }``

The original blog https://www.shiguopeng.cn/archives/522