Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add remove segments support for video studio

Chocobozzz39c06b847751
diff --git a/apps/peertube-runner/src/server/process/shared/process-studio.ts b/apps/peertube-runner/src/server/process/shared/process-studio.ts
index 6a4140846e..836211a227 100644
--- a/apps/peertube-runner/src/server/process/shared/process-studio.ts
+++ b/apps/peertube-runner/src/server/process/shared/process-studio.ts
@@ -6,6 +6,7 @@ import {
VideoStudioTaskIntroPayload,
VideoStudioTaskOutroPayload,
VideoStudioTaskPayload,
+ VideoStudioTaskRemoveSegmentsPayload,
VideoStudioTaskWatermarkPayload,
VideoStudioTranscodingSuccess
} from '@peertube/peertube-models'
@@ -101,7 +102,7 @@ export async function processStudioTranscoding (options: ProcessOptions<RunnerJo
// Private
// ---------------------------------------------------------------------------
-type TaskProcessorOptions <T extends VideoStudioTaskPayload = VideoStudioTaskPayload> = {
+type TaskProcessorOptions<T extends VideoStudioTaskPayload = VideoStudioTaskPayload> = {
videoInputPath: string
separatedAudioInputPath: string
@@ -116,7 +117,8 @@ const taskProcessors: { [id in VideoStudioTask['name']]: (options: TaskProcessor
'add-intro': processAddIntroOutro,
'add-outro': processAddIntroOutro,
'cut': processCut,
- 'add-watermark': processAddWatermark
+ 'add-watermark': processAddWatermark,
+ 'remove-segments': processRemoveSegments
}
async function processTask (options: TaskProcessorOptions) {
@@ -162,6 +164,18 @@ function processCut (options: TaskProcessorOptions<VideoStudioTaskCutPayload>) {
})
}
+function processRemoveSegments (options: TaskProcessorOptions<VideoStudioTaskRemoveSegmentsPayload>) {
+ const { videoInputPath, task } = options
+
+ logger.debug(`Removing segments from ${videoInputPath}`)
+
+ return buildFFmpegEdition().removeSegments({
+ ...pick(options, [ 'videoInputPath', 'separatedAudioInputPath', 'outputPath' ]),
+
+ segments: task.options.segments
+ })
+}
+
async function processAddWatermark (options: TaskProcessorOptions<VideoStudioTaskWatermarkPayload>) {
const { videoInputPath, task, runnerToken, job } = options
@@ -177,7 +191,7 @@ async function processAddWatermark (options: TaskProcessorOptions<VideoStudioTas
videoFilters: {
watermarkSizeRatio: task.options.watermarkSizeRatio,
- horitonzalMarginRatio: task.options.horitonzalMarginRatio,
+ horizontalMarginRatio: task.options.horizontalMarginRatio,
verticalMarginRatio: task.options.verticalMarginRatio
}
})
diff --git a/apps/peertube-runner/src/server/shared/supported-job.ts b/apps/peertube-runner/src/server/shared/supported-job.ts
index 1468b417a6..eca9377f69 100644
--- a/apps/peertube-runner/src/server/shared/supported-job.ts
+++ b/apps/peertube-runner/src/server/shared/supported-job.ts
@@ -26,7 +26,7 @@ const supportedMatrix: { [id in RunnerJobType]: (payload: RunnerJobPayload) => b
},
'video-studio-transcoding': (payload: RunnerJobStudioTranscodingPayload) => {
const tasks = payload?.tasks
- const supported = new Set<VideoStudioTaskPayload['name']>([ 'add-intro', 'add-outro', 'add-watermark', 'cut' ])
+ const supported = new Set<VideoStudioTaskPayload['name']>([ 'add-intro', 'add-outro', 'add-watermark', 'cut', 'remove-segments' ])
if (!Array.isArray(tasks)) return false
diff --git a/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts b/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts
index 8490812887..96a3f6034f 100644
--- a/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts
+++ b/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts
@@ -24,6 +24,7 @@ import {
VideoStateType,
VideoStudioTask,
VideoStudioTaskCut,
+ VideoStudioTaskRemoveSegments,
VideoUpdate
} from '@peertube/peertube-models'
import { logger } from '@root-helpers/logger'
@@ -74,6 +75,7 @@ type StudioForm = {
'add-intro'?: { file?: File }
'add-outro'?: { file?: File }
'add-watermark'?: { file?: File }
+ 'remove-segments'?: { start?: number, end?: number }[]
}
type PlayerSettingsForm = PlayerVideoSettingsUpdate
@@ -868,6 +870,14 @@ export class VideoEdit {
}
})
}
+
+ const removeSegments = (values['remove-segments'] ?? []).filter(s =>
+ exists(s.start) && exists(s.end)
+ ) as VideoStudioTaskRemoveSegments['options']['segments']
+
+ if (removeSegments.length > 0) {
+ this.studioTasks.push({ name: 'remove-segments', options: { segments: removeSegments } })
+ }
}
toStudioFormPatch (): Required<StudioForm> {
@@ -875,6 +885,7 @@ export class VideoEdit {
const addIntro = this.studioTasks.find(t => t.name === 'add-intro')
const addOutro = this.studioTasks.find(t => t.name === 'add-outro')
const addWatermark = this.studioTasks.find(t => t.name === 'add-watermark')
+ const removeSegments = this.studioTasks.find(t => t.name === 'remove-segments')
return {
'cut': {
@@ -883,7 +894,8 @@ export class VideoEdit {
},
'add-intro': { file: addIntro?.options?.file as File ?? null },
'add-outro': { file: addOutro?.options?.file as File },
- 'add-watermark': { file: addWatermark?.options?.file as File }
+ 'add-watermark': { file: addWatermark?.options?.file as File },
+ 'remove-segments': removeSegments?.options?.segments ?? []
}
}
@@ -970,37 +982,35 @@ export class VideoEdit {
}
getStudioTasksSummary () {
- return this.getStudioTasks().map(t => {
- if (t.name === 'add-intro') {
- return $localize`"${(t.options.file as File).name}" will be added at the beginning of the video`
- }
-
- if (t.name === 'add-outro') {
- return $localize`"${(t.options.file as File).name}" will be added at the end of the video`
- }
+ const summary: string[] = []
- if (t.name === 'add-watermark') {
- return $localize`"${(t.options.file as File).name}" image watermark will be added to the video`
- }
-
- if (t.name === 'cut') {
+ for (const t of this.getStudioTasks()) {
+ if (t.name === 'add-intro') {
+ summary.push($localize`"${(t.options.file as File).name}" will be added at the beginning of the video`)
+ } else if (t.name === 'add-outro') {
+ summary.push($localize`"${(t.options.file as File).name}" will be added at the end of the video`)
+ } else if (t.name === 'add-watermark') {
+ summary.push($localize`"${(t.options.file as File).name}" image watermark will be added to the video`)
+ } else if (t.name === 'cut') {
const { start, end } = t.options
if (start !== undefined && end !== undefined) {
- return $localize`Video will begin at ${secondsToTime(start)} and stop at ${secondsToTime(end)}`
+ summary.push($localize`Video will begin at ${secondsToTime(start)} and stop at ${secondsToTime(end)}`)
+ } else if (start !== undefined) {
+ summary.push($localize`Video will begin at ${secondsToTime(start)}`)
+ } else if (end !== undefined) {
+ summary.push($localize`Video will stop at ${secondsToTime(end)}`)
}
+ } else if (t.name === 'remove-segments') {
+ for (let i = 1; i <= t.options.segments.length; i++) {
+ const parts = t.options.segments[i - 1]
- if (start !== undefined) {
- return $localize`Video will begin at ${secondsToTime(start)}`
- }
-
- if (end !== undefined) {
- return $localize`Video will stop at ${secondsToTime(end)}`
+ summary.push($localize`Remove segment ${i} – ${secondsToTime(parts.start)} to ${secondsToTime(parts.end)}`)
}
}
+ }
- return ''
- })
+ return summary
}
// ---------------------------------------------------------------------------
diff --git a/client/src/app/+videos-publish-manage/shared-manage/studio/video-studio.component.html b/client/src/app/+videos-publish-manage/shared-manage/studio/video-studio.component.html
index e56220927b..b3722a5dba 100644
--- a/client/src/app/+videos-publish-manage/shared-manage/studio/video-studio.component.html
+++ b/client/src/app/+videos-publish-manage/shared-manage/studio/video-studio.component.html
@@ -8,65 +8,133 @@
<my-alert type="primary">{{ getUnavailability() }}</my-alert>
} @else {
<div class="grid-container">
- <form [formGroup]="form" id="video-manage-form">
-
- <div class="section cut" formGroupName="cut">
+ <form id="video-manage-form">
+ <div class="section cut">
<h3 class="section-label" i18n>CUT VIDEO</h3>
<div i18n class="description">Set a new start/end.</div>
<div class="form-group">
<label i18n for="cutStart">New start</label>
- <my-timestamp-input inputName="cutStart" enableBorder="true" [maxTimestamp]="videoEdit.getVideoAttributes().duration" formControlName="start"></my-timestamp-input>
+ <my-timestamp-input
+ inputName="cutStart"
+ enableBorder="true"
+ [maxTimestamp]="videoEdit.getVideoAttributes().duration"
+ [formField]="studioForm.cut.start"
+ ></my-timestamp-input>
</div>
<div class="form-group">
<label i18n for="cutEnd">New end</label>
- <my-timestamp-input inputName="cutEnd" enableBorder="true" [maxTimestamp]="videoEdit.getVideoAttributes().duration" formControlName="end"></my-timestamp-input>
+ <my-timestamp-input
+ inputName="cutEnd"
+ enableBorder="true"
+ [maxTimestamp]="videoEdit.getVideoAttributes().duration"
+ [formField]="studioForm.cut.end"
+ ></my-timestamp-input>
</div>
</div>
- <div class="section" formGroupName="add-intro">
+ <div class="section">
<h3 class="section-label" i18n>ADD INTRO</h3>
<div i18n class="description">Concatenate a file at the beginning of the video.</div>
<div class="form-group">
<my-reactive-file
- formControlName="file" inputName="addIntroFile" i18n-inputLabel inputLabel="Select the intro video file"
- [extensions]="videoExtensions" [displayFilename]="true" [displayReset]="true"
+ [formField]="studioForm['add-intro'].file"
+ inputName="addIntroFile"
+ i18n-inputLabel
+ inputLabel="Select the intro video file"
+ [extensions]="videoExtensions"
+ [displayFilename]="true"
+ [displayReset]="true"
[buttonTooltip]="getIntroOutroTooltip()"
></my-reactive-file>
</div>
</div>
- <div class="section" formGroupName="add-outro">
+ <div class="section">
<h3 class="section-label" i18n>ADD OUTRO</h3>
<div i18n class="description">Concatenate a file at the end of the video.</div>
<div class="form-group">
<my-reactive-file
- formControlName="file" inputName="addOutroFile" i18n-inputLabel inputLabel="Select the outro video file"
- [extensions]="videoExtensions" [displayFilename]="true" [displayReset]="true"
+ [formField]="studioForm['add-outro'].file"
+ inputName="addOutroFile"
+ i18n-inputLabel
+ inputLabel="Select the outro video file"
+ [extensions]="videoExtensions"
+ [displayFilename]="true"
+ [displayReset]="true"
[buttonTooltip]="getIntroOutroTooltip()"
></my-reactive-file>
</div>
</div>
- <div class="section" formGroupName="add-watermark">
+ <div class="section">
<h3 class="section-label" i18n>ADD WATERMARK</h3>
<div i18n class="description">Add a watermark image to the video.</div>
<div class="form-group">
<my-reactive-file
- formControlName="file" inputName="addWatermarkFile" i18n-inputLabel inputLabel="Select watermark image file"
- [extensions]="imageExtensions" [displayFilename]="true" [displayReset]="true"
+ [formField]="studioForm['add-watermark'].file"
+ inputName="addWatermarkFile"
+ i18n-inputLabel
+ inputLabel="Select watermark image file"
+ [extensions]="imageExtensions"
+ [displayFilename]="true"
+ [displayReset]="true"
[buttonTooltip]="getWatermarkTooltip()"
></my-reactive-file>
</div>
</div>
+
+ <div class="section remove-segments">
+ <h3 class="section-label" i18n>REMOVE SEGMENTS</h3>
+
+ <div i18n class="description">Remove specific segments of the video. Each segment requires a start and end time.</div>
+
+ @for (_ of removeSegments; track $index; let i = $index) {
+ <div class="remove-segment form-group">
+ <span class="remove-segment-label" i18n>Segment {{ i + 1 }} to remove</span>
+
+ <div class="remove-segment-inputs">
+ <div>
+ <label i18n [for]="'removeStart-' + i">Start</label>
+ <my-timestamp-input
+ [inputName]="'removeStart-' + i"
+ enableBorder="true"
+ [maxTimestamp]="videoEdit.getVideoAttributes().duration"
+ [formField]="studioForm['remove-segments'][i].start"
+ ></my-timestamp-input>
+ </div>
+
+ <div>
+ <label i18n [for]="'removeEnd-' + i">End</label>
+ <my-timestamp-input
+ [inputName]="'removeEnd-' + i"
+ enableBorder="true"
+ [maxTimestamp]="videoEdit.getVideoAttributes().duration"
+ [formField]="studioForm['remove-segments'][i].end"
+ ></my-timestamp-input>
+ </div>
+
+ <my-button theme="secondary" (click)="removeSegmentRemoval(i)" icon="delete" i18n-title title="Cancel segment removal"></my-button>
+ </div>
+
+ <my-form-error [field]="studioForm['remove-segments'][i]()"></my-form-error>
+ </div>
+ }
+
+ <div class="form-group">
+ <my-form-error class="d-block mb-3" [field]="studioForm['remove-segments']()"></my-form-error>
+
+ <my-button theme="secondary" (click)="addSegmentRemoval()" i18n>Add segment to remove</my-button>
+ </div>
+ </div>
</form>
<div class="embed-container">
diff --git a/client/src/app/+videos-publish-manage/shared-manage/studio/video-studio.component.scss b/client/src/app/+videos-publish-manage/shared-manage/studio/video-studio.component.scss
index 6fca8b845d..70c63bc2af 100644
--- a/client/src/app/+videos-publish-manage/shared-manage/studio/video-studio.component.scss
+++ b/client/src/app/+videos-publish-manage/shared-manage/studio/video-studio.component.scss
@@ -1,5 +1,5 @@
-@use '_variables' as *;
-@use '_mixins' as *;
+@use "_variables" as *;
+@use "_mixins" as *;
my-timestamp-input {
display: block;
@@ -70,7 +70,8 @@ h3 {
border-radius: 5px;
width: fit-content;
- @include padding-left(10px);
+ @include padding-left(0.75rem);
+ @include padding-right(0.75rem);
.form-group,
.description {
@@ -98,3 +99,31 @@ my-reactive-file {
display: block;
width: fit-content;
}
+
+.remove-segment {
+ margin-bottom: 1rem;
+ padding-bottom: 1rem;
+ border-bottom: 1px solid pvar(--border-secondary);
+
+ &:last-of-type {
+ border-bottom: 0;
+ }
+}
+
+.remove-segment-label {
+ display: block;
+ font-weight: $font-semibold;
+ margin-bottom: 0.5rem;
+}
+
+.remove-segment-inputs {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: flex-end;
+
+ @include rfs(1.5rem, gap);
+
+ .form-group {
+ margin: 0;
+ }
+}
diff --git a/client/src/app/+videos-publish-manage/shared-manage/studio/video-studio.component.ts b/client/src/app/+videos-publish-manage/shared-manage/studio/video-studio.component.ts
index fe6dcaae71..0ef4f26c3b 100644
--- a/client/src/app/+videos-publish-manage/shared-manage/studio/video-studio.component.ts
+++ b/client/src/app/+videos-publish-manage/shared-manage/studio/video-studio.component.ts
@@ -1,12 +1,13 @@
-
-import { Component, OnDestroy, OnInit, inject } from '@angular/core'
-import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms'
+import { Component, Injector, OnDestroy, OnInit, effect, inject, signal } from '@angular/core'
+import { FormField, applyEach, form, validate } from '@angular/forms/signals'
import { ServerService } from '@app/core'
-import { FormReactiveErrors, FormReactiveService, FormReactiveMessages } from '@app/shared/shared-forms/form-reactive.service'
+import { FormErrorComponent } from '@app/shared/shared-forms/form-error.component'
import { ReactiveFileComponent } from '@app/shared/shared-forms/reactive-file.component'
import { TimestampInputComponent } from '@app/shared/shared-forms/timestamp-input.component'
import { GlobalIconComponent } from '@app/shared/shared-icons/global-icon.component'
+import { ButtonComponent } from '@app/shared/shared-main/buttons/button.component'
import { EmbedComponent } from '@app/shared/shared-main/video/embed.component'
+import { sortBy } from '@peertube/peertube-core-utils'
import debug from 'debug'
import { Subscription } from 'rxjs'
import { AlertComponent } from '../../../shared/shared-main/common/alert.component'
@@ -16,11 +17,14 @@ import { VideoManageController } from '../video-manage-controller.service'
const debugLogger = debug('peertube:video-manage')
-type Form = {
- 'cut': FormGroup<{ start: FormControl<number>, end: FormControl<number> }>
- 'add-intro': FormGroup<{ file: FormControl<File> }>
- 'add-outro': FormGroup<{ file: FormControl<File> }>
- 'add-watermark': FormGroup<{ file: FormControl<File> }>
+type Segment = { start: number, end: number }
+
+type StudioModel = {
+ cut: Segment
+ 'add-intro': { file: File | null }
+ 'add-outro': { file: File | null }
+ 'add-watermark': { file: File | null }
+ 'remove-segments': Segment[]
}
@Component({
@@ -31,32 +35,63 @@ type Form = {
'./video-studio.component.scss'
],
imports: [
- FormsModule,
- ReactiveFormsModule,
TimestampInputComponent,
ReactiveFileComponent,
EmbedComponent,
GlobalIconComponent,
- AlertComponent
-]
+ AlertComponent,
+ ButtonComponent,
+ FormField,
+ FormErrorComponent
+ ]
})
export class VideoStudioEditComponent implements OnInit, OnDestroy {
- private formReactiveService = inject(FormReactiveService)
+ private readonly injector = inject(Injector)
private serverService = inject(ServerService)
private manageController = inject(VideoManageController)
- form: FormGroup<Form>
- formErrors: FormReactiveErrors = {}
- validationMessages: FormReactiveMessages = {}
+ readonly studioModel = signal<StudioModel>({
+ 'cut': { start: 0, end: 0 },
+ 'add-intro': { file: null },
+ 'add-outro': { file: null },
+ 'add-watermark': { file: null },
+ 'remove-segments': []
+ })
+
+ readonly studioForm = form(this.studioModel, f => {
+ validate(f['remove-segments'], ({ value }) => {
+ const sorted = sortBy(value().filter(s => s.start < s.end), 'start')
+
+ for (let i = 0; i < sorted.length - 1; i++) {
+ if (sorted[i].end > sorted[i + 1].start) {
+ return { kind: 'segmentsOverlap', message: $localize`Segments must not overlap each other.` }
+ }
+ }
+ return null
+ })
+
+ applyEach(
+ f['remove-segments'],
+ seg => {
+ validate(seg, ({ value }) => {
+ const { start, end } = value()
+
+ return start >= end
+ ? { kind: 'startAfterEnd', message: $localize`Start time must be before end time.` }
+ : null
+ })
+ }
+ )
+ })
isRunningEdit = false
- videoEdit: VideoEdit
+ videoEdit!: VideoEdit
- studioEnabled: boolean
- instanceName: string
+ studioEnabled = false
+ instanceName = ''
- private updatedSub: Subscription
+ private updatedSub!: Subscription
ngOnInit () {
this.videoEdit = this.manageController.getStore().videoEdit
@@ -65,39 +100,23 @@ export class VideoStudioEditComponent implements OnInit, OnDestroy {
this.studioEnabled = config.videoStudio.enabled === true
this.instanceName = config.instance.name
- const { form, formErrors, validationMessages } = this.formReactiveService.buildForm<Form>({
- 'cut': {
- start: null,
- end: null
- },
- 'add-intro': {
- file: null
- },
- 'add-outro': {
- file: null
- },
- 'add-watermark': {
- file: null
- }
- }, this.videoEdit.toStudioFormPatch())
+ this.syncModelFromPatch()
- this.form = form
- this.formErrors = formErrors
- this.validationMessages = validationMessages
+ effect(() => {
+ const values = this.studioModel()
+ const errors = this.studioForm().errorSummary()
+ const formErrors = Object.fromEntries(errors.map(e => [ e.kind, e.message ?? e.kind ]))
- this.form.valueChanges.subscribe(() => {
- this.manageController.setFormError($localize`Studio`, 'studio', this.formErrors)
-
- const formValues = this.form.value
- debugLogger('Updating form values', formValues)
-
- this.videoEdit.loadFromStudioForm(formValues)
- })
+ setTimeout(() => {
+ debugLogger('Updating form values', values)
+ this.videoEdit.loadFromStudioForm(values)
- this.formReactiveService.markAllAsDirty(this.form.controls)
+ this.manageController.setFormError($localize`Studio`, 'studio', formErrors)
+ })
+ }, { injector: this.injector })
this.updatedSub = this.manageController.getUpdatedObs().subscribe(() => {
- this.form.patchValue(this.videoEdit.toStudioFormPatch())
+ this.syncModelFromPatch()
})
}
@@ -113,6 +132,10 @@ export class VideoStudioEditComponent implements OnInit, OnDestroy {
return this.serverService.getHTMLConfig().video.image.extensions
}
+ get removeSegments () {
+ return this.studioModel()['remove-segments']
+ }
+
getIntroOutroTooltip () {
return $localize`(extensions: ${this.videoExtensions.join(', ')})`
}
@@ -121,6 +144,22 @@ export class VideoStudioEditComponent implements OnInit, OnDestroy {
return $localize`(extensions: ${this.imageExtensions.join(', ')})`
}
+ addSegmentRemoval (start = 0, end = this.videoEdit?.getVideoAttributes().duration ?? 0) {
+ this.studioModel.update(m => ({
+ ...m,
+
+ 'remove-segments': [ ...m['remove-segments'], { start, end } ]
+ }))
+ }
+
+ removeSegmentRemoval (index: number) {
+ this.studioModel.update(m => ({
+ ...m,
+
+ 'remove-segments': m['remove-segments'].filter((_, i) => i !== index)
+ }))
+ }
+
noEdit () {
return this.videoEdit.getStudioTasks().length === 0
}
@@ -133,4 +172,20 @@ export class VideoStudioEditComponent implements OnInit, OnDestroy {
studioEnabled: this.studioEnabled
})
}
+
+ private syncModelFromPatch () {
+ const patch = this.videoEdit.toStudioFormPatch()
+ const duration = this.videoEdit.getVideoAttributes().duration
+
+ this.studioModel.set({
+ 'cut': {
+ start: patch.cut?.start ?? 0,
+ end: patch.cut?.end ?? duration
+ },
+ 'add-intro': { file: patch['add-intro']?.file ?? null },
+ 'add-outro': { file: patch['add-outro']?.file ?? null },
+ 'add-watermark': { file: patch['add-watermark']?.file ?? null },
+ 'remove-segments': (patch['remove-segments'] ?? []).map(s => ({ start: s.start ?? 0, end: s.end ?? 0 }))
+ })
+ }
}
diff --git a/client/src/app/+videos-publish-manage/shared-manage/video-manage-container.component.ts b/client/src/app/+videos-publish-manage/shared-manage/video-manage-container.component.ts
index 42fde21bc0..9b37f7cd2f 100644
--- a/client/src/app/+videos-publish-manage/shared-manage/video-manage-container.component.ts
+++ b/client/src/app/+videos-publish-manage/shared-manage/video-manage-container.component.ts
@@ -112,6 +112,9 @@ export class VideoManageContainerComponent implements OnInit, OnDestroy {
if (this.hasFormErrors()) {
this.displayFormErrorsMsg = true
+
+ window.scrollTo({ top: 0, behavior: 'instant' })
+
return
}
diff --git a/client/src/app/shared/shared-forms/form-error.component.html b/client/src/app/shared/shared-forms/form-error.component.html
new file mode 100644
index 0000000000..4e10d70863
--- /dev/null
+++ b/client/src/app/shared/shared-forms/form-error.component.html
@@ -0,0 +1,5 @@
+@if (field().touched() && field().invalid()) {
+ @for (err of field().errors(); track err.kind) {
+ <div class="form-error" role="alert">{{ err.message }}</div>
+ }
+}
diff --git a/client/src/app/shared/shared-forms/form-error.component.ts b/client/src/app/shared/shared-forms/form-error.component.ts
new file mode 100644
index 0000000000..603a39b9e4
--- /dev/null
+++ b/client/src/app/shared/shared-forms/form-error.component.ts
@@ -0,0 +1,13 @@
+import { ChangeDetectionStrategy, Component, input } from '@angular/core'
+import { FieldState } from '@angular/forms/signals'
+
+@Component({
+ selector: 'my-form-error',
+ templateUrl: './form-error.component.html',
+ styleUrls: [],
+ imports: [],
+ changeDetection: ChangeDetectionStrategy.OnPush
+})
+export class FormErrorComponent {
+ field = input.required<FieldState<any>>()
+}
diff --git a/client/src/app/shared/shared-forms/timestamp-input.component.ts b/client/src/app/shared/shared-forms/timestamp-input.component.ts
index 8c93366b1c..270e4be95b 100644
--- a/client/src/app/shared/shared-forms/timestamp-input.component.ts
+++ b/client/src/app/shared/shared-forms/timestamp-input.component.ts
@@ -44,6 +44,10 @@ export class TimestampInputComponent implements ControlValueAccessor, OnInit {
// empty
}
+ onTouched = () => {
+ // empty
+ }
+
writeValue (timestamp: number) {
this.timestamp.set(timestamp)
this.timestampString = this.formatter()(this.timestamp())
@@ -53,8 +57,8 @@ export class TimestampInputComponent implements ControlValueAccessor, OnInit {
this.propagateChange = fn
}
- registerOnTouched () {
- // Unused
+ registerOnTouched (fn: () => void) {
+ this.onTouched = fn
}
onModelChange () {
@@ -64,6 +68,8 @@ export class TimestampInputComponent implements ControlValueAccessor, OnInit {
}
onBlur () {
+ this.onTouched()
+
const maxTimestamp = this.maxTimestamp()
if (maxTimestamp && this.timestamp() > maxTimestamp) {
this.writeValue(maxTimestamp)
diff --git a/packages/ffmpeg/src/ffmpeg-edition.ts b/packages/ffmpeg/src/ffmpeg-edition.ts
index 89de5c493d..c31cb00436 100644
--- a/packages/ffmpeg/src/ffmpeg-edition.ts
+++ b/packages/ffmpeg/src/ffmpeg-edition.ts
@@ -67,7 +67,7 @@ export class FFmpegEdition {
videoFilters: {
watermarkSizeRatio: number
- horitonzalMarginRatio: number
+ horizontalMarginRatio: number
verticalMarginRatio: number
}
}
@@ -115,7 +115,7 @@ export class FFmpegEdition {
inputs: [ `[${videoInput}]`, '[watermark]' ],
filter: 'overlay',
options: {
- x: `main_w - overlay_w - (main_h * ${videoFilters.horitonzalMarginRatio})`,
+ x: `main_w - overlay_w - (main_h * ${videoFilters.horizontalMarginRatio})`,
y: `main_h * ${videoFilters.verticalMarginRatio}`
}
}
@@ -270,6 +270,118 @@ export class FFmpegEdition {
await this.commandWrapper.runCommand()
}
+ async removeSegments (
+ options: BaseStudioOptions & {
+ segments: { start: number, end: number }[]
+ }
+ ) {
+ const { videoInputPath, separatedAudioInputPath, outputPath, inputFileMutexReleaser, segments } = options
+
+ const mainProbe = await ffprobePromise(videoInputPath)
+ const fps = await getVideoStreamFPS(videoInputPath, mainProbe)
+ const { resolution } = await getVideoStreamDimensionsInfo(videoInputPath, mainProbe)
+ const duration = await getVideoStreamDuration(videoInputPath, mainProbe)
+
+ const mainHasAudio = await hasAudioStream(separatedAudioInputPath || videoInputPath)
+
+ const videoInput = 0
+ const audioInput = separatedAudioInputPath ? 1 : 0
+
+ // Compute keep intervals as the inverse of the delete segments
+ const sortedSegments = [ ...segments ].sort((a, b) => a.start - b.start)
+ const keepIntervals: { start: number, end: number }[] = []
+
+ let pos = 0
+ for (const seg of sortedSegments) {
+ if (seg.start > pos) keepIntervals.push({ start: pos, end: seg.start })
+ pos = seg.end
+ }
+ if (pos < duration) keepIntervals.push({ start: pos, end: duration })
+
+ if (keepIntervals.length === 0) throw new Error('No video content remains after applying remove segments')
+
+ const command = this.commandWrapper.buildCommand(this.buildInputs(options), inputFileMutexReleaser)
+ .output(outputPath)
+
+ await presetVOD({
+ commandWrapper: this.commandWrapper,
+
+ videoInputPath,
+ separatedAudioInputPath,
+
+ resolution,
+ videoStreamOnly: false,
+ fps,
+ canCopyAudio: false,
+ canCopyVideo: false
+ })
+
+ const N = keepIntervals.length
+ const complexFilter: FilterSpecification[] = []
+
+ // Split input streams so each keep interval gets its own copy
+ complexFilter.push({
+ inputs: [ `${videoInput}:v` ],
+ filter: 'split',
+ options: N,
+ outputs: keepIntervals.map((_, i) => `vsrc${i}`)
+ })
+
+ if (mainHasAudio) {
+ complexFilter.push({
+ inputs: [ `${audioInput}:a` ],
+ filter: 'asplit',
+ options: N,
+ outputs: keepIntervals.map((_, i) => `asrc${i}`)
+ })
+ }
+
+ // Trim each keep interval and reset timestamps
+ for (let i = 0; i < N; i++) {
+ const { start, end } = keepIntervals[i]
+
+ complexFilter.push(
+ { inputs: [ `vsrc${i}` ], filter: 'trim', options: { start, end }, outputs: [ `vtrimmed${i}` ] },
+ { inputs: [ `vtrimmed${i}` ], filter: 'setpts', options: 'PTS-STARTPTS', outputs: [ `v${i}` ] }
+ )
+
+ if (mainHasAudio) {
+ complexFilter.push(
+ { inputs: [ `asrc${i}` ], filter: 'atrim', options: { start, end }, outputs: [ `atrimmed${i}` ] },
+ { inputs: [ `atrimmed${i}` ], filter: 'asetpts', options: 'PTS-STARTPTS', outputs: [ `a${i}` ] }
+ )
+ }
+ }
+
+ // Concatenate all keep intervals
+ const concatInputs: string[] = []
+ for (let i = 0; i < N; i++) {
+ concatInputs.push(`v${i}`)
+ if (mainHasAudio) concatInputs.push(`a${i}`)
+ }
+
+ const concatOptions: Record<string, number> = { n: N, v: 1 }
+ const concatOutputs = [ 'vout' ]
+
+ if (mainHasAudio) {
+ concatOptions.a = 1
+ concatOutputs.push('aout')
+ }
+
+ complexFilter.push({
+ inputs: concatInputs,
+ filter: 'concat',
+ options: concatOptions,
+ outputs: concatOutputs
+ })
+
+ command.complexFilter(complexFilter)
+ command.outputOption('-map [vout]')
+ if (mainHasAudio) command.outputOption('-map [aout]')
+
+ await this.commandWrapper.runCommand()
+ }
+
private buildInputs (options: {
videoInputPath: string
separatedAudioInputPath?: string
diff --git a/packages/models/src/server/job.model.ts b/packages/models/src/server/job.model.ts
index 64117fa0e8..dda828063c 100644
--- a/packages/models/src/server/job.model.ts
+++ b/packages/models/src/server/job.model.ts
@@ -254,16 +254,28 @@ export type VideoStudioTaskWatermarkPayload = {
file: string
watermarkSizeRatio: number
- horitonzalMarginRatio: number
+ horizontalMarginRatio: number
verticalMarginRatio: number
}
}
+export type VideoStudioTaskRemoveSegmentsPayload = {
+ name: 'remove-segments'
+
+ options: {
+ segments: {
+ start: number
+ end: number
+ }[]
+ }
+}
+
export type VideoStudioTaskPayload =
| VideoStudioTaskCutPayload
| VideoStudioTaskIntroPayload
| VideoStudioTaskOutroPayload
| VideoStudioTaskWatermarkPayload
+ | VideoStudioTaskRemoveSegmentsPayload
export interface VideoStudioEditionPayload {
videoUUID: string
diff --git a/packages/models/src/videos/studio/video-studio-create-edit.model.ts b/packages/models/src/videos/studio/video-studio-create-edit.model.ts
index 5e8296dc9f..9d96485a5f 100644
--- a/packages/models/src/videos/studio/video-studio-create-edit.model.ts
+++ b/packages/models/src/videos/studio/video-studio-create-edit.model.ts
@@ -3,10 +3,11 @@ export interface VideoStudioCreateEdition {
}
export type VideoStudioTask =
- VideoStudioTaskCut |
- VideoStudioTaskIntro |
- VideoStudioTaskOutro |
- VideoStudioTaskWatermark
+ | VideoStudioTaskCut
+ | VideoStudioTaskIntro
+ | VideoStudioTaskOutro
+ | VideoStudioTaskWatermark
+ | VideoStudioTaskRemoveSegments
export interface VideoStudioTaskCut {
name: 'cut'
@@ -41,6 +42,17 @@ export interface VideoStudioTaskWatermark {
}
}
+export interface VideoStudioTaskRemoveSegments {
+ name: 'remove-segments'
+
+ options: {
+ segments: {
+ start: number
+ end: number
+ }[]
+ }
+}
+
// ---------------------------------------------------------------------------
export function isVideoStudioTaskIntro (v: VideoStudioTask): v is VideoStudioTaskIntro {
@@ -58,3 +70,7 @@ export function isVideoStudioTaskWatermark (v: VideoStudioTask): v is VideoStudi
export function hasVideoStudioTaskFile (v: VideoStudioTask): v is VideoStudioTaskIntro | VideoStudioTaskOutro | VideoStudioTaskWatermark {
return isVideoStudioTaskIntro(v) || isVideoStudioTaskOutro(v) || isVideoStudioTaskWatermark(v)
}
+
+export function isVideoStudioTaskRemoveSegments (v: VideoStudioTask): v is VideoStudioTaskRemoveSegments {
+ return v.name === 'remove-segments'
+}
diff --git a/packages/server-commands/src/videos/video-studio-command.ts b/packages/server-commands/src/videos/video-studio-command.ts
index 8c5ff169ad..bcfcf0f903 100644
--- a/packages/server-commands/src/videos/video-studio-command.ts
+++ b/packages/server-commands/src/videos/video-studio-command.ts
@@ -2,7 +2,6 @@ import { HttpStatusCode, VideoStudioTask } from '@peertube/peertube-models'
import { AbstractCommand, OverrideCommandOptions } from '../shared/index.js'
export class VideoStudioCommand extends AbstractCommand {
-
static getComplexTask (): VideoStudioTask[] {
return [
// Total duration: 2
@@ -22,6 +21,17 @@ export class VideoStudioCommand extends AbstractCommand {
}
},
+ // Total duration: 4
+ {
+ name: 'remove-segments',
+ options: {
+ segments: [
+ { start: 0, end: 2 },
+ { start: 6, end: 7 }
+ ]
+ }
+ },
+
{
name: 'add-watermark',
options: {
@@ -29,7 +39,7 @@ export class VideoStudioCommand extends AbstractCommand {
}
},
- // Total duration: 9
+ // Total duration: 6
{
name: 'add-intro',
options: {
@@ -39,10 +49,16 @@ export class VideoStudioCommand extends AbstractCommand {
]
}
- createEditionTasks (options: OverrideCommandOptions & {
- videoId: number | string
- tasks: VideoStudioTask[]
- }) {
+ static getComplexTaskVideoDuration (baseDuration = 5) {
+ return baseDuration - 3 /* cut */ + 5 /* add-outro */ - 3 /* remove-segments */ + 2 /* add-intro */
+ }
+
+ createEditionTasks (
+ options: OverrideCommandOptions & {
+ videoId: number | string
+ tasks: VideoStudioTask[]
+ }
+ ) {
const path = '/api/v1/videos/' + options.videoId + '/studio/edit'
const attaches: { [id: string]: any } = {}
diff --git a/packages/tests/src/api/check-params/video-studio.ts b/packages/tests/src/api/check-params/video-studio.ts
index 1da3726f4a..13de04eef9 100644
--- a/packages/tests/src/api/check-params/video-studio.ts
+++ b/packages/tests/src/api/check-params/video-studio.ts
@@ -390,6 +390,74 @@ describe('Test video studio API validator', function () {
}
})
})
+
+ describe('Remove segments task', function () {
+ async function removeSegments (
+ segments: { start: number, end: number }[],
+ expectedStatus: HttpStatusCodeType = HttpStatusCode.BAD_REQUEST_400
+ ) {
+ await command.createEditionTasks({
+ videoId: videoUUID,
+ tasks: [
+ {
+ name: 'remove-segments',
+ options: { segments }
+ }
+ ],
+ expectedStatus
+ })
+ }
+
+ it('Should fail with empty segments', async function () {
+ await removeSegments([])
+ })
+
+ it('Should fail with invalid segment start', async function () {
+ const invalidStarts = [ 'tintin', -1, undefined ] as any[]
+
+ for (const start of invalidStarts) {
+ await removeSegments([ { start, end: 5 } ])
+ }
+ })
+
+ it('Should fail with invalid segment end', async function () {
+ await removeSegments([ { start: 1, end: 0 } ])
+ await removeSegments([ { start: 1, end: -1 } ] as any)
+ await removeSegments([ { start: 1, end: 'tintin' } ] as any)
+ })
+
+ it('Should fail when start equals end', async function () {
+ await removeSegments([ { start: 3, end: 3 } ])
+ })
+
+ it('Should fail when start is greater than end', async function () {
+ await removeSegments([ { start: 5, end: 2 } ])
+ })
+
+ it('Should fail with overlapping segments', async function () {
+ await removeSegments([ { start: 1, end: 5 }, { start: 3, end: 7 } ])
+ })
+
+ it('Should fail with unordered overlapping segments', async function () {
+ await removeSegments([ { start: 5, end: 8 }, { start: 1, end: 6 } ])
+ })
+
+ it('Should succeed with a single valid segment', async function () {
+ this.timeout(360000)
+
+ await removeSegments([ { start: 1, end: 3 } ], HttpStatusCode.NO_CONTENT_204)
+
+ await waitJobs([ server ])
+ })
+
+ it('Should succeed with multiple valid non-overlapping segments', async function () {
+ this.timeout(360000)
+
+ await removeSegments([ { start: 1, end: 3 }, { start: 5, end: 7 } ], HttpStatusCode.NO_CONTENT_204)
+
+ await waitJobs([ server ])
+ })
+ })
})
after(async function () {
diff --git a/packages/tests/src/api/transcoding/video-studio.ts b/packages/tests/src/api/transcoding/video-studio.ts
index 7d18c29e6a..e83fa3e100 100644
--- a/packages/tests/src/api/transcoding/video-studio.ts
+++ b/packages/tests/src/api/transcoding/video-studio.ts
@@ -267,6 +267,47 @@ describe('Test video studio', function () {
})
})
+ describe('Removing segments', function () {
+ it('Should remove a single segment from the middle of the video', async function () {
+ this.timeout(120_000)
+ await renewVideo('video_short1.webm') // 10 seconds
+
+ await createTasks([
+ {
+ name: 'remove-segments',
+ options: {
+ segments: [ { start: 2, end: 6 } ] // removes 4s → 6s remaining
+ }
+ }
+ ])
+
+ for (const server of servers) {
+ await checkVideoDuration(server, videoUUID, 6)
+ }
+ })
+
+ it('Should remove multiple segments from the video', async function () {
+ this.timeout(120_000)
+ await renewVideo('video_short1.webm') // 10 seconds
+
+ await createTasks([
+ {
+ name: 'remove-segments',
+ options: {
+ segments: [
+ { start: 1, end: 3 }, // removes 2s
+ { start: 6, end: 8 } // removes 2s → 6s remaining
+ ]
+ }
+ }
+ ])
+
+ for (const server of servers) {
+ await checkVideoDuration(server, videoUUID, 6)
+ }
+ })
+ })
+
describe('Watermark', function () {
it('Should add a watermark to the video', async function () {
this.timeout(120_000)
@@ -304,7 +345,7 @@ describe('Test video studio', function () {
await createTasks(VideoStudioCommand.getComplexTask())
for (const server of servers) {
- await checkVideoDuration(server, videoUUID, 9)
+ await checkVideoDuration(server, videoUUID, VideoStudioCommand.getComplexTaskVideoDuration())
}
})
})
@@ -326,7 +367,7 @@ describe('Test video studio', function () {
const video = await server.videos.get({ id: videoUUID })
expect(video.files).to.have.lengthOf(0)
- await checkVideoDuration(server, videoUUID, 9)
+ await checkVideoDuration(server, videoUUID, VideoStudioCommand.getComplexTaskVideoDuration())
await completeCheckHlsPlaylist({ servers, videoUUID, hlsOnly: true, resolutions: [ 720, 240 ] })
}
@@ -350,7 +391,7 @@ describe('Test video studio', function () {
const video = await server.videos.get({ id: videoUUID })
expect(video.files).to.have.lengthOf(0)
- await checkVideoDuration(server, videoUUID, 9)
+ await checkVideoDuration(server, videoUUID, VideoStudioCommand.getComplexTaskVideoDuration())
await completeCheckHlsPlaylist({ servers, videoUUID, hlsOnly: true, splittedAudio: true, resolutions: [ 720, 240 ] })
}
@@ -370,7 +411,7 @@ describe('Test video studio', function () {
await waitJobs(servers)
for (const server of servers) {
- await checkVideoDuration(server, videoUUID, 9)
+ await checkVideoDuration(server, videoUUID, VideoStudioCommand.getComplexTaskVideoDuration())
}
})
@@ -418,7 +459,7 @@ describe('Test video studio', function () {
expectStartWith(hlsFile.fileUrl, objectStorage.getMockPlaylistBaseUrl())
}
- await checkVideoDuration(server, videoUUID, 9)
+ await checkVideoDuration(server, videoUUID, VideoStudioCommand.getComplexTaskVideoDuration())
}
})
diff --git a/packages/tests/src/peertube-runner/studio-transcoding.ts b/packages/tests/src/peertube-runner/studio-transcoding.ts
index 762ec4ca17..c477265b41 100644
--- a/packages/tests/src/peertube-runner/studio-transcoding.ts
+++ b/packages/tests/src/peertube-runner/studio-transcoding.ts
@@ -56,7 +56,7 @@ describe('Test studio transcoding in peertube-runner program', function () {
}
}
- await checkVideoDuration(server, uuid, 9)
+ await checkVideoDuration(server, uuid, VideoStudioCommand.getComplexTaskVideoDuration())
}
})
@@ -74,7 +74,7 @@ describe('Test studio transcoding in peertube-runner program', function () {
const video = await server.videos.get({ id: uuid })
expect(video.files).to.have.lengthOf(0)
- await checkVideoDuration(server, uuid, 9)
+ await checkVideoDuration(server, uuid, VideoStudioCommand.getComplexTaskVideoDuration())
await completeCheckHlsPlaylist({
servers,
@@ -137,7 +137,6 @@ describe('Test studio transcoding in peertube-runner program', function () {
})
describe('Check cleanup', function () {
-
it('Should have an empty cache directory', async function () {
await checkPeerTubeRunnerCacheIsEmpty(peertubeRunner, 'transcoding')
})
diff --git a/server/core/controllers/api/videos/studio.ts b/server/core/controllers/api/videos/studio.ts
index 0389ed9932..192cee3c39 100644
--- a/server/core/controllers/api/videos/studio.ts
+++ b/server/core/controllers/api/videos/studio.ts
@@ -15,6 +15,7 @@ import {
VideoStudioTaskIntro,
VideoStudioTaskOutro,
VideoStudioTaskPayload,
+ VideoStudioTaskRemoveSegments,
VideoStudioTaskWatermark
} from '@peertube/peertube-models'
import { asyncMiddleware, authenticate, videoStudioAddEditionValidator } from '../../../middlewares/index.js'
@@ -105,7 +106,8 @@ const taskPayloadBuilders: {
'add-intro': buildIntroOutroTask,
'add-outro': buildIntroOutroTask,
'cut': buildCutTask,
- 'add-watermark': buildWatermarkTask
+ 'add-watermark': buildWatermarkTask,
+ 'remove-segments': buildRemoveSegmentsTask
}
function buildTaskPayload (task: VideoStudioTask, indice: number, files: Express.Multer.File[]): Promise<VideoStudioTaskPayload> {
@@ -141,12 +143,21 @@ async function buildWatermarkTask (task: VideoStudioTaskWatermark, indice: numbe
options: {
file: destination,
watermarkSizeRatio: VIDEO_FILTERS.WATERMARK.SIZE_RATIO,
- horitonzalMarginRatio: VIDEO_FILTERS.WATERMARK.HORIZONTAL_MARGIN_RATIO,
+ horizontalMarginRatio: VIDEO_FILTERS.WATERMARK.HORIZONTAL_MARGIN_RATIO,
verticalMarginRatio: VIDEO_FILTERS.WATERMARK.VERTICAL_MARGIN_RATIO
}
}
}
+function buildRemoveSegmentsTask (task: VideoStudioTaskRemoveSegments) {
+ return Promise.resolve({
+ name: task.name as 'remove-segments',
+ options: {
+ segments: task.options.segments
+ }
+ })
+}
+
async function moveStudioFileToPersistentTMP (file: string) {
const destination = getStudioTaskFilePath(basename(file))
diff --git a/server/core/helpers/custom-validators/video-studio.ts b/server/core/helpers/custom-validators/video-studio.ts
index 2279552930..92662af9bc 100644
--- a/server/core/helpers/custom-validators/video-studio.ts
+++ b/server/core/helpers/custom-validators/video-studio.ts
@@ -57,3 +57,32 @@ export function isStudioTaskAddWatermarkValid (options: {
return task.name === 'add-watermark' &&
file && isVideoImageValid([ file ], null, true)
}
+
+export function isStudioRemoveSegmentsTaskValid (options: {
+ task: VideoStudioTask
+}) {
+ const { task } = options
+
+ if (task.name !== 'remove-segments') return false
+ if (!task.options?.segments) return false
+
+ const { segments } = task.options
+
+ if (!isArray(segments)) return false
+ if (segments.length < CONSTRAINTS_FIELDS.VIDEO_STUDIO.REMOVE_SEGMENTS.min) return false
+ if (segments.length > CONSTRAINTS_FIELDS.VIDEO_STUDIO.REMOVE_SEGMENTS.max) return false
+
+ let previousEnd = -1
+
+ for (const segment of segments) {
+ if (!validator.default.isInt(segment.start + '', CONSTRAINTS_FIELDS.VIDEO_STUDIO.REMOVE_SEGMENT_TIME_START)) return false
+ if (!validator.default.isInt(segment.end + '', CONSTRAINTS_FIELDS.VIDEO_STUDIO.REMOVE_SEGMENT_TIME_END)) return false
+
+ if (forceNumber(segment.start) >= forceNumber(segment.end)) return false
+ if (forceNumber(segment.start) <= previousEnd) return false
+
+ previousEnd = forceNumber(segment.end)
+ }
+
+ return true
+}
diff --git a/server/core/initializers/constants.ts b/server/core/initializers/constants.ts
index 38bf4d66a8..d187d23a77 100644
--- a/server/core/initializers/constants.ts
+++ b/server/core/initializers/constants.ts
@@ -517,7 +517,10 @@ export const CONSTRAINTS_FIELDS = {
VIDEO_STUDIO: {
TASKS: { min: 1, max: 10 }, // Number of tasks
CUT_TIME_START: { min: 0 }, // Value
- CUT_TIME_END: { min: 1 } // Value
+ CUT_TIME_END: { min: 1 }, // Value
+ REMOVE_SEGMENT_TIME_START: { min: 0 }, // Value
+ REMOVE_SEGMENT_TIME_END: { min: 1 }, // Value
+ REMOVE_SEGMENTS: { min: 1, max: 10 } // Number of segments per remove-segments task
},
LOGS: {
CLIENT_MESSAGE: { min: 1, max: 1000 }, // Length
diff --git a/server/core/lib/job-queue/handlers/video-studio-edition.ts b/server/core/lib/job-queue/handlers/video-studio-edition.ts
index d6be46db92..c7c217e2c2 100644
--- a/server/core/lib/job-queue/handlers/video-studio-edition.ts
+++ b/server/core/lib/job-queue/handlers/video-studio-edition.ts
@@ -8,6 +8,7 @@ import {
VideoStudioTaskIntroPayload,
VideoStudioTaskOutroPayload,
VideoStudioTaskPayload,
+ VideoStudioTaskRemoveSegmentsPayload,
VideoStudioTaskWatermarkPayload
} from '@peertube/peertube-models'
import { buildUUID } from '@peertube/peertube-node-utils'
@@ -135,7 +136,8 @@ const taskProcessors: { [id in VideoStudioTask['name']]: (options: TaskProcessor
'add-intro': processAddIntroOutro,
'add-outro': processAddIntroOutro,
'cut': processCut,
- 'add-watermark': processAddWatermark
+ 'add-watermark': processAddWatermark,
+ 'remove-segments': processRemoveSegments
}
async function processTask (options: TaskProcessorOptions) {
@@ -177,6 +179,18 @@ function processCut (options: TaskProcessorOptions<VideoStudioTaskCutPayload>) {
})
}
+function processRemoveSegments (options: TaskProcessorOptions<VideoStudioTaskRemoveSegmentsPayload>) {
+ const { task, lTags } = options
+
+ logger.debug('Will remove segments from the video.', { options, ...lTags })
+
+ return buildFFmpegEdition().removeSegments({
+ ...pick(options, [ 'inputFileMutexReleaser', 'videoInputPath', 'separatedAudioInputPath', 'outputPath' ]),
+
+ segments: task.options.segments
+ })
+}
+
function processAddWatermark (options: TaskProcessorOptions<VideoStudioTaskWatermarkPayload>) {
const { task, lTags } = options
@@ -189,7 +203,7 @@ function processAddWatermark (options: TaskProcessorOptions<VideoStudioTaskWater
videoFilters: {
watermarkSizeRatio: task.options.watermarkSizeRatio,
- horitonzalMarginRatio: task.options.horitonzalMarginRatio,
+ horizontalMarginRatio: task.options.horizontalMarginRatio,
verticalMarginRatio: task.options.verticalMarginRatio
}
})
diff --git a/server/core/middlewares/validators/videos/video-studio.ts b/server/core/middlewares/validators/videos/video-studio.ts
index 92ed9c62b0..9a60a1d86e 100644
--- a/server/core/middlewares/validators/videos/video-studio.ts
+++ b/server/core/middlewares/validators/videos/video-studio.ts
@@ -5,6 +5,7 @@ import {
isStudioCutTaskValid,
isStudioTaskAddIntroOutroValid,
isStudioTaskAddWatermarkValid,
+ isStudioRemoveSegmentsTaskValid,
isValidStudioTasksArray
} from '@server/helpers/custom-validators/video-studio.js'
import { cleanUpReqFiles } from '@server/helpers/express-utils.js'
@@ -109,7 +110,8 @@ const taskCheckers: {
'cut': isStudioCutTaskValid,
'add-intro': isStudioTaskAddIntroOutroValid,
'add-outro': isStudioTaskAddIntroOutroValid,
- 'add-watermark': isStudioTaskAddWatermarkValid
+ 'add-watermark': isStudioTaskAddWatermarkValid,
+ 'remove-segments': isStudioRemoveSegmentsTaskValid
}
function checkTask (req: express.Request, task: VideoStudioTask, indice?: number) {
diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml
index 009aa27a63..0c885e316a 100644
--- a/support/doc/api/openapi.yaml
+++ b/support/doc/api/openapi.yaml
@@ -12740,6 +12740,34 @@ components:
file:
type: string
format: binary
+ -
+ title: remove-segments
+ type: object
+ properties:
+ name:
+ type: string
+ enum:
+ - 'remove-segments'
+ options:
+ type: object
+ required:
+ - segments
+ properties:
+ segments:
+ type: array
+ minItems: 1
+ items:
+ type: object
+ required:
+ - start
+ - end
+ properties:
+ start:
+ type: integer
+ minimum: 0
+ end:
+ type: integer
+ minimum: 1
LiveVideoSessionResponse:
properties: