How to download a clip of an YouTube video with pytube?

旧城冷巷雨未停 提交于 2021-02-20 05:24:05

问题


I've been trying to download certain portions of YouTube video. The long way is to download the video then extract the certain portion of it. But when it comes to a big dataset with long videos, the method is costly.

The code works. But downloads the entire video instead of the certain portion.

from pytube import YouTube

YouTube('https://www.youtube.com/embed/yf8Ub90OWFM?start=15&end=25').streams.first().download()

Expected result: 10 second video in the time interval of 15-25 seconds.


回答1:


According to issue Support to download partial videos of PyTube it is not currently possible.

Therefore you might use one of Python videos post processing library, eg moviepy:

from moviepy.editor import *

video = VideoFileClip("myHolidays.mp4").subclip(50,60)
result.write_videofile("myHolidays_edited.webm",fps=25)

Or get the command-line ffmpeg tool:

ffmpeg -ss (start time) -i (direct video link) -t (duration needed) -c:v copy -c:a copy (destination file)


来源:https://stackoverflow.com/questions/56017234/how-to-download-a-clip-of-an-youtube-video-with-pytube

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!