是否可以下载文件的特定部分? [英] Is it possible to download a specific part of a file?

查看:35
本文介绍了是否可以下载文件的特定部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想下载一个文件,但我不需要所有文件.是否可以跳过文件的前 1/4 部分并下载其余部分?

So I want to download a file, but I dont need all of it. Is it possible that I skip the first 1/4 of the file and download the rest?

我已经尝试过 python youtube-dl 包,我认为有一些相关的标志可能有用.但我不知道如何使用它们

I have tried the python youtube-dl package, there are some relevant flags that I think might work. But I dont know how to use them

所以无论如何,如果有人以前尝试过,您介意分享一下您的做法吗?或者甚至有可能吗?

So anyway, if anyone has attempted this before, would you mind sharing how you go about it. Or is it even possible?

推荐答案

有人建议使用 ffmpeg 和 youtube-dl 的组合来做你想做的事情:

Someone has suggested using a combination of ffmpeg and youtube-dl to do exactly what you want here:

https://askubuntu.com/questions/970629/how-to-download-a-portion-of-a-video-with-youtube-dl-or-something-else

这是一个建议的示例,原样来自上面的链接.如您所见,youtube-dl 仅用于获取视频 URL,ffmpeg 可以完成这项工作:

Here is a suggested example, as is, from the link above. As you can see, youtube-dl is only used to fetch the video URL, ffmpeg does the job:

ffmpeg -i $(youtube-dl -f 22 --get-url https://www.youtube.com/watch?v=ZbZSe6N_BXs) -ss 00:00:10 -t 00:00:30 -c:v copy -c:a copy happy.mp4

以类似方式启动 ffmpeg 并下载一段 3 小时视频的示例:

Example that launches ffmpeg in a similar way and downloads a piece of a 3h video:

import youtube_dl, subprocess

URL = "https://www.youtube.com/watch?v=eyU3bRy2x44"
FROM = "00:00:15"
TO = "00:00:25"
TARGET = "demo.mp4"

with youtube_dl.YoutubeDL({'format': 'best'}) as ydl:
    result = ydl.extract_info(URL, download=False)
    video = result['entries'][0] if 'entries' in result else result

url = video['url']
subprocess.call('ffmpeg -i "%s" -ss %s -t %s -c:v copy -c:a copy "%s"' % (url, FROM, TO, TARGET))

这篇关于是否可以下载文件的特定部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆