Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video: Allow re-trimming of already trimmed video #9315

Merged
merged 6 commits into from
Oct 10, 2021

Conversation

barklund
Copy link
Contributor

@barklund barklund commented Oct 7, 2021

Context

This implements re-trimming an already trimmed video by abstracting out which video is being trimmed completely from most components.

To-do

Some things that could be added, but don't have to be:

  • Caching the loaded media and checking if we might even already have it in the media library.
  • Agree what the custom poster should be (should it be taken from the video being re-trimmed or the original video?)

User-facing changes

Trimming a video, that has already been trimmed, now shows the full original video with the handles placed correctly:
retrim

Testing Instructions

This PR can be tested by following these steps:

  1. Add an original (not trimmed) video to a page
  2. Click to enter trim mode and observe, that the handles start at the far end for the trim rail
  3. Move both handles in and press to trim the video
  4. When trimming is fully completed press to trim the new video again
  5. Observe that the trim handles are now placed exactly as before with the same indents made before pressing the trim button
  6. Move the trim handles to completely new positions and press trim to re-trim the video
  7. Once trimming has completed, observe that this third video is correctly trimmed to the desired interval (optionally by entering trim mode to see the handle positions and play the loop)
  8. Insert another copy of the newly trimmed video on the canvas
  9. Press to enter trim mode and observe the same trim position is still the case

Checklist

  • This PR addresses an existing issue and I have linked this PR to it in ZenHub
  • I have tested this code to the best of my abilities
  • I have verified accessibility to the best of my abilities (docs)
  • I have verified i18n and l10n (translation, right-to-left layout) to the best of my abilities
  • This code is covered by automated tests (unit, integration, and/or e2e) to verify it works as intended (docs)
  • I have added documentation where necessary
  • I have added a matching Type: XYZ label to the PR

Fixes #8892

@barklund barklund added Type: Enhancement New feature or improvement of an existing feature Pod: Prometheus labels Oct 7, 2021
@barklund barklund requested review from swissspidy and miina October 7, 2021 01:47
@barklund barklund self-assigned this Oct 7, 2021
@google-cla google-cla bot added the cla: yes label Oct 7, 2021
# Conflicts:
#	packages/story-editor/src/components/videoTrim/provider.js
#	packages/story-editor/src/components/videoTrim/useVideoNode.js
#	packages/story-editor/src/components/videoTrim/videoTrimmer.js
@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2021

Size Change: +839 B (0%)

Total Size: 4.05 MB

Filename Size Change
assets/js/chunk-getStoryPropsToSave.js 1.32 MB +469 B (0%)
assets/js/wp-story-editor.js 1.49 MB +433 B (0%)
ℹ️ View Unchanged
Filename Size Change
assets/css/carousel-view-rtl.css 701 B 0 B
assets/css/carousel-view.css 701 B 0 B
assets/css/vendors-chunk-getStoryPropsToSave-wp-story-editor-rtl.css 706 B 0 B
assets/css/vendors-chunk-getStoryPropsToSave-wp-story-editor.css 706 B 0 B
assets/css/web-stories-block-rtl.css 4.43 kB 0 B
assets/css/web-stories-block.css 4.47 kB 0 B
assets/css/web-stories-embed-rtl.css 288 B 0 B
assets/css/web-stories-embed.css 288 B 0 B
assets/css/web-stories-list-styles-rtl.css 2.3 kB 0 B
assets/css/web-stories-list-styles.css 2.32 kB 0 B
assets/css/web-stories-theme-style-twentyeleven-rtl.css 102 B 0 B
assets/css/web-stories-theme-style-twentyeleven.css 102 B 0 B
assets/css/web-stories-theme-style-twentyfifteen-rtl.css 251 B 0 B
assets/css/web-stories-theme-style-twentyfifteen.css 251 B 0 B
assets/css/web-stories-theme-style-twentyfourteen-rtl.css 287 B 0 B
assets/css/web-stories-theme-style-twentyfourteen.css 287 B 0 B
assets/css/web-stories-theme-style-twentyseventeen-rtl.css 288 B 0 B
assets/css/web-stories-theme-style-twentyseventeen.css 288 B 0 B
assets/css/web-stories-theme-style-twentysixteen-rtl.css 224 B 0 B
assets/css/web-stories-theme-style-twentysixteen.css 224 B 0 B
assets/css/web-stories-theme-style-twentyten-rtl.css 143 B 0 B
assets/css/web-stories-theme-style-twentyten.css 143 B 0 B
assets/css/web-stories-theme-style-twentytwelve-rtl.css 256 B 0 B
assets/css/web-stories-theme-style-twentytwelve.css 256 B 0 B
assets/css/web-stories-theme-style-twentytwenty-rtl.css 86 B 0 B
assets/css/web-stories-theme-style-twentytwenty.css 86 B 0 B
assets/css/web-stories-theme-style-twentytwentyone-rtl.css 325 B 0 B
assets/css/web-stories-theme-style-twentytwentyone.css 326 B 0 B
assets/css/web-stories-widget-rtl.css 485 B 0 B
assets/css/web-stories-widget.css 485 B 0 B
assets/css/wp-dashboard-rtl.css 658 B 0 B
assets/css/wp-dashboard.css 659 B 0 B
assets/css/wp-story-editor-rtl.css 608 B 0 B
assets/css/wp-story-editor.css 609 B 0 B
assets/js/carousel-view.js 3.72 kB 0 B
assets/js/chunk-colorthief.js 2.61 kB +1 B (0%)
assets/js/chunk-focus-visible.js 1 kB +1 B (0%)
assets/js/chunk-fonts.js 53.2 kB 0 B
assets/js/chunk-web-stories-template-0.js 535 B 0 B
assets/js/chunk-web-stories-template-100.js 465 B -1 B (0%)
assets/js/chunk-web-stories-template-102.js 9.15 kB 0 B
assets/js/chunk-web-stories-template-104.js 516 B 0 B
assets/js/chunk-web-stories-template-108.js 488 B 0 B
assets/js/chunk-web-stories-template-110.js 6.99 kB 0 B
assets/js/chunk-web-stories-template-112.js 566 B -1 B (0%)
assets/js/chunk-web-stories-template-116.js 539 B -1 B (0%)
assets/js/chunk-web-stories-template-118.js 7.06 kB 0 B
assets/js/chunk-web-stories-template-12.js 503 B 0 B
assets/js/chunk-web-stories-template-120.js 531 B 0 B
assets/js/chunk-web-stories-template-124.js 503 B 0 B
assets/js/chunk-web-stories-template-126.js 7.69 kB 0 B
assets/js/chunk-web-stories-template-128.js 574 B 0 B
assets/js/chunk-web-stories-template-132.js 546 B 0 B
assets/js/chunk-web-stories-template-134.js 9.85 kB 0 B
assets/js/chunk-web-stories-template-136.js 535 B +1 B (0%)
assets/js/chunk-web-stories-template-14.js 8.57 kB 0 B
assets/js/chunk-web-stories-template-140.js 507 B 0 B
assets/js/chunk-web-stories-template-142.js 7.95 kB 0 B
assets/js/chunk-web-stories-template-144.js 573 B 0 B
assets/js/chunk-web-stories-template-148.js 545 B 0 B
assets/js/chunk-web-stories-template-150.js 8.79 kB 0 B
assets/js/chunk-web-stories-template-152.js 485 B 0 B
assets/js/chunk-web-stories-template-156.js 457 B 0 B
assets/js/chunk-web-stories-template-158.js 9.6 kB 0 B
assets/js/chunk-web-stories-template-16.js 571 B 0 B
assets/js/chunk-web-stories-template-160.js 541 B 0 B
assets/js/chunk-web-stories-template-164.js 514 B 0 B
assets/js/chunk-web-stories-template-166.js 8.21 kB 0 B
assets/js/chunk-web-stories-template-168.js 519 B 0 B
assets/js/chunk-web-stories-template-172.js 492 B 0 B
assets/js/chunk-web-stories-template-174.js 8.49 kB 0 B
assets/js/chunk-web-stories-template-176.js 510 B 0 B
assets/js/chunk-web-stories-template-180.js 482 B -1 B (0%)
assets/js/chunk-web-stories-template-182.js 6.91 kB 0 B
assets/js/chunk-web-stories-template-184.js 595 B 0 B
assets/js/chunk-web-stories-template-188.js 567 B 0 B
assets/js/chunk-web-stories-template-190.js 6.63 kB -1 B (0%)
assets/js/chunk-web-stories-template-192.js 511 B 0 B
assets/js/chunk-web-stories-template-196.js 484 B 0 B
assets/js/chunk-web-stories-template-198.js 10.5 kB 0 B
assets/js/chunk-web-stories-template-20.js 543 B 0 B
assets/js/chunk-web-stories-template-200.js 535 B 0 B
assets/js/chunk-web-stories-template-204.js 507 B +1 B (0%)
assets/js/chunk-web-stories-template-206.js 6.71 kB 0 B
assets/js/chunk-web-stories-template-208.js 589 B -1 B (0%)
assets/js/chunk-web-stories-template-212.js 562 B 0 B
assets/js/chunk-web-stories-template-214.js 6.32 kB 0 B
assets/js/chunk-web-stories-template-216.js 535 B 0 B
assets/js/chunk-web-stories-template-22.js 8.69 kB 0 B
assets/js/chunk-web-stories-template-220.js 507 B 0 B
assets/js/chunk-web-stories-template-222.js 7.16 kB 0 B
assets/js/chunk-web-stories-template-224.js 525 B 0 B
assets/js/chunk-web-stories-template-228.js 498 B 0 B
assets/js/chunk-web-stories-template-230.js 8.05 kB 0 B
assets/js/chunk-web-stories-template-232.js 551 B 0 B
assets/js/chunk-web-stories-template-236.js 524 B 0 B
assets/js/chunk-web-stories-template-238.js 8.09 kB 0 B
assets/js/chunk-web-stories-template-24.js 531 B +1 B (0%)
assets/js/chunk-web-stories-template-240.js 564 B 0 B
assets/js/chunk-web-stories-template-244.js 537 B 0 B
assets/js/chunk-web-stories-template-246.js 7.42 kB 0 B
assets/js/chunk-web-stories-template-248.js 503 B +1 B (0%)
assets/js/chunk-web-stories-template-252.js 476 B 0 B
assets/js/chunk-web-stories-template-254.js 9.14 kB 0 B
assets/js/chunk-web-stories-template-256.js 540 B 0 B
assets/js/chunk-web-stories-template-260.js 512 B +1 B (0%)
assets/js/chunk-web-stories-template-262.js 12 kB 0 B
assets/js/chunk-web-stories-template-264.js 489 B +1 B (0%)
assets/js/chunk-web-stories-template-268.js 463 B 0 B
assets/js/chunk-web-stories-template-270.js 8.54 kB 0 B
assets/js/chunk-web-stories-template-272.js 560 B 0 B
assets/js/chunk-web-stories-template-276.js 533 B 0 B
assets/js/chunk-web-stories-template-278.js 7.21 kB 0 B
assets/js/chunk-web-stories-template-28.js 503 B 0 B
assets/js/chunk-web-stories-template-280.js 556 B +1 B (0%)
assets/js/chunk-web-stories-template-284.js 528 B 0 B
assets/js/chunk-web-stories-template-286.js 8.48 kB 0 B
assets/js/chunk-web-stories-template-288.js 576 B -1 B (0%)
assets/js/chunk-web-stories-template-292.js 547 B 0 B
assets/js/chunk-web-stories-template-294.js 11.1 kB 0 B
assets/js/chunk-web-stories-template-296.js 522 B +1 B (0%)
assets/js/chunk-web-stories-template-30.js 7.81 kB 0 B
assets/js/chunk-web-stories-template-300.js 495 B 0 B
assets/js/chunk-web-stories-template-302.js 5.93 kB 0 B
assets/js/chunk-web-stories-template-304.js 571 B 0 B
assets/js/chunk-web-stories-template-308.js 544 B +1 B (0%)
assets/js/chunk-web-stories-template-310.js 7.5 kB 0 B
assets/js/chunk-web-stories-template-312.js 579 B +1 B (0%)
assets/js/chunk-web-stories-template-316.js 552 B 0 B
assets/js/chunk-web-stories-template-318.js 7.1 kB 0 B
assets/js/chunk-web-stories-template-32.js 558 B 0 B
assets/js/chunk-web-stories-template-320.js 551 B +1 B (0%)
assets/js/chunk-web-stories-template-324.js 523 B -1 B (0%)
assets/js/chunk-web-stories-template-326.js 8.7 kB 0 B
assets/js/chunk-web-stories-template-328.js 551 B 0 B
assets/js/chunk-web-stories-template-332.js 523 B 0 B
assets/js/chunk-web-stories-template-334.js 7.38 kB 0 B
assets/js/chunk-web-stories-template-336.js 512 B 0 B
assets/js/chunk-web-stories-template-340.js 486 B 0 B
assets/js/chunk-web-stories-template-342.js 6.57 kB 0 B
assets/js/chunk-web-stories-template-344.js 545 B 0 B
assets/js/chunk-web-stories-template-348.js 517 B 0 B
assets/js/chunk-web-stories-template-350.js 7.97 kB 0 B
assets/js/chunk-web-stories-template-352.js 561 B 0 B
assets/js/chunk-web-stories-template-356.js 533 B -1 B (0%)
assets/js/chunk-web-stories-template-358.js 9.79 kB 0 B
assets/js/chunk-web-stories-template-36.js 529 B 0 B
assets/js/chunk-web-stories-template-360.js 556 B 0 B
assets/js/chunk-web-stories-template-364.js 529 B 0 B
assets/js/chunk-web-stories-template-366.js 6.86 kB 0 B
assets/js/chunk-web-stories-template-368.js 526 B -2 B (0%)
assets/js/chunk-web-stories-template-372.js 501 B 0 B
assets/js/chunk-web-stories-template-374.js 4.57 kB 0 B
assets/js/chunk-web-stories-template-376.js 574 B 0 B
assets/js/chunk-web-stories-template-38.js 11 kB 0 B
assets/js/chunk-web-stories-template-380.js 546 B 0 B
assets/js/chunk-web-stories-template-382.js 7.93 kB 0 B
assets/js/chunk-web-stories-template-384.js 542 B -1 B (0%)
assets/js/chunk-web-stories-template-388.js 516 B 0 B
assets/js/chunk-web-stories-template-390.js 7.76 kB 0 B
assets/js/chunk-web-stories-template-392.js 499 B 0 B
assets/js/chunk-web-stories-template-396.js 472 B 0 B
assets/js/chunk-web-stories-template-398.js 9.39 kB 0 B
assets/js/chunk-web-stories-template-4.js 507 B -1 B (0%)
assets/js/chunk-web-stories-template-40.js 550 B +1 B (0%)
assets/js/chunk-web-stories-template-400.js 495 B +1 B (0%)
assets/js/chunk-web-stories-template-404.js 467 B 0 B
assets/js/chunk-web-stories-template-406.js 8.04 kB 0 B
assets/js/chunk-web-stories-template-408.js 524 B +1 B (0%)
assets/js/chunk-web-stories-template-412.js 496 B +1 B (0%)
assets/js/chunk-web-stories-template-414.js 9.57 kB 0 B
assets/js/chunk-web-stories-template-416.js 588 B 0 B
assets/js/chunk-web-stories-template-420.js 561 B 0 B
assets/js/chunk-web-stories-template-422.js 9.6 kB 0 B
assets/js/chunk-web-stories-template-424.js 545 B +1 B (0%)
assets/js/chunk-web-stories-template-428.js 518 B +1 B (0%)
assets/js/chunk-web-stories-template-430.js 5.35 kB 0 B
assets/js/chunk-web-stories-template-432.js 544 B 0 B
assets/js/chunk-web-stories-template-436.js 514 B 0 B
assets/js/chunk-web-stories-template-438.js 7.14 kB 0 B
assets/js/chunk-web-stories-template-44.js 521 B +1 B (0%)
assets/js/chunk-web-stories-template-440.js 568 B 0 B
assets/js/chunk-web-stories-template-444.js 539 B 0 B
assets/js/chunk-web-stories-template-446.js 6.22 kB 0 B
assets/js/chunk-web-stories-template-448.js 530 B 0 B
assets/js/chunk-web-stories-template-452.js 502 B 0 B
assets/js/chunk-web-stories-template-454.js 9.14 kB 0 B
assets/js/chunk-web-stories-template-456.js 522 B +1 B (0%)
assets/js/chunk-web-stories-template-46.js 8.92 kB +1 B (0%)
assets/js/chunk-web-stories-template-460.js 493 B 0 B
assets/js/chunk-web-stories-template-462.js 13.6 kB 0 B
assets/js/chunk-web-stories-template-464.js 551 B 0 B
assets/js/chunk-web-stories-template-468.js 521 B 0 B
assets/js/chunk-web-stories-template-470.js 5.27 kB 0 B
assets/js/chunk-web-stories-template-472.js 575 B 0 B
assets/js/chunk-web-stories-template-476.js 546 B -1 B (0%)
assets/js/chunk-web-stories-template-478.js 8.26 kB 0 B
assets/js/chunk-web-stories-template-48.js 558 B -1 B (0%)
assets/js/chunk-web-stories-template-480.js 501 B 0 B
assets/js/chunk-web-stories-template-484.js 473 B 0 B
assets/js/chunk-web-stories-template-486.js 8.51 kB -1 B (0%)
assets/js/chunk-web-stories-template-52.js 532 B 0 B
assets/js/chunk-web-stories-template-54.js 6.59 kB -1 B (0%)
assets/js/chunk-web-stories-template-56.js 556 B +2 B (0%)
assets/js/chunk-web-stories-template-6.js 10.4 kB 0 B
assets/js/chunk-web-stories-template-60.js 527 B 0 B
assets/js/chunk-web-stories-template-62.js 6.69 kB 0 B
assets/js/chunk-web-stories-template-64.js 565 B 0 B
assets/js/chunk-web-stories-template-68.js 536 B 0 B
assets/js/chunk-web-stories-template-70.js 7.94 kB 0 B
assets/js/chunk-web-stories-template-72.js 573 B 0 B
assets/js/chunk-web-stories-template-76.js 545 B 0 B
assets/js/chunk-web-stories-template-78.js 8.04 kB 0 B
assets/js/chunk-web-stories-template-8.js 532 B +1 B (0%)
assets/js/chunk-web-stories-template-80.js 525 B 0 B
assets/js/chunk-web-stories-template-84.js 495 B -1 B (0%)
assets/js/chunk-web-stories-template-86.js 6.54 kB 0 B
assets/js/chunk-web-stories-template-88.js 535 B 0 B
assets/js/chunk-web-stories-template-92.js 507 B 0 B
assets/js/chunk-web-stories-template-94.js 8 kB 0 B
assets/js/chunk-web-stories-template-96.js 493 B -1 B (0%)
assets/js/chunk-web-stories-textset-0.js 5.27 kB 0 B
assets/js/chunk-web-stories-textset-1.js 6.76 kB 0 B
assets/js/chunk-web-stories-textset-2.js 7.88 kB 0 B
assets/js/chunk-web-stories-textset-3.js 15.4 kB 0 B
assets/js/chunk-web-stories-textset-4.js 4.38 kB 0 B
assets/js/chunk-web-stories-textset-5.js 5.68 kB -1 B (0%)
assets/js/chunk-web-stories-textset-6.js 5.5 kB 0 B
assets/js/chunk-web-stories-textset-7.js 10.4 kB 0 B
assets/js/imgareaselect.js 4.14 kB 0 B
assets/js/lightbox.js 991 B 0 B
assets/js/tinymce-button.js 3.49 kB 0 B
assets/js/vendors-chunk-ffmpeg.js 5.61 kB -1 B (0%)
assets/js/vendors-chunk-getStoryPropsToSave-chunk-resize-observer-polyfill-wp-story-editor.js 2.55 kB 0 B
assets/js/vendors-chunk-getStoryPropsToSave-wp-story-editor.js 193 kB +2 B (0%)
assets/js/vendors-chunk-html-to-image.js 4.48 kB +2 B (0%)
assets/js/vendors-chunk-react-calendar.js 11.7 kB -1 B (0%)
assets/js/vendors-chunk-react-color.js 43.4 kB +6 B (0%)
assets/js/vendors-chunk-web-animations-js.js 14.6 kB 0 B
assets/js/vendors-wp-dashboard.js 94.2 kB -53 B (0%)
assets/js/web-stories-activation-notice.js 23.4 kB 0 B
assets/js/web-stories-block.js 19.4 kB 0 B
assets/js/web-stories-embed.js 493 B 0 B
assets/js/web-stories-widget.js 984 B 0 B
assets/js/wp-dashboard.js 116 kB -23 B (0%)

compressed-size-action

@miina
Copy link
Contributor

miina commented Oct 7, 2021

@barklund I'm getting this error currently:
Screenshot 2021-10-07 at 11 28 44

With the following REST response (might be since there were some API changes in #8513, I think, but not sure) (cc @spacedmonkey since you implemented the API part of trimming):

{"code":"rest_invalid_param","message":"Invalid parameter(s): media_source","data":{"status":400,"params":{"media_source":"media_source[0] is not of type integer."},"details":{"media_source":{"code":"rest_invalid_type","message":"media_source[0] is not of type integer.","data":{"param":"media_source[0]"}}}}}

Also, I wasn't able to test it yet due to the previous error but just wanted to confirm that the same video can be trimmed more than once and the initial video is always used. Part of the logic in the original PR you had questions about (in terms of necessity) was for ensuring that the original video is used for the second and third etc. trim as well. Would be good to add that case to the testing instructions as well (trimming the video more than once and ensuring the same origin video is always used).

@miina
Copy link
Contributor

miina commented Oct 7, 2021

I'm getting this error currently:

Looks like the PR works in the QA environment so it seems like the error is just happening locally.
However, re-trimming the same video more than one time doesn't seem to work as expected when testing in QA. Steps:

  1. Add a video
  2. Re-trim the video to very short.
  3. Now re-trim the video again to longer
  4. Click "Trim" again. See that the handles are still showing trimmed short as trimmed in step 2.

@spacedmonkey
Copy link
Contributor

With the following REST response (might be since there were some API changes in #8513, I think, but not sure) (cc @spacedmonkey since you implemented the API part of trimming):

I think this issue will be fixed in #9301. Do you have the unsplash plugin installed out of interest?

@miina
Copy link
Contributor

miina commented Oct 7, 2021

I think this issue will be fixed in #9301. Do you have the unsplash plugin installed out of interest?

Hm, I did have it installed and enabled, didn't even remember. After disabling it there's no error locally anymore.

@spacedmonkey
Copy link
Contributor

Seeing something weird. I trimmed a video to 1 second. Then retrimmed to 5 seconds. After the upload is complete, I am still seeing the 1 second video when I play it.

Screen.Recording.2021-10-07.at.13.35.46.mov

Am I missing something here?

@miina
Copy link
Contributor

miina commented Oct 7, 2021

Seeing something weird. I trimmed a video to 1 second. Then retrimmed to 5 seconds. After the upload is complete, I am still seeing the 1 second video when I play it.

@spacedmonkey This is the same bug as reported here: #9315 (comment)

@barklund
Copy link
Contributor Author

barklund commented Oct 7, 2021

Seeing something weird. I trimmed a video to 1 second. Then retrimmed to 5 seconds. After the upload is complete, I am still seeing the 1 second video when I play it.

@spacedmonkey This is the same bug as reported here: #9315 (comment)

I'm looking into this now. There's definitely a bug here somewhere, probably something trivial.

if (!resource) {
return;
}
const lengthInSeconds = Math.round(endOffset / 1000 - startOffset / 1000);
trimExistingVideo({
resource: {
...resource,
// Preserve the id of the source resource even though we might be trimming from a third resource
id: element.resource.id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this a little more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a bit messy, but we need both IDs in the media processing function.

This ID here is the resource from which to copy the information over to the new element. This is considered the source for all data except the actual raw video. It is used in updateExistingElements many times. It is also the element that is temporarily marked as being "trimmed", though in effect it is not necessarily this element's video that is being trimmed.

The other ID listed a few lines below, trimSourceId, is to be considered the ID of the resource of the raw video, that is to be processed into a new video. It is used as the original key in the trim data for the newly create resource.

I would be good to clean this up a bit more, but I'm not really sure how to do that...

Copy link
Contributor

@spacedmonkey spacedmonkey Oct 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different naming might be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reorganized it a bit in 9afe07f - does that make it clearer? I separate it between the resource and the canvas resource. The former is the actual resource where working on, where the canvas resource is the element on the canvas that should be cloned into a new element with the resulting video.

Comment on lines +123 to +126
actions.getMediaById = useCallback(
(mediaId) => getMediaById(mediaId, media),
[getMediaById, media]
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sayedtaqui Flagging will need to taken in account for #9318

@spacedmonkey
Copy link
Contributor

What if you do this?

  • Trim 1 minute to 30 seconds.
  • Mute new 30 second video.
  • Retrim video to 45 seconds.

Would the 45 second video be muted? Should it be trimmed?

@swissspidy
Copy link
Collaborator

What if you do this?

  • Trim 1 minute to 30 seconds.
  • Mute new 30 second video.
  • Retrim video to 45 seconds.

Would the 45 second video be muted? Should it be trimmed?

Good question!

Sounds like a product question that is best resolved in a follow-up ticket.

As a user I would expect it to be still muted. And if it was optimized before, it should be still be optimized. Everything else would be super confusing.

The question is how we can achieve this? Sounds like we'd need to refactor the media upload queue and perhaps even useFFmpeg quite a bit to basically do trimming & muting in one step... Hence best done in a follow-up.

@barklund
Copy link
Contributor Author

barklund commented Oct 8, 2021

What if you do this?

  • Trim 1 minute to 30 seconds.
  • Mute new 30 second video.
  • Retrim video to 45 seconds.

Would the 45 second video be muted? Should it be trimmed?

Yeah, I was thinking about that too somewhere along the way.

All of this would be trivial if we moved all video transcoding to a "rendering" step just before publishing/updating, but that's not where we are right now. In our current setup, this is a bit tricky.

But let's file that as a follow-up ticket.

Copy link
Contributor

@miina miina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

One potential improvement:
If the user is trying to re-trim the video to the same length that the original video is, perhaps there's no need to create a new video and just the old video can be used? E.g. the user re-trims a 30s video to 5s and then back to 30s, currently it creates a new 30s video.

@barklund
Copy link
Contributor Author

barklund commented Oct 8, 2021

LGTM!

One potential improvement: If the user is trying to re-trim the video to the same length that the original video is, perhaps there's no need to create a new video and just the old video can be used? E.g. the user re-trims a 30s video to 5s and then back to 30s, currently it creates a new 30s video.

Yes, in general if you create a trimmed video, of which we already have an identical copy in the library, it would make sense to re-use that rather than make a new one.

But your example is of course even more simple, that if you want to return to the original, we rather than reuse said original instead just make a duplicate, which is pretty stupid.

I'll file as a follow-up.

@barklund
Copy link
Contributor Author

barklund commented Oct 8, 2021

@swissspidy, what do you say about either caching the API response for the get media request here or making a very lightweight API request for just the video source URL, as I think that's the only thing we need here?

Currently, the loading time on my setup is about 0.5-1.0 seconds, which is pretty long to wait every time I press to re-trim a video. Or is it just my local virtual environment, that's slow?

I'd file it as a follow-up enhancement, but not sure how to best file it, as I don't know what would be the recommended path forward?

@swissspidy
Copy link
Collaborator

@barklund If you only need the source URL and nothing else, you can use the ?_fields parameter to only fetch the fields you'd like. e.g. /wp-json/wp/v2/media/123456?_fields=source_url

@swissspidy swissspidy changed the title Added video re-trimming feature Video: Allow re-trimming of already trimmed video Oct 10, 2021
@swissspidy swissspidy merged commit 8884048 into main Oct 10, 2021
@swissspidy swissspidy deleted the add/8892-retrimming-alt branch October 10, 2021 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Re-trimming a video
4 participants