I wasn’t sure where to post this, but here goes. If I download the same video two or more times using youtube-dl, each file is different. Does anyone know why?
Does it just get the video.file or does it include information like view count in the meta data for the file? That would change all the time.
Or is it possible that it is pulling from one of the many different servers for the video and they are all slightly different?
Is it always downloading at the same video and audio quality?
All good questions. The files are the same quality. All I’m left with ordinarily is the video file; however, there is an option “–write-info-json” which gives a little more info. I’m looking at those now. Just FYI, the view_count is the same in both files. I was thinking perhaps a timestamp, or some sort of watermark, or something…
How recent was the video released and what quality setting were you downloading?
I tend to notice this the most on things that are very recent (within the first several hours). That if the download does not complete and I try to resume the download the file size will be different, therefore corrupting the download. This may be that the video is still being processed and getting the closest setting that matches until it does.
I also suspect YouTube has some sort of progressive encoding in place, essentially encoding on the fly for certain video qualities.
Typically what I do to avoid this behavior from YouTube is to issue my youtube-dl command with the -e and -g flags to get the video url and title, then use a dedicated server with a better internet connection to download it with wget. That way I have a stable file size that I can download / resume as long as it takes to finish.
I first noticed this behaviour on L1 News videos which were new and maybe still being processed in some way. However, today I picked a random video which was uploaded in November 2019. Just for grins, I’m going to try it your way and see what happens.
It’s true YouTube constantly re-encodes with better algorithms. An older encode will not look as good as a more recent x264 based encode. SVT-VP9 is also incrementally improving and that’s what’s used for VP9.
There must be magic I don’t know to use “-g”. I did “youtube-dl -e…” and got the title. I then did “youtube-dl -g” to get a pathname. I then tried wget with that path (enclosed in double quotes). It pulled down a webm file, but it isn’t playable with vlc or mplayer. I tried converting it with ffmpeg and that failed.
My typical method looks like this
youtube-dl -e -g -f 18 "https://www.youtube.com/watch?v=yDgpBC7c1uY"
then on the my server
wget -O "filename.mp4" "source_url"
You can use the -F flag to get a list of the qualities and video formats available.
youtube-dl -F "https://www.youtube.com/watch?v=yDgpBC7c1uY"
The -f 18
in the first example is the format code that is returned from the -F
flag.
Be careful with bestvideo[ext=mp4]
because sometimes for 60fps videos it grabs 30fps instead.
Thanks. Those incantations worked. And for my first experiment, downloading the same video twice in a row (with a rename in between) gave me the same exact file.
In case anyone’s interested, I ended up going down this rathole because I found a file on one of my NAS boxes which appeared to have been silently damaged. Once a month, a script runs which uses cfv to do simple checksums on one system and then compares them to sums from the other system.
The damaged file was a video I’d downloaded from youtube. So I thought an easy check would be to download the file again and compare it to the other two to see which was good. Alas, the third file was different from the other two. So that was no help.
The silent damage happened again this month to a different file. So I’m considering how to proceed, but FreeNAS with ZFS is looking mighty good at the moment.
setting your youtube-dl command with the switch -f 18 is 360p
thats quite specific and not always available on all youtube videos so i think youtube-dl has a fall back format it downloads instead. For more consistent downloads perhaps try “best” or “worst” ??