-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
is it possible to download only desired time interval? #4821
Comments
At the moment, there is no such functionality. This is quite complicated internally, because we need to find a table of which times correspond to which byte intervals, interpret that table, download the partial file (that's actually the easy part), and then reassemble the whole shebang so that the headers are valid. |
You could try to let youtube-dl only generate the url and then feed that url to ffmpeg. SET /P url=
FOR /F %%A IN ('youtube-dl.exe -g %url%') DO (
ffmpeg.exe -ss 00:41:55 -i "%%A" -c copy -t 00:03:00 output.mp4
) |
Thank You.. !! |
+1 Long Twitch videos can sometimes be upwards of 5 GiB or more, and if you just want watch a small part of them, you have to wait a long time to be able to even watch that. |
@corone17 This command downloads a full video to /tmp files or somewhere, loads it for cutting OR it naturally retrieves a part of remote file? |
@corone17 This didn't work with long video: http://www.youtube.com/watch?v=eyU3bRy2x44 :-( |
@alexmatveev I didn't actually test it 3 months ago, so you could try and run the following as a batch-file: @ECHO off
:Input
ECHO.
SET url=
ECHO Enter Youtube-url:
SET /P url=
IF "%url%" EQU "" GOTO End
IF "%url: =%" NEQ "%url%" GOTO Input
ECHO Enter start time (in seconds, or in hh:mm:ss[.xxx] form):
SET /P start=
ECHO Enter duration (in seconds, or in hh:mm:ss[.xxx] form):
SET /P dur=
ECHO.
FOR /F "delims==" %%A IN ('youtube-dl.exe --no-warnings --get-filename "%url%"') DO SET filename=%%A
FOR /F %%B IN ('youtube-dl.exe -g "%url%"') DO (
ffmpeg.exe -hide_banner -ss "%start%" -i "%%B" -c copy -t "%dur%" "%filename%"
)
GOTO Input
:End If you make sure youtube-dl.exe and ffmpeg.exe are in the same directory, then this will work fine for your 3hour fireplace video :p. |
Closing as a duplicate of #622. |
@Reino17 Could you please write a shell script? (for linux users) |
I'm sorry, but I'm not a Linux user. I have very little experience with Linux's shell script. |
@Reino17 Ok, still thanks |
i finally made an account because I'm desperate for a clipconverter dot cc alternative because they've recently made impossible restrictions to what they could download. Really hope you find a way :( |
I know this is a somewhat difficult feature, but it is a great one to add. Right now, I want to grab a 2 minute clip from a 3 gig video file! I'd love to be able to give you the -ss and -t flags like ffmpeg. |
youtube-dl does have a --postprocessor-args command-line parameter. Example: youtube-dl --postprocessor-args "-ss 00:13:00.00 -t 00:04:00.00" https://youtu.be/... where -ss indicates start position (13 minutes in) and -t indicates new length (4 minutes) of output video. Just tried it with a 47-minute video that had about 4 hours of nothing on the end of it. I used --postprocessor-args "-t 00:47:00.0" and it worked fine. |
I know that this question is long but you can do it using this command:
You need to have the |
Yes, but that would mean I will have to download what could be a 1 gb file to get a few seconds |
I was primarily giving a command-line-friendly solution. If your download speed is too slow, then what alternative would you suggest for downloading a smaller chunk of the original? |
teocci's command works perfectly and doesn't download the entire video; I just tried it. Inspired by it and Reino17's script, I hacked together a non-interactive Bash function that downloads a range of any youtube-dl downloadable video, provided you have ffmpeg. You can put it in you download-clip() {
# $1: url or Youtube video id
# $2: starting time, in seconds, or in hh:mm:ss[.xxx] form
# $3: duration, in seconds, or in hh:mm:ss[.xxx] form
# $4: format, as accepted by youtube-dl (default: best)
# other args are passed directly to youtube-dl; eg, -r 40K
local fmt=${4:-best}
local url="$(youtube-dl --get-url "$1" -f $fmt ${@:5})"
local filename="$(youtube-dl --get-filename "$1" ${@:5})"
ffmpeg -loglevel warning -hide_banner \
-ss $2 -i "$url" -c copy -t $3 "$filename"
printf "Saved to: %s\n" "$filename"
# based on Reino17's and teocci's comments in https://github.com/rg3/youtube-dl/issues/4821
} A few catches:
|
Very nice. |
Thanks, Reino17.
I preferred I also forgot to add the format option to the get-filename command, because it can change the extension. As I can't find a documentation for the urls-options order except what you mentioned, I will change the code to put the urls at the end. Thanks. I also added the For quieter output, you can remove download-clip() {
# $1: url or Youtube video id
# $2: starting time, in seconds, or in hh:mm:ss[.xxx] form
# $3: duration, in seconds, or in hh:mm:ss[.xxx] form
# $4: format, as accepted by youtube-dl (default: best)
# other args are passed directly to youtube-dl; eg, -r 40K
local fmt=${4:-best}
local url="$(youtube-dl -g -f $fmt ${@:5} "$1")"
local filename="$(youtube-dl --get-filename -f $fmt ${@:5} "$1")"
ffmpeg -loglevel warning -hide_banner -stats \
-ss $2 -i "$url" -c copy -t $3 "$filename"
printf "Saved to: %s\n" "$filename"
# based on Reino17's and teocci's comments in https://github.com/rg3/youtube-dl/issues/4821
} |
That's a great step. Do you think you could convert it to Python and submit it as a patch? |
@noureddin do you know a way of doing same but with support for resuming? |
@satnatantas, if ffmpeg can resume a paused transcoding, it can be done. But unfortunately I couldn't find a way to do that reliably; the best way I was able to find is to pause using |
any progress ? |
its 2020 now 5 year passed since that comment. Is that feature available now to trim the youtube video and dounload the specific parts.Please reply ASAP |
I made the following batch file to make it easier for me to download all or part of video, select desired streams, and extract/convert audio. Hopefully, others will find it helpful as well.
|
Does this download only the part of the video? |
Yes, if you choose the ffmpeg option.
But, please note the comment:
REM Using ffmpeg to download part of a video will only save time when downloading a very small chunk.
For example, that option saved me time when downloading the first five minutes of a two hour video. But selecting something like 15 minutes actually took longer than the youtube-dl method. YMMV. Do some trial and error testing to figure out the threshold for the video chunks you're downloading.
I'd be interested to hear your results.
|
Just for anyone reading this issue who wants a quick way to do it on Linux, you can use
|
This downloads full video and then crops it. A little off topic. |
No it doesn't... try it yourself if you don't believe me. It's the same solution that @Reino17 provided, but adapted for linux |
Thanks! What would be the format of time? START_TIME = 2:30 (for 2 minutes 30 seconds)? |
You can read the ffmpeg docs to see other ways of specifying time, but hh:mm:ss works (00:02:30) |
My doubt is caused by the fact that youtube-dl doesn't get the start timestamp. This means that the video will download from the beginning. In any case, the above command does not work:
|
That isn't what I wrote though... Also, you'll need to make sure youtube-dl doesn't automatically select separate formats for audio and video |
My bad, I copied wrong line from my bash history, so here is correct one:
I just thought that one of the commands might work differently on Mac and Linux. It doesn't seem to have this error under Linux, but it looks like the video is downloading from the start. I'll continue to try with other videos. |
When I run this I get
|
Don't forget to put quotes around your Since there seems to be some confusion here about how this works and because some people assume that this will download the whole video first and only split afterwards, let me explain how this works. The
The |
With quotes around {} does not work either, same message |
@AtomicNess123 what's your operating system and your version of xargs? |
MacOS Catalina 10.15.7 |
@AtomicNess123 it seems that some versions of freebsd xargs do not have the https://www.freebsd.org/cgi/man.cgi?query=xargs&manpath=FreeBSD+4.0-RELEASE Maybe you can fix your problem by getting a more modern version of xargs. |
I have been trying to find how to update xargs on my MAC, unsucessfully. |
@AtomicNess123 depending on what you want to download, maybe you don't need xargs at all. Try running the first part, the
Which (in my case) outputs:
I can then plug that into ffmpeg directly instead of the
|
This worked out almost perfectly, except for the "FINISH_TIME" that should be "DURATION" since the flag "-t" is being used. Maybe that's why @AlexanderMatveev was assuming the video was being downloaded in full as he was telling the program to download more than one hour of video. The other issue I have is not getting audio from the stream selected by youtube-dl. Investigating now either how to merge or how the select a stream with audio Thanks @rhysperry111 EDIT: This is how I did it: 2 - Then run the original code but add |
A cross-platform yt-dl solution involving |
I want to download small part of a video which is 2 hours long and 1080p. How can i do that with youtube-dl?
The text was updated successfully, but these errors were encountered: