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.

trim is not truly trimming duration, keeping stillframe before after

See original GitHub issue

i took trimming example and try to make use in app i am working on. its simple gui (pyqt5) to help me work do batch processing. graph / operations happening in following order Crop > trim > pad > drawtext > watermark i tried changing order by keeping trim in start and moving crop ahead as well. same result. previously i was doing all above via batch files separately, it works but i hate it, Earlier in my tests with batch file, i had noticed same issue as well. Stack OverFlow searches taught me that, adding -strict -2 before end helps. command in batch file looked like this ffmpeg -i %dtp% -ss %s% -strict -2 -t %t% %filepath%\%filename above line worked correctly in batch file. Q. how can i make use of that here if my triming funtion looks like below

def trim_video(input,ss=0,t=100):
    trimmed_out = (
        input
        .trim(start_frame=ss, end_frame=t)
    )
    return trimmed_out

thanks again for support

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

4reactions
bidspellscommented, Mar 11, 2020

Solved! I observed the same issue of the ‘still frames’. As ffmpeg-python is a wrapper the root cause lies in most cases in FFmpeg itself.

In this case, two additional filters are required:

  • in the video filter chain “setpts=PTS-STARTPTS”
  • in the audio filter chain “asetpts=PTS-STARTPTS”

ffmpeg: “Be aware that frames are taken from each input [video] in timestamp order, so it is a good idea to pass all overlay inputs through a setpts=PTS-STARTPTS filter to have them begin in the same zero timestamp, such as …”

Translating back to ffmpeg-python, this means you have to add the following calls to you filter chains. An respective API call is available for video (but not for audio):

.setpts('PTS-STARTPTS')

A generic filter call can be used in both cases:

.filter('setpts', expr='PTS-STARTPTS'))
.filter('asetpts', expr='PTS-STARTPTS'))

–Bid

2reactions
TTransmitcommented, Jun 2, 2019

I think the problem may be keyframes. You can use ss on the input to seek to the needed frame.

ffmpeg.input('video.mp4', ss=20, t=10)

Starts video.mp4 at 20 seconds and plays ten seconds of it without including a paused frame.

See: https://trac.ffmpeg.org/wiki/Seeking#Cuttingsmallsections

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to trim clips in Adobe Premiere Elements.
Right-click/ctrl-click in the gap in the Expert view timeline, and then click Delete And Close Gap. Retrieve frames in the Expert view timeline....
Read more >
The difference between trimming and cropping – Ming Thein
Additionally, even if you find something of interest in the frame after the fact, you might not have been fully aware of it...
Read more >
2 Methods to Trim Videos on Windows 10 for Free [2022 ...
The colored slider only shows the current frame and has no effect on trimming. To trim videos, simply select the area you wish...
Read more >
Trim your videos - YouTube Help - Google Support
This restriction does not apply to channels that are in the YouTube Partner Programme. Open the video editor. Open the video editor to...
Read more >
Trim a movie or clip in QuickTime Player on Mac - Apple Support
Drag the yellow handles in the trimming bar. The area outside of the yellow handles is the area to be trimmed. Tip: To...
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