-
Notifications
You must be signed in to change notification settings - Fork 883
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
How to cut (trim
) video and audio with timestamps
#184
Comments
I have the same issue with start=, end= arguments |
I also have the same issue with start and end kwargs. As stated about end seems to be working, but start does not select the start of the video. I tried some of the earlier release, with no success. |
Update: I tried this with ffmpeg directly, and it doesn't work either. Looks like this library isn't the issue. As a workaround you can use the "start+duration" method. Some people discussing here: https://stackoverflow.com/questions/18444194/cutting-the-videos-based-on-start-and-end-time-using-ffmpeg |
I found a solution: (
input_vid
.trim (start_frame = 10000, end_frame = 10600)
.setpts ('PTS-STARTPTS')
.output (f'output.mp4')
.run()
)
The above output, however, does not have any audio attached to the output. This is due to ffmpeg's behavior, as has been discussed in detail in #26 , #208 and shown in this example. Mysteriously the vid = (
input_vid
.trim(start = 100, end = 160)
.setpts('PTS-STARTPTS')
)
aud = (
input_vid
.filter_('atrim', start = 100, end = 160)
.filter_('asetpts', 'PTS-STARTPTS')
)
joined = ffmpeg.concat(vid, aud, v=1, a=1)
output = ffmpeg.output(joined[0], joined[1], 'out.mp4')
output.run() |
trim
) video and audio with timestamps
@rsomani95 's snippet gave me the error below. TypeError: Expected string index (e.g. 'a'); got 0 In my case, adding def trim(input_path, output_path, start=30, end=60):
input_stream = ffmpeg.input(input_path)
vid = (
input_stream.video
.trim(start=start, end=end)
.setpts('PTS-STARTPTS')
)
aud = (
input_stream.audio
.filter_('atrim', start=start, end=end)
.filter_('asetpts', 'PTS-STARTPTS')
)
joined = ffmpeg.concat(vid, aud, v=1, a=1).node
output = ffmpeg.output(joined[0], joined[1], output_path)
output.run() |
Did you need Mysteriously, adding |
Removing |
it couldn't wok on Google colab |
@TanvirMobasshir see this #184 (comment) |
Great work!
I'm confused as to how to solve this problem, but am sure that it is solvable with a little guidance. I'm trying to trim a clip that should be
600/25(fps) = 24s
long.However, the output gives me a file that is
10600 frames
long, where the first10000 frames
don't play in some video players while they skip over in others. Nevertheless, what I wish for is a clip that is only600 frames
long.Additionally, my output files do not have any audio. This isn't an issue though, but a solution would be a nice bonus.
Thanks!
The text was updated successfully, but these errors were encountered: