@gradio/video 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @gradio/video
2
2
 
3
+ ## 0.1.9
4
+
5
+ ### Fixes
6
+
7
+ - [#6566](https://github.com/gradio-app/gradio/pull/6566) [`d548202`](https://github.com/gradio-app/gradio/commit/d548202d2b5bd8a99e3ebc5bf56820b0282ce0f5) - Improve video trimming and error handling. Thanks [@hannahblair](https://github.com/hannahblair)!
8
+
3
9
  ## 0.1.8
4
10
 
5
11
  ### Patch Changes
@@ -228,4 +234,4 @@ Thanks [@pngwn](https://github.com/pngwn)!
228
234
  - @gradio/image@0.1.0
229
235
  - @gradio/utils@0.0.2
230
236
  - @gradio/atoms@0.0.2
231
- - @gradio/upload@0.0.2
237
+ - @gradio/upload@0.0.2
@@ -3,30 +3,15 @@
3
3
  import Video from "./Index.svelte";
4
4
  import { format } from "svelte-i18n";
5
5
  import { get } from "svelte/store";
6
+ import { userEvent, within } from "@storybook/testing-library";
7
+ import { waitFor } from "@testing-library/dom";
6
8
  </script>
7
9
 
8
- <Meta
9
- title="Components/Video"
10
- component={Video}
11
- argTypes={{
12
- video: {
13
- control: "text",
14
- description:
15
- "A path or URL for the default value that Video component is going to take. Can also be a tuple consisting of (video filepath, subtitle filepath). If a subtitle file is provided, it should be of type .srt or .vtt. Or can be callable, in which case the function will be called whenever the app loads to set the initial value of the component.",
16
- name: "value"
17
- },
18
- autoplay: {
19
- control: [true, false],
20
- description: "Whether to autoplay the video on load",
21
- name: "autoplay",
22
- value: true
23
- }
24
- }}
25
- />
10
+ <Meta title="Components/Video" component={Video} />
26
11
 
27
12
  <div>
28
13
  <Template let:args>
29
- <Video {...args} i18n={get(format)} />
14
+ <Video i18n={get(format)} {...args} />
30
15
  </Template>
31
16
  </div>
32
17
 
@@ -72,3 +57,26 @@
72
57
  value: null
73
58
  }}
74
59
  />
60
+
61
+ <Story
62
+ name="Trim video"
63
+ args={{
64
+ value: {
65
+ video: {
66
+ path: "https://gradio-static-files.s3.us-west-2.amazonaws.com/world.mp4",
67
+ url: "https://gradio-static-files.s3.us-west-2.amazonaws.com/world.mp4",
68
+ orig_name: "world.mp4"
69
+ }
70
+ },
71
+ label: "world video",
72
+ show_label: true,
73
+ interactive: "true",
74
+ sources: ["upload"],
75
+ width: 400
76
+ }}
77
+ play={async ({ canvasElement }) => {
78
+ const canvas = within(canvasElement);
79
+ const trimButton = canvas.getByLabelText("Trim video to selection");
80
+ userEvent.click(trimButton);
81
+ }}
82
+ />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradio/video",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Gradio UI packages",
5
5
  "type": "module",
6
6
  "author": "",
@@ -9,14 +9,14 @@
9
9
  "dependencies": {
10
10
  "@ffmpeg/ffmpeg": "^0.12.7",
11
11
  "@ffmpeg/util": "^0.12.1",
12
- "@gradio/atoms": "^0.3.0",
12
+ "@gradio/atoms": "^0.3.1",
13
13
  "@gradio/client": "^0.8.2",
14
- "@gradio/icons": "^0.3.0",
15
- "@gradio/statustracker": "^0.4.0",
16
- "@gradio/image": "^0.4.1",
17
- "@gradio/upload": "^0.5.1",
14
+ "@gradio/icons": "^0.3.1",
15
+ "@gradio/image": "^0.4.2",
16
+ "@gradio/statustracker": "^0.4.1",
17
+ "@gradio/wasm": "^0.3.0",
18
18
  "@gradio/utils": "^0.2.0",
19
- "@gradio/wasm": "^0.3.0"
19
+ "@gradio/upload": "^0.5.2"
20
20
  },
21
21
  "devDependencies": {
22
22
  "mrmime": "^1.0.1"
@@ -28,6 +28,11 @@
28
28
  const minutes = Math.floor(seconds / 60);
29
29
  const secondsRemainder = Math.round(seconds) % 60;
30
30
  const paddedSeconds = `0${secondsRemainder}`.slice(-2);
31
+
32
+ if (Number.isNaN(minutes) || Number.isNaN(secondsRemainder)) {
33
+ return "00:00";
34
+ }
35
+
31
36
  return `${minutes}:${paddedSeconds}`;
32
37
  };
33
38
 
@@ -156,6 +156,7 @@
156
156
  {:else}
157
157
  <div id="timeline" class="thumbnail-wrapper">
158
158
  <button
159
+ aria-label="start drag handle for trimming video"
159
160
  class="handle left"
160
161
  on:mousedown={() => startDragging("left")}
161
162
  on:blur={stopDragging}
@@ -176,6 +177,7 @@
176
177
  <img src={thumbnail} alt={`frame-${i}`} draggable="false" />
177
178
  {/each}
178
179
  <button
180
+ aria-label="end drag handle for trimming video"
179
181
  class="handle right"
180
182
  on:mousedown={() => startDragging("right")}
181
183
  on:blur={stopDragging}
package/shared/utils.ts CHANGED
@@ -66,15 +66,19 @@ export async function trimVideo(
66
66
  endTime: number,
67
67
  videoElement: HTMLVideoElement
68
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
+
69
78
  try {
70
- const videoUrl = videoElement.src;
71
- const mimeType = lookup(videoElement.src) || "video/mp4";
72
- const blobUrl = await toBlobURL(videoUrl, mimeType);
73
- const response = await fetch(blobUrl);
74
- const vidBlob = await response.blob();
75
- const type = getVideoExtensionFromMimeType(mimeType) || "mp4";
76
- const inputName = `input.${type}`;
77
- const outputName = `output.${type}`;
79
+ if (startTime === 0 && endTime === 0) {
80
+ return vidBlob;
81
+ }
78
82
 
79
83
  await ffmpeg.writeFile(
80
84
  inputName,
@@ -84,10 +88,8 @@ export async function trimVideo(
84
88
  let command = [
85
89
  "-i",
86
90
  inputName,
87
- "-ss",
88
- startTime.toString(),
89
- "-to",
90
- endTime.toString(),
91
+ ...(startTime !== 0 ? ["-ss", startTime.toString()] : []),
92
+ ...(endTime !== 0 ? ["-to", endTime.toString()] : []),
91
93
  "-c:a",
92
94
  "copy",
93
95
  outputName
@@ -102,6 +104,7 @@ export async function trimVideo(
102
104
  return outputBlob;
103
105
  } catch (error) {
104
106
  console.error("Error initializing FFmpeg:", error);
107
+ return vidBlob;
105
108
  }
106
109
  }
107
110