question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trimming of video

See original GitHub issue

I have not found a way in the docs on how to trim the video down to a portion of the original (e.g. from x milliseconds to y milliseconds).

Seems to me that I could implement by creating a custom MediaSource and supplying it to the transform method.

Am I on the right track here or is there an already built in way that I am currently missing?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
izzytwoshedscommented, Nov 30, 2020
0reactions
grahamearleycommented, Aug 14, 2020

Made some more progress! Instead of making a custom decoder, I ended up adding new logic to the VideoTrackTranscoder’s resizeDecodedInputFrame() method.

This is the logic that method currently uses to render frames (see the file here):

decoder.releaseOutputFrame(tag, true);
renderer.renderFrame(null, frame.bufferInfo.presentationTimeUs * MILLISECONDS_IN_SECOND);

This logic assumes we want to render every frame in the video (the first line’s true parameter tells the decoder to render, and the second line performs the render). For trimming, there are frames we don’t want to render! I updated the logic to this:

long presentationTimeUs = frame.bufferInfo.presentationTimeUs;
boolean shouldRender = presentationTimeUs >= trimStartUs && presentationTimeUs <= trimEndUs;

decoder.releaseOutputFrame(tag, shouldRender);

if (shouldRender) {
    renderer.renderFrame(null, frame.bufferInfo.presentationTimeUs * MILLISECONDS_IN_SECOND);
}

And this gives us a precisely trimmed output!

I haven’t cleaned anything up into more presentable code, but maybe next week I’ll have some time to get a draft PR up. Right now, I’m hardcoding my trim start and end values in a few places, so I’ll need to make a single spot for those parameters to be set.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Free Video Trimmer: Cut Videos Online | Adobe Express
Trimming a video is when you remove footage from the beginning or end of clip, usually to bring the focus in to the...
Read more >
Video Trimmer - Cut Video Online for Free - MP4, AVI, MPG ...
Use our Online Video Trimmer to cut a fragment from any video! It supports any video format - MP4, AVI, 3GP, and many...
Read more >
Video Trimmer — Cut Video Online
Fast Video Cutting. The tool allows you to move the two markers to select the beginning and ending of your clip. It takes...
Read more >
Online Video Cutter - Cut, Trim & Crop Video for Free
Drag & drop your video files to cut, crop and trim. No account needed. ... With VEED you can cut and trim your...
Read more >
Online Video Trimmer — Trim and Cut Videos
The online video trimmer from Kapwing is the fastest way to cut a video to your desired duration. You can trim by dragging...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found