gradio-pr-bot commited on
Commit
6c580b6
·
verified ·
1 Parent(s): 573a210

Upload folder using huggingface_hub

Browse files
6.4.0/video/Example.svelte ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import Video from "./shared/Video.svelte";
3
+ import { playable } from "./shared/utils";
4
+ import { type FileData } from "@gradio/client";
5
+
6
+ export let type: "gallery" | "table";
7
+ export let selected = false;
8
+ export let value: null | FileData = null;
9
+ export let loop: boolean;
10
+ let video: HTMLVideoElement;
11
+
12
+ async function init(): Promise<void> {
13
+ video.muted = true;
14
+ video.playsInline = true;
15
+ video.controls = false;
16
+ video.setAttribute("muted", "");
17
+
18
+ await video.play();
19
+ video.pause();
20
+ }
21
+ </script>
22
+
23
+ {#if value}
24
+ {#if playable()}
25
+ <div
26
+ class="container"
27
+ class:table={type === "table"}
28
+ class:gallery={type === "gallery"}
29
+ class:selected
30
+ >
31
+ <Video
32
+ muted
33
+ playsinline
34
+ bind:node={video}
35
+ on:loadeddata={init}
36
+ on:mouseover={video.play.bind(video)}
37
+ on:mouseout={video.pause.bind(video)}
38
+ src={value?.url}
39
+ is_stream={false}
40
+ {loop}
41
+ />
42
+ </div>
43
+ {:else}
44
+ <div>{value}</div>
45
+ {/if}
46
+ {/if}
47
+
48
+ <style>
49
+ .container {
50
+ flex: none;
51
+ max-width: none;
52
+ }
53
+ .container :global(video) {
54
+ width: var(--size-full);
55
+ height: var(--size-full);
56
+ object-fit: cover;
57
+ }
58
+
59
+ .container:hover,
60
+ .container.selected {
61
+ border-color: var(--border-color-accent);
62
+ }
63
+ .container.table {
64
+ margin: 0 auto;
65
+ border: 2px solid var(--border-color-primary);
66
+ border-radius: var(--radius-lg);
67
+ overflow: hidden;
68
+ width: var(--size-20);
69
+ height: var(--size-20);
70
+ object-fit: cover;
71
+ }
72
+
73
+ .container.gallery {
74
+ height: var(--size-20);
75
+ max-height: var(--size-20);
76
+ object-fit: cover;
77
+ }
78
+ </style>
6.4.0/video/Index.svelte ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <svelte:options accessors={true} />
2
+
3
+ <script lang="ts">
4
+ import { tick } from "svelte";
5
+ import type { FileData } from "@gradio/client";
6
+ import { Block, UploadText } from "@gradio/atoms";
7
+ import StaticVideo from "./shared/VideoPreview.svelte";
8
+ import Video from "./shared/InteractiveVideo.svelte";
9
+ import { StatusTracker } from "@gradio/statustracker";
10
+ import { Gradio } from "@gradio/utils";
11
+ import type { VideoProps, VideoEvents } from "./types";
12
+
13
+ const props = $props();
14
+
15
+ let upload_promise = $state<Promise<any>>();
16
+
17
+ class VideoGradio extends Gradio<VideoEvents, VideoProps> {
18
+ async get_data() {
19
+ if (upload_promise) {
20
+ await upload_promise;
21
+ await tick();
22
+ }
23
+ const data = await super.get_data();
24
+
25
+ return data;
26
+ }
27
+ }
28
+
29
+ const gradio = new VideoGradio(props);
30
+ let old_value = $state(gradio.props.value);
31
+
32
+ let uploading = $state(false);
33
+ let dragging = $state(false);
34
+ let active_source = $derived.by(() =>
35
+ gradio.props.sources ? gradio.props.sources[0] : undefined
36
+ );
37
+ let initial_value: FileData | null = gradio.props.value;
38
+
39
+ $effect(() => {
40
+ if (old_value != gradio.props.value) {
41
+ old_value = gradio.props.value;
42
+ gradio.dispatch("change");
43
+ }
44
+ });
45
+
46
+ const handle_reset_value = (): void => {
47
+ if (initial_value === null || gradio.props.value === initial_value) {
48
+ return;
49
+ }
50
+ gradio.props.value = initial_value;
51
+ };
52
+
53
+ function handle_change({ detail }: CustomEvent<FileData | null>): void {
54
+ if (detail != null) {
55
+ gradio.props.value = detail as FileData;
56
+ } else {
57
+ gradio.props.value = null;
58
+ }
59
+ }
60
+
61
+ function handle_error({ detail }: CustomEvent<string>): void {
62
+ const [level, status] = detail.includes("Invalid file type")
63
+ ? ["warning", "complete"]
64
+ : ["error", "error"];
65
+ gradio.shared.loading_status.status = status as any;
66
+ gradio.shared.loading_status.message = detail;
67
+ gradio.dispatch(level as "error" | "warning", detail);
68
+ }
69
+ </script>
70
+
71
+ {#if !gradio.shared.interactive}
72
+ <Block
73
+ visible={gradio.shared.visible}
74
+ variant={gradio.props.value === null && active_source === "upload"
75
+ ? "dashed"
76
+ : "solid"}
77
+ border_mode={dragging ? "focus" : "base"}
78
+ padding={false}
79
+ elem_id={gradio.shared.elem_id}
80
+ elem_classes={gradio.shared.elem_classes}
81
+ height={gradio.props.height || undefined}
82
+ width={gradio.props.width}
83
+ container={gradio.shared.container}
84
+ scale={gradio.shared.scale}
85
+ min_width={gradio.shared.min_width}
86
+ allow_overflow={false}
87
+ >
88
+ <StatusTracker
89
+ autoscroll={gradio.shared.autoscroll}
90
+ i18n={gradio.i18n}
91
+ {...gradio.shared.loading_status}
92
+ on_clear_status={() =>
93
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
94
+ />
95
+
96
+ <StaticVideo
97
+ value={gradio.props.value}
98
+ subtitle={gradio.props.subtitles}
99
+ label={gradio.shared.label}
100
+ show_label={gradio.shared.show_label}
101
+ autoplay={gradio.props.autoplay}
102
+ loop={gradio.props.loop}
103
+ buttons={gradio.props.buttons ?? ["download", "share"]}
104
+ on_custom_button_click={(id) => {
105
+ gradio.dispatch("custom_button_click", { id });
106
+ }}
107
+ bind:playback_position={gradio.props.playback_position}
108
+ on:play={() => gradio.dispatch("play")}
109
+ on:pause={() => gradio.dispatch("pause")}
110
+ on:stop={() => gradio.dispatch("stop")}
111
+ on:end={() => gradio.dispatch("end")}
112
+ on:share={({ detail }) => gradio.dispatch("share", detail)}
113
+ on:error={({ detail }) => gradio.dispatch("error", detail)}
114
+ i18n={gradio.i18n}
115
+ upload={(...args) => gradio.shared.client.upload(...args)}
116
+ />
117
+ </Block>
118
+ {:else}
119
+ <Block
120
+ visible={gradio.shared.visible}
121
+ variant={gradio.props.value === null && active_source === "upload"
122
+ ? "dashed"
123
+ : "solid"}
124
+ border_mode={dragging ? "focus" : "base"}
125
+ padding={false}
126
+ elem_id={gradio.shared.elem_id}
127
+ elem_classes={gradio.shared.elem_classes}
128
+ height={gradio.props.height || undefined}
129
+ width={gradio.props.width}
130
+ container={gradio.shared.container}
131
+ scale={gradio.shared.scale}
132
+ min_width={gradio.shared.min_width}
133
+ allow_overflow={false}
134
+ >
135
+ <StatusTracker
136
+ autoscroll={gradio.shared.autoscroll}
137
+ i18n={gradio.i18n}
138
+ {...gradio.shared.loading_status}
139
+ on_clear_status={() =>
140
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
141
+ />
142
+
143
+ <Video
144
+ bind:upload_promise
145
+ value={gradio.props.value}
146
+ subtitle={gradio.props.subtitles}
147
+ on:change={handle_change}
148
+ on:drag={({ detail }) => (dragging = detail)}
149
+ on:error={handle_error}
150
+ bind:uploading
151
+ label={gradio.shared.label}
152
+ show_label={gradio.shared.show_label}
153
+ buttons={gradio.props.buttons ?? ["download", "share"]}
154
+ on_custom_button_click={(id) => {
155
+ gradio.dispatch("custom_button_click", { id });
156
+ }}
157
+ sources={gradio.props.sources}
158
+ {active_source}
159
+ webcam_options={gradio.props.webcam_options}
160
+ include_audio={gradio.props.include_audio}
161
+ autoplay={gradio.props.autoplay}
162
+ root={gradio.shared.root}
163
+ loop={gradio.props.loop}
164
+ {handle_reset_value}
165
+ bind:playback_position={gradio.props.playback_position}
166
+ on:clear={() => {
167
+ gradio.props.value = null;
168
+ gradio.dispatch("clear");
169
+ gradio.dispatch("input");
170
+ }}
171
+ on:play={() => gradio.dispatch("play")}
172
+ on:pause={() => gradio.dispatch("pause")}
173
+ on:upload={() => {
174
+ gradio.dispatch("upload");
175
+ gradio.dispatch("input");
176
+ }}
177
+ on:stop={() => gradio.dispatch("stop")}
178
+ on:end={() => gradio.dispatch("end")}
179
+ on:start_recording={() => gradio.dispatch("start_recording")}
180
+ on:stop_recording={() => gradio.dispatch("stop_recording")}
181
+ i18n={gradio.i18n}
182
+ max_file_size={gradio.shared.max_file_size}
183
+ upload={(...args) => gradio.shared.client.upload(...args)}
184
+ stream_handler={(...args) => gradio.shared.client.stream(...args)}
185
+ >
186
+ <UploadText i18n={gradio.i18n} type="video" />
187
+ </Video>
188
+ </Block>
189
+ {/if}
6.4.0/video/index.ts ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ export { default as BaseInteractiveVideo } from "./shared/InteractiveVideo.svelte";
2
+ export { default as BaseStaticVideo } from "./shared/VideoPreview.svelte";
3
+ export { default as BasePlayer } from "./shared/Player.svelte";
4
+ export { prettyBytes, playable, loaded } from "./shared/utils";
5
+ export { default as BaseExample } from "./Example.svelte";
6
+ import { default as Index } from "./Index.svelte";
7
+ export default Index;
6.4.0/video/package.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/video",
3
+ "version": "0.20.1",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "dependencies": {
10
+ "@ffmpeg/ffmpeg": "^0.12.15",
11
+ "@ffmpeg/util": "^0.12.2",
12
+ "@gradio/atoms": "workspace:^",
13
+ "@gradio/client": "workspace:^",
14
+ "@gradio/icons": "workspace:^",
15
+ "@gradio/image": "workspace:^",
16
+ "@gradio/statustracker": "workspace:^",
17
+ "@gradio/upload": "workspace:^",
18
+ "@gradio/utils": "workspace:^",
19
+ "hls.js": "^1.6.13",
20
+ "mrmime": "^2.0.1"
21
+ },
22
+ "devDependencies": {
23
+ "@gradio/preview": "workspace:^"
24
+ },
25
+ "exports": {
26
+ "./package.json": "./package.json",
27
+ ".": {
28
+ "gradio": "./index.ts",
29
+ "svelte": "./dist/index.js",
30
+ "types": "./dist/index.d.ts"
31
+ },
32
+ "./example": {
33
+ "gradio": "./Example.svelte",
34
+ "svelte": "./dist/Example.svelte",
35
+ "types": "./dist/Example.svelte.d.ts"
36
+ },
37
+ "./shared": {
38
+ "gradio": "./shared/index.ts",
39
+ "svelte": "./dist/shared/index.js",
40
+ "types": "./dist/shared/index.d.ts"
41
+ },
42
+ "./base": {
43
+ "gradio": "./shared/VideoPreview.svelte",
44
+ "svelte": "./dist/shared/VideoPreview.svelte",
45
+ "types": "./dist/shared/VideoPreview.svelte.d.ts"
46
+ }
47
+ },
48
+ "peerDependencies": {
49
+ "svelte": "^5.43.4"
50
+ },
51
+ "main": "index.ts",
52
+ "main_changeset": true,
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "git+https://github.com/gradio-app/gradio.git",
56
+ "directory": "js/video"
57
+ }
58
+ }
6.4.0/video/shared/InteractiveVideo.svelte ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { createEventDispatcher } from "svelte";
3
+ import { Upload, ModifyUpload } from "@gradio/upload";
4
+ import type { FileData, Client } from "@gradio/client";
5
+ import { BlockLabel } from "@gradio/atoms";
6
+ import { Webcam } from "@gradio/image";
7
+ import { Video } from "@gradio/icons";
8
+ import type { WebcamOptions } from "./utils";
9
+ import { prettyBytes, playable } from "./utils";
10
+ import Player from "./Player.svelte";
11
+ import type { I18nFormatter } from "@gradio/utils";
12
+ import { SelectSource } from "@gradio/atoms";
13
+
14
+ export let value: FileData | null = null;
15
+ export let subtitle: FileData | null = null;
16
+ export let sources:
17
+ | ["webcam"]
18
+ | ["upload"]
19
+ | ["webcam", "upload"]
20
+ | ["upload", "webcam"] = ["webcam", "upload"];
21
+ export let label: string | undefined = undefined;
22
+ export let show_download_button = false;
23
+ export let show_label = true;
24
+ export let webcam_options: WebcamOptions;
25
+ export let include_audio: boolean;
26
+ export let autoplay: boolean;
27
+ export let root: string;
28
+ export let i18n: I18nFormatter;
29
+ export let active_source: "webcam" | "upload" = "webcam";
30
+ export let handle_reset_value: () => void = () => {};
31
+ export let max_file_size: number | null = null;
32
+ export let upload: Client["upload"];
33
+ export let stream_handler: Client["stream"];
34
+ export let loop: boolean;
35
+ export let uploading = false;
36
+ export let upload_promise: Promise<any> | null = null;
37
+ export let playback_position = 0;
38
+
39
+ let has_change_history = false;
40
+
41
+ const dispatch = createEventDispatcher<{
42
+ change: FileData | null;
43
+ clear?: never;
44
+ play?: never;
45
+ pause?: never;
46
+ end?: never;
47
+ drag: boolean;
48
+ error: string;
49
+ upload: FileData;
50
+ start_recording?: never;
51
+ stop_recording?: never;
52
+ }>();
53
+
54
+ function handle_load({ detail }: CustomEvent<FileData | null>): void {
55
+ value = detail;
56
+ dispatch("change", detail);
57
+ dispatch("upload", detail!);
58
+ }
59
+
60
+ function handle_clear(): void {
61
+ value = null;
62
+ dispatch("change", null);
63
+ dispatch("clear");
64
+ }
65
+
66
+ function handle_change(video: FileData): void {
67
+ has_change_history = true;
68
+ dispatch("change", video);
69
+ }
70
+
71
+ function handle_capture({
72
+ detail
73
+ }: CustomEvent<FileData | any | null>): void {
74
+ dispatch("change", detail);
75
+ }
76
+
77
+ let dragging = false;
78
+ $: dispatch("drag", dragging);
79
+ </script>
80
+
81
+ <BlockLabel {show_label} Icon={Video} label={label || "Video"} />
82
+ <div data-testid="video" class="video-container">
83
+ {#if value === null || value?.url === undefined}
84
+ <div class="upload-container">
85
+ {#if active_source === "upload"}
86
+ <Upload
87
+ bind:upload_promise
88
+ bind:dragging
89
+ bind:uploading
90
+ filetype="video/x-m4v,video/*"
91
+ on:load={handle_load}
92
+ {max_file_size}
93
+ on:error={({ detail }) => dispatch("error", detail)}
94
+ {root}
95
+ {upload}
96
+ {stream_handler}
97
+ aria_label={i18n("video.drop_to_upload")}
98
+ >
99
+ <slot />
100
+ </Upload>
101
+ {:else if active_source === "webcam"}
102
+ <Webcam
103
+ {root}
104
+ mirror_webcam={webcam_options.mirror}
105
+ webcam_constraints={webcam_options.constraints}
106
+ {include_audio}
107
+ mode="video"
108
+ on:error
109
+ on:capture={handle_capture}
110
+ on:start_recording
111
+ on:stop_recording
112
+ {i18n}
113
+ {upload}
114
+ stream_every={1}
115
+ />
116
+ {/if}
117
+ </div>
118
+ {:else if value?.url}
119
+ {#key value?.url}
120
+ <Player
121
+ {upload}
122
+ {root}
123
+ interactive
124
+ {autoplay}
125
+ src={value.url}
126
+ subtitle={subtitle?.url}
127
+ is_stream={false}
128
+ on:play
129
+ on:pause
130
+ on:stop
131
+ on:end
132
+ on:error
133
+ mirror={webcam_options.mirror && active_source === "webcam"}
134
+ {label}
135
+ {handle_change}
136
+ {handle_reset_value}
137
+ {loop}
138
+ {value}
139
+ {i18n}
140
+ {show_download_button}
141
+ {handle_clear}
142
+ {has_change_history}
143
+ bind:playback_position
144
+ />
145
+ {/key}
146
+ {:else if value.size}
147
+ <div class="file-name">{value.orig_name || value.url}</div>
148
+ <div class="file-size">
149
+ {prettyBytes(value.size)}
150
+ </div>
151
+ {/if}
152
+
153
+ <SelectSource {sources} bind:active_source {handle_clear} />
154
+ </div>
155
+
156
+ <style>
157
+ .file-name {
158
+ padding: var(--size-6);
159
+ font-size: var(--text-xxl);
160
+ word-break: break-all;
161
+ }
162
+
163
+ .file-size {
164
+ padding: var(--size-2);
165
+ font-size: var(--text-xl);
166
+ }
167
+
168
+ .upload-container {
169
+ height: 100%;
170
+ width: 100%;
171
+ }
172
+
173
+ .video-container {
174
+ display: flex;
175
+ height: 100%;
176
+ flex-direction: column;
177
+ justify-content: center;
178
+ align-items: center;
179
+ }
180
+ </style>
6.4.0/video/shared/Player.svelte ADDED
@@ -0,0 +1,381 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { createEventDispatcher, onMount, onDestroy } from "svelte";
3
+ import { Play, Pause, Maximize, Undo } from "@gradio/icons";
4
+ import Video from "./Video.svelte";
5
+ import VideoControls from "./VideoControls.svelte";
6
+ import VolumeControl from "./VolumeControl.svelte";
7
+ import VolumeLevels from "../../audio/shared/VolumeLevels.svelte";
8
+ import type { FileData, Client } from "@gradio/client";
9
+ import { prepare_files } from "@gradio/client";
10
+ import { format_time } from "@gradio/utils";
11
+ import type { I18nFormatter } from "@gradio/utils";
12
+
13
+ export let root = "";
14
+ export let src: string;
15
+ export let subtitle: string | null = null;
16
+ export let mirror: boolean;
17
+ export let autoplay: boolean;
18
+ export let loop: boolean;
19
+ export let label = "test";
20
+ export let interactive = false;
21
+ export let handle_change: (video: FileData) => void = () => {};
22
+ export let handle_reset_value: () => void = () => {};
23
+ export let upload: Client["upload"];
24
+ export let is_stream: boolean | undefined;
25
+ export let i18n: I18nFormatter;
26
+ export let show_download_button = false;
27
+ export let value: FileData | null = null;
28
+ export let handle_clear: () => void = () => {};
29
+ export let has_change_history = false;
30
+ export let playback_position = 0;
31
+
32
+ const dispatch = createEventDispatcher<{
33
+ play: undefined;
34
+ pause: undefined;
35
+ stop: undefined;
36
+ end: undefined;
37
+ clear: undefined;
38
+ }>();
39
+
40
+ let time = 0;
41
+ let duration: number;
42
+ let paused = true;
43
+ let video: HTMLVideoElement;
44
+ let processingVideo = false;
45
+ let show_volume_slider = false;
46
+ let current_volume = 1;
47
+ let is_fullscreen = false;
48
+
49
+ function handleMove(e: TouchEvent | MouseEvent): void {
50
+ if (!duration) return;
51
+
52
+ if (e.type === "click") {
53
+ handle_click(e as MouseEvent);
54
+ return;
55
+ }
56
+
57
+ if (e.type !== "touchmove" && !((e as MouseEvent).buttons & 1)) return;
58
+
59
+ const clientX =
60
+ e.type === "touchmove"
61
+ ? (e as TouchEvent).touches[0].clientX
62
+ : (e as MouseEvent).clientX;
63
+ const { left, right } = (
64
+ e.currentTarget as HTMLProgressElement
65
+ ).getBoundingClientRect();
66
+ time = (duration * (clientX - left)) / (right - left);
67
+ }
68
+
69
+ async function play_pause(): Promise<void> {
70
+ if (document.fullscreenElement != video) {
71
+ const isPlaying =
72
+ video.currentTime > 0 &&
73
+ !video.paused &&
74
+ !video.ended &&
75
+ video.readyState > video.HAVE_CURRENT_DATA;
76
+
77
+ if (!isPlaying) {
78
+ await video.play();
79
+ } else video.pause();
80
+ }
81
+ }
82
+
83
+ function handle_click(e: MouseEvent): void {
84
+ const { left, right } = (
85
+ e.currentTarget as HTMLProgressElement
86
+ ).getBoundingClientRect();
87
+ time = (duration * (e.clientX - left)) / (right - left);
88
+ }
89
+
90
+ function handle_end(): void {
91
+ dispatch("stop");
92
+ dispatch("end");
93
+ }
94
+
95
+ const handle_trim_video = async (videoBlob: Blob): Promise<void> => {
96
+ let _video_blob = new File([videoBlob], "video.mp4");
97
+ const val = await prepare_files([_video_blob]);
98
+ let value = ((await upload(val, root))?.filter(Boolean) as FileData[])[0];
99
+
100
+ handle_change(value);
101
+ };
102
+
103
+ function open_full_screen(): void {
104
+ if (!is_fullscreen) {
105
+ video.requestFullscreen();
106
+ } else {
107
+ document.exitFullscreen();
108
+ }
109
+ }
110
+
111
+ function handleFullscreenChange(): void {
112
+ is_fullscreen = document.fullscreenElement === video;
113
+ if (video) {
114
+ video.controls = is_fullscreen;
115
+ }
116
+ }
117
+
118
+ let last_synced_volume = 1;
119
+ let previous_video: HTMLVideoElement | undefined;
120
+ // Tolerance for floating-point comparison of volume values
121
+ const VOLUME_EPSILON = 0.001;
122
+
123
+ function handleVolumeChange(): void {
124
+ if (video && Math.abs(video.volume - last_synced_volume) > VOLUME_EPSILON) {
125
+ current_volume = video.volume;
126
+ last_synced_volume = video.volume;
127
+ }
128
+ }
129
+
130
+ onMount(() => {
131
+ document.addEventListener("fullscreenchange", handleFullscreenChange);
132
+ return () => {
133
+ document.removeEventListener("fullscreenchange", handleFullscreenChange);
134
+ };
135
+ });
136
+
137
+ onDestroy(() => {
138
+ if (video) {
139
+ video.removeEventListener("volumechange", handleVolumeChange);
140
+ }
141
+ });
142
+
143
+ $: if (video && video !== previous_video) {
144
+ if (previous_video) {
145
+ previous_video.removeEventListener("volumechange", handleVolumeChange);
146
+ }
147
+ video.addEventListener("volumechange", handleVolumeChange);
148
+ previous_video = video;
149
+ }
150
+
151
+ $: time = time || 0;
152
+ $: duration = duration || 0;
153
+ $: playback_position = time;
154
+ $: if (playback_position !== time && video) {
155
+ video.currentTime = playback_position;
156
+ }
157
+ $: if (video && !is_fullscreen) {
158
+ if (Math.abs(video.volume - current_volume) > VOLUME_EPSILON) {
159
+ video.volume = current_volume;
160
+ last_synced_volume = current_volume;
161
+ }
162
+ video.controls = false;
163
+ }
164
+ $: if (video && is_fullscreen) {
165
+ last_synced_volume = video.volume;
166
+ }
167
+ </script>
168
+
169
+ <div class="wrap">
170
+ <div class="mirror-wrap" class:mirror>
171
+ <Video
172
+ {src}
173
+ preload="auto"
174
+ {autoplay}
175
+ {loop}
176
+ {is_stream}
177
+ controls={is_fullscreen}
178
+ on:click={play_pause}
179
+ on:play
180
+ on:pause
181
+ on:error
182
+ on:ended={handle_end}
183
+ bind:currentTime={time}
184
+ bind:duration
185
+ bind:paused
186
+ bind:node={video}
187
+ data-testid={`${label}-player`}
188
+ {processingVideo}
189
+ on:loadstart
190
+ on:loadeddata
191
+ on:loadedmetadata
192
+ >
193
+ <track kind="captions" src={subtitle} default />
194
+ </Video>
195
+ </div>
196
+
197
+ <div class="controls">
198
+ <div class="inner">
199
+ <span
200
+ role="button"
201
+ tabindex="0"
202
+ class="icon"
203
+ aria-label="play-pause-replay-button"
204
+ on:click={play_pause}
205
+ on:keydown={play_pause}
206
+ >
207
+ {#if time === duration}
208
+ <Undo />
209
+ {:else if paused}
210
+ <Play />
211
+ {:else}
212
+ <Pause />
213
+ {/if}
214
+ </span>
215
+
216
+ <span class="time">{format_time(time)} / {format_time(duration)}</span>
217
+
218
+ <!-- TODO: implement accessible video timeline for 4.0 -->
219
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
220
+ <!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
221
+ <progress
222
+ value={time / duration || 0}
223
+ on:mousemove={handleMove}
224
+ on:touchmove|preventDefault={handleMove}
225
+ on:click|stopPropagation|preventDefault={handle_click}
226
+ />
227
+
228
+ <div class="volume-control-wrapper">
229
+ <button
230
+ class="icon volume-button"
231
+ style:color={show_volume_slider ? "var(--color-accent)" : "white"}
232
+ aria-label="Adjust volume"
233
+ on:click={() => (show_volume_slider = !show_volume_slider)}
234
+ >
235
+ <VolumeLevels currentVolume={current_volume} />
236
+ </button>
237
+
238
+ {#if show_volume_slider}
239
+ <VolumeControl bind:current_volume bind:show_volume_slider />
240
+ {/if}
241
+ </div>
242
+
243
+ {#if !show_volume_slider}
244
+ <div
245
+ role="button"
246
+ tabindex="0"
247
+ class="icon"
248
+ aria-label="full-screen"
249
+ on:click={open_full_screen}
250
+ on:keypress={open_full_screen}
251
+ >
252
+ <Maximize />
253
+ </div>
254
+ {/if}
255
+ </div>
256
+ </div>
257
+ </div>
258
+ {#if interactive}
259
+ <VideoControls
260
+ videoElement={video}
261
+ showRedo
262
+ {handle_trim_video}
263
+ {handle_reset_value}
264
+ bind:processingVideo
265
+ {value}
266
+ {i18n}
267
+ {show_download_button}
268
+ {handle_clear}
269
+ {has_change_history}
270
+ />
271
+ {/if}
272
+
273
+ <style lang="postcss">
274
+ span {
275
+ text-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
276
+ }
277
+
278
+ progress {
279
+ margin-right: var(--size-3);
280
+ border-radius: var(--radius-sm);
281
+ width: var(--size-full);
282
+ height: var(--size-2);
283
+ }
284
+
285
+ progress::-webkit-progress-bar {
286
+ border-radius: 2px;
287
+ background-color: rgba(255, 255, 255, 0.2);
288
+ overflow: hidden;
289
+ }
290
+
291
+ progress::-webkit-progress-value {
292
+ background-color: rgba(255, 255, 255, 0.9);
293
+ }
294
+
295
+ .mirror {
296
+ transform: scaleX(-1);
297
+ }
298
+
299
+ .mirror-wrap {
300
+ position: relative;
301
+ height: 100%;
302
+ width: 100%;
303
+ }
304
+
305
+ .controls {
306
+ position: absolute;
307
+ bottom: 0;
308
+ opacity: 0;
309
+ transition: 500ms;
310
+ margin: var(--size-2);
311
+ border-radius: var(--radius-md);
312
+ background: var(--color-grey-800);
313
+ padding: var(--size-2) var(--size-1);
314
+ width: calc(100% - 0.375rem * 2);
315
+ width: calc(100% - var(--size-2) * 2);
316
+ z-index: 10;
317
+ }
318
+ .wrap:hover .controls {
319
+ opacity: 1;
320
+ }
321
+ :global(:fullscreen) .controls {
322
+ display: none;
323
+ }
324
+
325
+ .inner {
326
+ display: flex;
327
+ justify-content: space-between;
328
+ align-items: center;
329
+ padding-right: var(--size-2);
330
+ padding-left: var(--size-2);
331
+ width: var(--size-full);
332
+ height: var(--size-full);
333
+ }
334
+
335
+ .icon {
336
+ display: flex;
337
+ justify-content: center;
338
+ cursor: pointer;
339
+ width: var(--size-6);
340
+ color: white;
341
+ }
342
+
343
+ .volume-control-wrapper {
344
+ position: relative;
345
+ display: flex;
346
+ align-items: center;
347
+ margin-right: var(--spacing-md);
348
+ }
349
+
350
+ .volume-button {
351
+ display: flex;
352
+ justify-content: center;
353
+ align-items: center;
354
+ cursor: pointer;
355
+ width: var(--size-6);
356
+ color: white;
357
+ border: none;
358
+ background: none;
359
+ padding: 0;
360
+ }
361
+
362
+ .time {
363
+ flex-shrink: 0;
364
+ margin-right: var(--size-3);
365
+ margin-left: var(--size-3);
366
+ color: white;
367
+ font-size: var(--text-sm);
368
+ font-family: var(--font-mono);
369
+ }
370
+ .wrap {
371
+ position: relative;
372
+ background-color: var(--background-fill-secondary);
373
+ height: var(--size-full);
374
+ width: var(--size-full);
375
+ border-radius: var(--radius-xl);
376
+ }
377
+ .wrap :global(video) {
378
+ height: var(--size-full);
379
+ width: var(--size-full);
380
+ }
381
+ </style>
6.4.0/video/shared/Video.svelte ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { HTMLVideoAttributes } from "svelte/elements";
3
+ import { createEventDispatcher } from "svelte";
4
+ import { loaded } from "./utils";
5
+
6
+ import Hls from "hls.js";
7
+
8
+ export let src: HTMLVideoAttributes["src"] = undefined;
9
+
10
+ export let muted: HTMLVideoAttributes["muted"] = undefined;
11
+ export let playsinline: HTMLVideoAttributes["playsinline"] = undefined;
12
+ export let preload: HTMLVideoAttributes["preload"] = undefined;
13
+ export let autoplay: HTMLVideoAttributes["autoplay"] = undefined;
14
+ export let controls: HTMLVideoAttributes["controls"] = undefined;
15
+
16
+ export let currentTime: number | undefined = undefined;
17
+ export let duration: number | undefined = undefined;
18
+ export let paused: boolean | undefined = undefined;
19
+
20
+ export let node: HTMLVideoElement | undefined = undefined;
21
+ export let loop: boolean;
22
+ export let is_stream;
23
+
24
+ export let processingVideo = false;
25
+
26
+ let stream_active = false;
27
+
28
+ const dispatch = createEventDispatcher();
29
+
30
+ function load_stream(
31
+ src: string | null | undefined,
32
+ is_stream: boolean,
33
+ node: HTMLVideoElement
34
+ ): void {
35
+ if (!src || !is_stream) return;
36
+
37
+ if (Hls.isSupported() && !stream_active) {
38
+ const hls = new Hls({
39
+ maxBufferLength: 1, // 0.5 seconds (500 ms)
40
+ maxMaxBufferLength: 1, // Maximum max buffer length in seconds
41
+ lowLatencyMode: true // Enable low latency mode
42
+ });
43
+ hls.loadSource(src);
44
+ hls.attachMedia(node);
45
+ hls.on(Hls.Events.MANIFEST_PARSED, function () {
46
+ (node as HTMLVideoElement).play();
47
+ });
48
+ hls.on(Hls.Events.ERROR, function (event, data) {
49
+ console.error("HLS error:", event, data);
50
+ if (data.fatal) {
51
+ switch (data.type) {
52
+ case Hls.ErrorTypes.NETWORK_ERROR:
53
+ console.error(
54
+ "Fatal network error encountered, trying to recover"
55
+ );
56
+ hls.startLoad();
57
+ break;
58
+ case Hls.ErrorTypes.MEDIA_ERROR:
59
+ console.error("Fatal media error encountered, trying to recover");
60
+ hls.recoverMediaError();
61
+ break;
62
+ default:
63
+ console.error("Fatal error, cannot recover");
64
+ hls.destroy();
65
+ break;
66
+ }
67
+ }
68
+ });
69
+ stream_active = true;
70
+ }
71
+ }
72
+
73
+ $: (src, (stream_active = false));
74
+
75
+ $: if (node && src && is_stream) {
76
+ load_stream(src, is_stream, node);
77
+ }
78
+ </script>
79
+
80
+ <!--
81
+ The spread operator with `$$props` or `$$restProps` can't be used here
82
+ to pass props from the parent component to the <video> element
83
+ because of its unexpected behavior: https://github.com/sveltejs/svelte/issues/7404
84
+ For example, if we add {...$$props} or {...$$restProps}, the boolean props aside it like `controls` will be compiled as string "true" or "false" on the actual DOM.
85
+ Then, even when `controls` is false, the compiled DOM would be `<video controls="false">` which is equivalent to `<video controls>` since the string "false" is even truthy.
86
+ -->
87
+ <div class:hidden={!processingVideo} class="overlay">
88
+ <span class="load-wrap">
89
+ <span class="loader" />
90
+ </span>
91
+ </div>
92
+ <video
93
+ {src}
94
+ {muted}
95
+ {playsinline}
96
+ {preload}
97
+ {autoplay}
98
+ {controls}
99
+ {loop}
100
+ on:loadeddata={dispatch.bind(null, "loadeddata")}
101
+ on:click={dispatch.bind(null, "click")}
102
+ on:play={dispatch.bind(null, "play")}
103
+ on:pause={dispatch.bind(null, "pause")}
104
+ on:ended={dispatch.bind(null, "ended")}
105
+ on:mouseover={dispatch.bind(null, "mouseover")}
106
+ on:mouseout={dispatch.bind(null, "mouseout")}
107
+ on:focus={dispatch.bind(null, "focus")}
108
+ on:blur={dispatch.bind(null, "blur")}
109
+ on:error={dispatch.bind(null, "error", "Video not playable")}
110
+ on:loadstart
111
+ on:loadeddata
112
+ on:loadedmetadata
113
+ bind:currentTime
114
+ bind:duration
115
+ bind:paused
116
+ bind:this={node}
117
+ use:loaded={{ autoplay: autoplay ?? false }}
118
+ data-testid={$$props["data-testid"]}
119
+ crossorigin="anonymous"
120
+ >
121
+ <slot />
122
+ </video>
123
+
124
+ <style>
125
+ .overlay {
126
+ position: absolute;
127
+ background-color: rgba(0, 0, 0, 0.4);
128
+ width: 100%;
129
+ height: 100%;
130
+ }
131
+
132
+ .hidden {
133
+ display: none;
134
+ }
135
+
136
+ .load-wrap {
137
+ display: flex;
138
+ justify-content: center;
139
+ align-items: center;
140
+ height: 100%;
141
+ }
142
+
143
+ .loader {
144
+ display: flex;
145
+ position: relative;
146
+ background-color: var(--border-color-accent-subdued);
147
+ animation: shadowPulse 2s linear infinite;
148
+ box-shadow:
149
+ -24px 0 var(--border-color-accent-subdued),
150
+ 24px 0 var(--border-color-accent-subdued);
151
+ margin: var(--spacing-md);
152
+ border-radius: 50%;
153
+ width: 10px;
154
+ height: 10px;
155
+ scale: 0.5;
156
+ }
157
+
158
+ @keyframes shadowPulse {
159
+ 33% {
160
+ box-shadow:
161
+ -24px 0 var(--border-color-accent-subdued),
162
+ 24px 0 #fff;
163
+ background: #fff;
164
+ }
165
+ 66% {
166
+ box-shadow:
167
+ -24px 0 #fff,
168
+ 24px 0 #fff;
169
+ background: var(--border-color-accent-subdued);
170
+ }
171
+ 100% {
172
+ box-shadow:
173
+ -24px 0 #fff,
174
+ 24px 0 var(--border-color-accent-subdued);
175
+ background: #fff;
176
+ }
177
+ }
178
+ </style>
6.4.0/video/shared/VideoControls.svelte ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { Undo, Trim, Clear } from "@gradio/icons";
3
+ import VideoTimeline from "./VideoTimeline.svelte";
4
+ import { trimVideo } from "./utils";
5
+ import { FFmpeg } from "@ffmpeg/ffmpeg";
6
+ import loadFfmpeg from "./utils";
7
+ import { onMount } from "svelte";
8
+ import { format_time } from "@gradio/utils";
9
+ import { IconButton } from "@gradio/atoms";
10
+ import { ModifyUpload } from "@gradio/upload";
11
+ import type { FileData } from "@gradio/client";
12
+
13
+ export let videoElement: HTMLVideoElement;
14
+
15
+ export let showRedo = false;
16
+ export let interactive = true;
17
+ export let mode = "";
18
+ export let handle_reset_value: () => void;
19
+ export let handle_trim_video: (videoBlob: Blob) => void;
20
+ export let processingVideo = false;
21
+ export let i18n: (key: string) => string;
22
+ export let value: FileData | null = null;
23
+ export let show_download_button = false;
24
+ export let handle_clear: () => void = () => {};
25
+ export let has_change_history = false;
26
+
27
+ let ffmpeg: FFmpeg;
28
+
29
+ onMount(async () => {
30
+ ffmpeg = await loadFfmpeg();
31
+ });
32
+
33
+ $: if (mode === "edit" && trimmedDuration === null && videoElement)
34
+ trimmedDuration = videoElement.duration;
35
+
36
+ let trimmedDuration: number | null = null;
37
+ let dragStart = 0;
38
+ let dragEnd = 0;
39
+
40
+ let loadingTimeline = false;
41
+
42
+ const toggleTrimmingMode = (): void => {
43
+ if (mode === "edit") {
44
+ mode = "";
45
+ trimmedDuration = videoElement.duration;
46
+ } else {
47
+ mode = "edit";
48
+ }
49
+ };
50
+ </script>
51
+
52
+ <div class="container" class:hidden={mode !== "edit"}>
53
+ {#if mode === "edit"}
54
+ <div class="timeline-wrapper">
55
+ <VideoTimeline
56
+ {videoElement}
57
+ bind:dragStart
58
+ bind:dragEnd
59
+ bind:trimmedDuration
60
+ bind:loadingTimeline
61
+ />
62
+ </div>
63
+ {/if}
64
+
65
+ <div class="controls" data-testid="waveform-controls">
66
+ {#if mode === "edit" && trimmedDuration !== null}
67
+ <time
68
+ aria-label="duration of selected region in seconds"
69
+ class:hidden={loadingTimeline}>{format_time(trimmedDuration)}</time
70
+ >
71
+ <div class="edit-buttons">
72
+ <button
73
+ class:hidden={loadingTimeline}
74
+ class="text-button"
75
+ on:click={() => {
76
+ mode = "";
77
+ processingVideo = true;
78
+ trimVideo(ffmpeg, dragStart, dragEnd, videoElement)
79
+ .then((videoBlob) => {
80
+ handle_trim_video(videoBlob);
81
+ })
82
+ .then(() => {
83
+ processingVideo = false;
84
+ });
85
+ }}>Trim</button
86
+ >
87
+ <button
88
+ class="text-button"
89
+ class:hidden={loadingTimeline}
90
+ on:click={toggleTrimmingMode}>Cancel</button
91
+ >
92
+ </div>
93
+ {:else}
94
+ <div />
95
+ {/if}
96
+ </div>
97
+ </div>
98
+
99
+ <ModifyUpload
100
+ {i18n}
101
+ on:clear={() => handle_clear()}
102
+ download={show_download_button ? value?.url : null}
103
+ >
104
+ {#if showRedo && mode === ""}
105
+ <IconButton
106
+ Icon={Undo}
107
+ label="Reset video to initial value"
108
+ disabled={processingVideo || !has_change_history}
109
+ on:click={() => {
110
+ handle_reset_value();
111
+ mode = "";
112
+ }}
113
+ />
114
+ {/if}
115
+
116
+ {#if interactive && mode === ""}
117
+ <IconButton
118
+ Icon={Trim}
119
+ label="Trim video to selection"
120
+ disabled={processingVideo}
121
+ on:click={toggleTrimmingMode}
122
+ />
123
+ {/if}
124
+ </ModifyUpload>
125
+
126
+ <style>
127
+ .container {
128
+ width: 100%;
129
+ }
130
+ time {
131
+ color: var(--color-accent);
132
+ font-weight: bold;
133
+ padding-left: var(--spacing-xs);
134
+ }
135
+
136
+ .timeline-wrapper {
137
+ display: flex;
138
+ align-items: center;
139
+ justify-content: center;
140
+ width: 100%;
141
+ }
142
+
143
+ .text-button {
144
+ border: 1px solid var(--neutral-400);
145
+ border-radius: var(--radius-sm);
146
+ font-weight: 300;
147
+ font-size: var(--size-3);
148
+ text-align: center;
149
+ color: var(--neutral-400);
150
+ height: var(--size-5);
151
+ font-weight: bold;
152
+ padding: 0 5px;
153
+ margin-left: 5px;
154
+ }
155
+
156
+ .text-button:hover,
157
+ .text-button:focus {
158
+ color: var(--color-accent);
159
+ border-color: var(--color-accent);
160
+ }
161
+
162
+ .controls {
163
+ display: flex;
164
+ justify-content: space-between;
165
+ align-items: center;
166
+ margin: var(--spacing-lg);
167
+ overflow: hidden;
168
+ }
169
+
170
+ .edit-buttons {
171
+ display: flex;
172
+ gap: var(--spacing-sm);
173
+ }
174
+
175
+ @media (max-width: 320px) {
176
+ .controls {
177
+ flex-direction: column;
178
+ align-items: flex-start;
179
+ }
180
+
181
+ .edit-buttons {
182
+ margin-top: var(--spacing-sm);
183
+ }
184
+
185
+ .controls * {
186
+ margin: var(--spacing-sm);
187
+ }
188
+
189
+ .controls .text-button {
190
+ margin-left: 0;
191
+ }
192
+ }
193
+
194
+ .container {
195
+ display: flex;
196
+ flex-direction: column;
197
+ }
198
+
199
+ .hidden {
200
+ display: none;
201
+ }
202
+ </style>
6.4.0/video/shared/VideoPreview.svelte ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { createEventDispatcher, afterUpdate, tick } from "svelte";
3
+ import {
4
+ BlockLabel,
5
+ Empty,
6
+ IconButton,
7
+ ShareButton,
8
+ IconButtonWrapper,
9
+ DownloadLink
10
+ } from "@gradio/atoms";
11
+ import type { FileData, Client } from "@gradio/client";
12
+ import { Video, Download } from "@gradio/icons";
13
+ import { uploadToHuggingFace } from "@gradio/utils";
14
+ import type { CustomButton as CustomButtonType } from "@gradio/utils";
15
+
16
+ import Player from "./Player.svelte";
17
+ import type { I18nFormatter } from "js/core/src/gradio_helper";
18
+
19
+ export let value: FileData | null = null;
20
+ export let subtitle: FileData | null = null;
21
+ export let label: string | undefined = undefined;
22
+ export let show_label = true;
23
+ export let autoplay: boolean;
24
+ export let buttons: (string | CustomButtonType)[] | null = null;
25
+ export let on_custom_button_click: ((id: number) => void) | null = null;
26
+ export let loop: boolean;
27
+ export let i18n: I18nFormatter;
28
+ export let upload: Client["upload"];
29
+ export let display_icon_button_wrapper_top_corner = false;
30
+ export let playback_position = 0;
31
+
32
+ let old_value: FileData | null = null;
33
+ let old_subtitle: FileData | null = null;
34
+
35
+ const dispatch = createEventDispatcher<{
36
+ change: FileData;
37
+ play: undefined;
38
+ pause: undefined;
39
+ end: undefined;
40
+ stop: undefined;
41
+ load: undefined;
42
+ }>();
43
+
44
+ $: value && dispatch("change", value);
45
+
46
+ afterUpdate(async () => {
47
+ // needed to bust subtitle caching issues on Chrome
48
+ if (
49
+ value !== old_value &&
50
+ subtitle !== old_subtitle &&
51
+ old_subtitle !== null
52
+ ) {
53
+ old_value = value;
54
+ value = null;
55
+ await tick();
56
+ value = old_value;
57
+ }
58
+ old_value = value;
59
+ old_subtitle = subtitle;
60
+ });
61
+ </script>
62
+
63
+ <BlockLabel {show_label} Icon={Video} label={label || "Video"} />
64
+ {#if !value || value.url === undefined}
65
+ <Empty unpadded_box={true} size="large"><Video /></Empty>
66
+ {:else}
67
+ {#key value.url}
68
+ <Player
69
+ src={value.url}
70
+ subtitle={subtitle?.url}
71
+ is_stream={value.is_stream}
72
+ {autoplay}
73
+ on:play
74
+ on:pause
75
+ on:stop
76
+ on:end
77
+ on:loadedmetadata={() => {
78
+ // Deal with `<video>`'s `loadedmetadata` event as `VideoPreview`'s `load` event
79
+ // to represent not only the video is loaded but also the metadata is loaded
80
+ // so its dimensions (w/h) are known. This is used for Chatbot's auto scroll.
81
+ dispatch("load");
82
+ }}
83
+ mirror={false}
84
+ {label}
85
+ {loop}
86
+ interactive={false}
87
+ {upload}
88
+ {i18n}
89
+ bind:playback_position
90
+ />
91
+ {/key}
92
+ <div data-testid="download-div">
93
+ <IconButtonWrapper
94
+ display_top_corner={display_icon_button_wrapper_top_corner}
95
+ buttons={buttons ?? ["download", "share"]}
96
+ {on_custom_button_click}
97
+ >
98
+ {#if buttons?.some((btn) => typeof btn === "string" && btn === "download")}
99
+ <DownloadLink
100
+ href={value.is_stream
101
+ ? value.url?.replace("playlist.m3u8", "playlist-file")
102
+ : value.url}
103
+ download={value.orig_name || value.path}
104
+ >
105
+ <IconButton Icon={Download} label="Download" />
106
+ </DownloadLink>
107
+ {/if}
108
+ {#if buttons?.some((btn) => typeof btn === "string" && btn === "share")}
109
+ <ShareButton
110
+ {i18n}
111
+ on:error
112
+ on:share
113
+ {value}
114
+ formatter={async (value) => {
115
+ if (!value) return "";
116
+ let url = await uploadToHuggingFace(value.data, "url");
117
+ return url;
118
+ }}
119
+ />
120
+ {/if}
121
+ </IconButtonWrapper>
122
+ </div>
123
+ {/if}
6.4.0/video/shared/VideoTimeline.svelte ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { onMount, onDestroy } from "svelte";
3
+
4
+ export let videoElement: HTMLVideoElement;
5
+ export let trimmedDuration: number | null;
6
+ export let dragStart: number;
7
+ export let dragEnd: number;
8
+ export let loadingTimeline: boolean;
9
+
10
+ let thumbnails: string[] = [];
11
+ let numberOfThumbnails = 10;
12
+ let intervalId: ReturnType<typeof setInterval> | undefined;
13
+ let videoDuration: number;
14
+
15
+ let leftHandlePosition = 0;
16
+ let rightHandlePosition = 100;
17
+
18
+ let dragging: string | null = null;
19
+
20
+ const startDragging = (side: string | null): void => {
21
+ dragging = side;
22
+ };
23
+
24
+ $: loadingTimeline = thumbnails.length !== numberOfThumbnails;
25
+
26
+ const stopDragging = (): void => {
27
+ dragging = null;
28
+ };
29
+
30
+ const drag = (event: { clientX: number }, distance?: number): void => {
31
+ if (dragging) {
32
+ const timeline = document.getElementById("timeline");
33
+
34
+ if (!timeline) return;
35
+
36
+ const rect = timeline.getBoundingClientRect();
37
+ let newPercentage = ((event.clientX - rect.left) / rect.width) * 100;
38
+
39
+ if (distance) {
40
+ // Move handle based on arrow key press
41
+ newPercentage =
42
+ dragging === "left"
43
+ ? leftHandlePosition + distance
44
+ : rightHandlePosition + distance;
45
+ } else {
46
+ // Move handle based on mouse drag
47
+ newPercentage = ((event.clientX - rect.left) / rect.width) * 100;
48
+ }
49
+
50
+ newPercentage = Math.max(0, Math.min(newPercentage, 100)); // Keep within 0 and 100
51
+
52
+ if (dragging === "left") {
53
+ leftHandlePosition = Math.min(newPercentage, rightHandlePosition);
54
+
55
+ // Calculate the new time and set it for the videoElement
56
+ const newTimeLeft = (leftHandlePosition / 100) * videoDuration;
57
+ videoElement.currentTime = newTimeLeft;
58
+
59
+ dragStart = newTimeLeft;
60
+ } else if (dragging === "right") {
61
+ rightHandlePosition = Math.max(newPercentage, leftHandlePosition);
62
+
63
+ const newTimeRight = (rightHandlePosition / 100) * videoDuration;
64
+ videoElement.currentTime = newTimeRight;
65
+
66
+ dragEnd = newTimeRight;
67
+ }
68
+
69
+ const startTime = (leftHandlePosition / 100) * videoDuration;
70
+ const endTime = (rightHandlePosition / 100) * videoDuration;
71
+ trimmedDuration = endTime - startTime;
72
+
73
+ leftHandlePosition = leftHandlePosition;
74
+ rightHandlePosition = rightHandlePosition;
75
+ }
76
+ };
77
+
78
+ const moveHandle = (e: KeyboardEvent): void => {
79
+ if (dragging) {
80
+ // Calculate the movement distance as a percentage of the video duration
81
+ const distance = (1 / videoDuration) * 100;
82
+
83
+ if (e.key === "ArrowLeft") {
84
+ drag({ clientX: 0 }, -distance);
85
+ } else if (e.key === "ArrowRight") {
86
+ drag({ clientX: 0 }, distance);
87
+ }
88
+ }
89
+ };
90
+
91
+ const generateThumbnail = (): void => {
92
+ const canvas = document.createElement("canvas");
93
+ const ctx = canvas.getContext("2d");
94
+ if (!ctx) return;
95
+
96
+ canvas.width = videoElement.videoWidth;
97
+ canvas.height = videoElement.videoHeight;
98
+
99
+ ctx.drawImage(videoElement, 0, 0, canvas.width, canvas.height);
100
+
101
+ const thumbnail: string = canvas.toDataURL("image/jpeg", 0.7);
102
+ thumbnails = [...thumbnails, thumbnail];
103
+ };
104
+
105
+ onMount(() => {
106
+ const loadMetadata = (): void => {
107
+ videoDuration = videoElement.duration;
108
+
109
+ const interval = videoDuration / numberOfThumbnails;
110
+ let captures = 0;
111
+
112
+ const onSeeked = (): void => {
113
+ generateThumbnail();
114
+ captures++;
115
+
116
+ if (captures < numberOfThumbnails) {
117
+ videoElement.currentTime += interval;
118
+ } else {
119
+ videoElement.removeEventListener("seeked", onSeeked);
120
+ }
121
+ };
122
+
123
+ videoElement.addEventListener("seeked", onSeeked);
124
+ videoElement.currentTime = 0;
125
+ };
126
+
127
+ if (videoElement.readyState >= 1) {
128
+ loadMetadata();
129
+ } else {
130
+ videoElement.addEventListener("loadedmetadata", loadMetadata);
131
+ }
132
+ });
133
+
134
+ onDestroy(() => {
135
+ window.removeEventListener("mousemove", drag);
136
+ window.removeEventListener("mouseup", stopDragging);
137
+ window.removeEventListener("keydown", moveHandle);
138
+
139
+ if (intervalId !== undefined) {
140
+ clearInterval(intervalId);
141
+ }
142
+ });
143
+
144
+ onMount(() => {
145
+ window.addEventListener("mousemove", drag);
146
+ window.addEventListener("mouseup", stopDragging);
147
+ window.addEventListener("keydown", moveHandle);
148
+ });
149
+ </script>
150
+
151
+ <div class="container">
152
+ {#if loadingTimeline}
153
+ <div class="load-wrap">
154
+ <span aria-label="loading timeline" class="loader" />
155
+ </div>
156
+ {:else}
157
+ <div id="timeline" class="thumbnail-wrapper">
158
+ <button
159
+ aria-label="start drag handle for trimming video"
160
+ class="handle left"
161
+ on:mousedown={() => startDragging("left")}
162
+ on:blur={stopDragging}
163
+ on:keydown={(e) => {
164
+ if (e.key === "ArrowLeft" || e.key == "ArrowRight") {
165
+ startDragging("left");
166
+ }
167
+ }}
168
+ style="left: {leftHandlePosition}%;"
169
+ />
170
+
171
+ <div
172
+ class="opaque-layer"
173
+ style="left: {leftHandlePosition}%; right: {100 - rightHandlePosition}%"
174
+ />
175
+
176
+ {#each thumbnails as thumbnail, i (i)}
177
+ <img src={thumbnail} alt={`frame-${i}`} draggable="false" />
178
+ {/each}
179
+ <button
180
+ aria-label="end drag handle for trimming video"
181
+ class="handle right"
182
+ on:mousedown={() => startDragging("right")}
183
+ on:blur={stopDragging}
184
+ on:keydown={(e) => {
185
+ if (e.key === "ArrowLeft" || e.key == "ArrowRight") {
186
+ startDragging("right");
187
+ }
188
+ }}
189
+ style="left: {rightHandlePosition}%;"
190
+ />
191
+ </div>
192
+ {/if}
193
+ </div>
194
+
195
+ <style>
196
+ .load-wrap {
197
+ display: flex;
198
+ justify-content: center;
199
+ align-items: center;
200
+ height: 100%;
201
+ }
202
+ .loader {
203
+ display: flex;
204
+ position: relative;
205
+ background-color: var(--border-color-accent-subdued);
206
+ animation: shadowPulse 2s linear infinite;
207
+ box-shadow:
208
+ -24px 0 var(--border-color-accent-subdued),
209
+ 24px 0 var(--border-color-accent-subdued);
210
+ margin: var(--spacing-md);
211
+ border-radius: 50%;
212
+ width: 10px;
213
+ height: 10px;
214
+ scale: 0.5;
215
+ }
216
+
217
+ @keyframes shadowPulse {
218
+ 33% {
219
+ box-shadow:
220
+ -24px 0 var(--border-color-accent-subdued),
221
+ 24px 0 #fff;
222
+ background: #fff;
223
+ }
224
+ 66% {
225
+ box-shadow:
226
+ -24px 0 #fff,
227
+ 24px 0 #fff;
228
+ background: var(--border-color-accent-subdued);
229
+ }
230
+ 100% {
231
+ box-shadow:
232
+ -24px 0 #fff,
233
+ 24px 0 var(--border-color-accent-subdued);
234
+ background: #fff;
235
+ }
236
+ }
237
+
238
+ .container {
239
+ display: flex;
240
+ flex-direction: column;
241
+ align-items: center;
242
+ justify-content: center;
243
+ margin: var(--spacing-lg) var(--spacing-lg) 0 var(--spacing-lg);
244
+ }
245
+
246
+ #timeline {
247
+ display: flex;
248
+ height: var(--size-10);
249
+ flex: 1;
250
+ position: relative;
251
+ }
252
+
253
+ img {
254
+ flex: 1 1 auto;
255
+ min-width: 0;
256
+ object-fit: cover;
257
+ height: var(--size-12);
258
+ border: 1px solid var(--block-border-color);
259
+ user-select: none;
260
+ z-index: 1;
261
+ }
262
+
263
+ .handle {
264
+ width: 3px;
265
+ background-color: var(--color-accent);
266
+ cursor: ew-resize;
267
+ height: var(--size-12);
268
+ z-index: 3;
269
+ position: absolute;
270
+ }
271
+
272
+ .opaque-layer {
273
+ background-color: rgba(230, 103, 40, 0.25);
274
+ border: 1px solid var(--color-accent);
275
+ height: var(--size-12);
276
+ position: absolute;
277
+ z-index: 2;
278
+ }
279
+ </style>
6.4.0/video/shared/VolumeControl.svelte ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+
4
+ export let current_volume = 1;
5
+ export let show_volume_slider = false;
6
+
7
+ let volume_element: HTMLInputElement;
8
+
9
+ onMount(() => {
10
+ adjustSlider();
11
+ });
12
+
13
+ const adjustSlider = (): void => {
14
+ let slider = volume_element;
15
+ if (!slider) return;
16
+
17
+ slider.style.background = `linear-gradient(to right, white ${
18
+ current_volume * 100
19
+ }%, rgba(255, 255, 255, 0.3) ${current_volume * 100}%)`;
20
+ };
21
+
22
+ $: (current_volume, adjustSlider());
23
+ </script>
24
+
25
+ <input
26
+ bind:this={volume_element}
27
+ id="volume"
28
+ class="volume-slider"
29
+ type="range"
30
+ min="0"
31
+ max="1"
32
+ step="0.01"
33
+ value={current_volume}
34
+ on:focusout={() => (show_volume_slider = false)}
35
+ on:input={(e) => {
36
+ if (e.target instanceof HTMLInputElement) {
37
+ current_volume = parseFloat(e.target.value);
38
+ }
39
+ }}
40
+ />
41
+
42
+ <style>
43
+ .volume-slider {
44
+ -webkit-appearance: none;
45
+ appearance: none;
46
+ width: var(--size-20);
47
+ accent-color: var(--color-accent);
48
+ height: 4px;
49
+ cursor: pointer;
50
+ outline: none;
51
+ border-radius: 15px;
52
+ background-color: rgba(255, 255, 255, 0.3);
53
+ margin-left: var(--spacing-sm);
54
+ }
55
+
56
+ input[type="range"]::-webkit-slider-thumb {
57
+ -webkit-appearance: none;
58
+ appearance: none;
59
+ height: 15px;
60
+ width: 15px;
61
+ background-color: white;
62
+ border-radius: 50%;
63
+ border: none;
64
+ transition: 0.2s ease-in-out;
65
+ }
66
+
67
+ input[type="range"]::-moz-range-thumb {
68
+ height: 15px;
69
+ width: 15px;
70
+ background-color: white;
71
+ border-radius: 50%;
72
+ border: none;
73
+ transition: 0.2s ease-in-out;
74
+ }
75
+ </style>
6.4.0/video/shared/index.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export { default as Video } from "./Video.svelte";
6.4.0/video/shared/types.ts ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ export interface SubtitleData {
2
+ start: number;
3
+ end: number;
4
+ text: string;
5
+ }
6.4.0/video/shared/utils.ts ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { toBlobURL } from "@ffmpeg/util";
2
+ import { FFmpeg } from "@ffmpeg/ffmpeg";
3
+ import { lookup } from "mrmime";
4
+
5
+ export const prettyBytes = (bytes: number): string => {
6
+ let units = ["B", "KB", "MB", "GB", "PB"];
7
+ let i = 0;
8
+ while (bytes > 1024) {
9
+ bytes /= 1024;
10
+ i++;
11
+ }
12
+ let unit = units[i];
13
+ return bytes.toFixed(1) + " " + unit;
14
+ };
15
+
16
+ export const playable = (): boolean => {
17
+ // TODO: Fix this
18
+ // let video_element = document.createElement("video");
19
+ // let mime_type = mime.lookup(filename);
20
+ // return video_element.canPlayType(mime_type) != "";
21
+ return true; // FIX BEFORE COMMIT - mime import causing issues
22
+ };
23
+
24
+ export function loaded(
25
+ node: HTMLVideoElement,
26
+ { autoplay }: { autoplay: boolean }
27
+ ): any {
28
+ async function handle_playback(): Promise<void> {
29
+ if (!autoplay) return;
30
+ await node.play();
31
+ }
32
+
33
+ node.addEventListener("loadeddata", handle_playback);
34
+
35
+ return {
36
+ destroy(): void {
37
+ node.removeEventListener("loadeddata", handle_playback);
38
+ }
39
+ };
40
+ }
41
+
42
+ export default async function loadFfmpeg(): Promise<FFmpeg> {
43
+ const ffmpeg = new FFmpeg();
44
+ const baseURL = "https://unpkg.com/@ffmpeg/core@0.12.4/dist/esm";
45
+
46
+ await ffmpeg.load({
47
+ coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, "text/javascript"),
48
+ wasmURL: await toBlobURL(`${baseURL}/ffmpeg-core.wasm`, "application/wasm")
49
+ });
50
+
51
+ return ffmpeg;
52
+ }
53
+
54
+ export function blob_to_data_url(blob: Blob): Promise<string> {
55
+ return new Promise((fulfill, reject) => {
56
+ let reader = new FileReader();
57
+ reader.onerror = reject;
58
+ reader.onload = () => fulfill(reader.result as string);
59
+ reader.readAsDataURL(blob);
60
+ });
61
+ }
62
+
63
+ export async function trimVideo(
64
+ ffmpeg: FFmpeg,
65
+ startTime: number,
66
+ endTime: number,
67
+ videoElement: HTMLVideoElement
68
+ ): Promise<any> {
69
+ const videoUrl = videoElement.src;
70
+ const mimeType = lookup(videoElement.src) || "video/mp4";
71
+ const blobUrl = await toBlobURL(videoUrl, mimeType);
72
+ const response = await fetch(blobUrl);
73
+ const vidBlob = await response.blob();
74
+ const type = getVideoExtensionFromMimeType(mimeType) || "mp4";
75
+ const inputName = `input.${type}`;
76
+ const outputName = `output.${type}`;
77
+
78
+ try {
79
+ if (startTime === 0 && endTime === 0) {
80
+ return vidBlob;
81
+ }
82
+
83
+ await ffmpeg.writeFile(
84
+ inputName,
85
+ new Uint8Array(await vidBlob.arrayBuffer())
86
+ );
87
+
88
+ let command = [
89
+ "-i",
90
+ inputName,
91
+ ...(startTime !== 0 ? ["-ss", startTime.toString()] : []),
92
+ ...(endTime !== 0 ? ["-to", endTime.toString()] : []),
93
+ "-c:a",
94
+ "copy",
95
+ outputName
96
+ ];
97
+
98
+ await ffmpeg.exec(command);
99
+ const outputData = await ffmpeg.readFile(outputName);
100
+ const outputBlob = new Blob([outputData], {
101
+ type: `video/${type}`
102
+ });
103
+
104
+ return outputBlob;
105
+ } catch (error) {
106
+ console.error("Error initializing FFmpeg:", error);
107
+ return vidBlob;
108
+ }
109
+ }
110
+
111
+ const getVideoExtensionFromMimeType = (mimeType: string): string | null => {
112
+ const videoMimeToExtensionMap: { [key: string]: string } = {
113
+ "video/mp4": "mp4",
114
+ "video/webm": "webm",
115
+ "video/ogg": "ogv",
116
+ "video/quicktime": "mov",
117
+ "video/x-msvideo": "avi",
118
+ "video/x-matroska": "mkv",
119
+ "video/mpeg": "mpeg",
120
+ "video/3gpp": "3gp",
121
+ "video/3gpp2": "3g2",
122
+ "video/h261": "h261",
123
+ "video/h263": "h263",
124
+ "video/h264": "h264",
125
+ "video/jpeg": "jpgv",
126
+ "video/jpm": "jpm",
127
+ "video/mj2": "mj2",
128
+ "video/mpv": "mpv",
129
+ "video/vnd.ms-playready.media.pyv": "pyv",
130
+ "video/vnd.uvvu.mp4": "uvu",
131
+ "video/vnd.vivo": "viv",
132
+ "video/x-f4v": "f4v",
133
+ "video/x-fli": "fli",
134
+ "video/x-flv": "flv",
135
+ "video/x-m4v": "m4v",
136
+ "video/x-ms-asf": "asf",
137
+ "video/x-ms-wm": "wm",
138
+ "video/x-ms-wmv": "wmv",
139
+ "video/x-ms-wmx": "wmx",
140
+ "video/x-ms-wvx": "wvx",
141
+ "video/x-sgi-movie": "movie",
142
+ "video/x-smv": "smv"
143
+ };
144
+
145
+ return videoMimeToExtensionMap[mimeType] || null;
146
+ };
147
+
148
+ export interface WebcamOptions {
149
+ mirror: boolean;
150
+ constraints: Record<string, any>;
151
+ }
6.4.0/video/types.ts ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { FileData } from "@gradio/client";
2
+ import type { LoadingStatus } from "@gradio/statustracker";
3
+ import type { CustomButton } from "@gradio/utils";
4
+ import type { WebcamOptions } from "./shared/utils";
5
+
6
+ export interface VideoProps {
7
+ value: FileData | null;
8
+ height: number | undefined;
9
+ width: number | undefined;
10
+ autoplay: boolean;
11
+ buttons: ("share" | "download" | "fullscreen" | CustomButton)[];
12
+ sources:
13
+ | ["webcam"]
14
+ | ["upload"]
15
+ | ["webcam", "upload"]
16
+ | ["upload", "webcam"];
17
+ webcam_options: WebcamOptions;
18
+ include_audio: boolean;
19
+ loop: boolean;
20
+ webcam_constraints: object;
21
+ subtitles: FileData | null;
22
+ playback_position: number;
23
+ }
24
+
25
+ export interface VideoEvents {
26
+ change: never;
27
+ clear: never;
28
+ play: never;
29
+ pause: never;
30
+ upload: never;
31
+ stop: never;
32
+ end: never;
33
+ start_recording: never;
34
+ stop_recording: never;
35
+ input: any;
36
+ clear_status: LoadingStatus;
37
+ share: any;
38
+ error: any;
39
+ warning: any;
40
+ custom_button_click: { id: number };
41
+ }