Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Youtube Video Download & Trim
import pafy
if __name__ == '__main__':
video_url = ''
video =
print(video.title, video.duration)
best = video.getbest()
import ffmpeg #
def trim(input_path, output_path, start=30, end=60):
input_stream = ffmpeg.input(input_path)
vid = (
.trim(start=start, end=end)
aud = (
.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)
if __name__ == '__main__':
input_path = './HOZIN | KING OF POP | Judge showcase.mp4'
output_path = './hozin_short.mp4'
trim(input_path, output_path, start=30, end=60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.