Sunday, September 3, 2017

Downloading Segmented Vimeo Videos

Have blogged about this before. Downloading Vimeo videos used to be a matter of clicking the download button that appears below the video player. Download disabled? No problem. Just plug in the Vimeo video URL to the many online video downloaders that supposedly can do the job. youtube-dl might even do the job.

Lately, I've noticed that a lot of the premium Vimeo videos are chopped up and sent to the client browser as m4s segments. I've written a blog post before re: downloading Brightcove videos, but this one is totally different. As far as I can tell, there is no main mp4 link that can be obtained. You'll have to save all these m4s segments and somehow piece them all together to get the complete video.

Did a bit of research, and looks like someone already wrote a python script that should be able to do this. Installation is pretty simple:

  1. Install additional requirements using pip install.
  2. Install ffmpeg.
  3. Extract the master URL (http://...master.json?base64_init=1) and plug into the vimeo-download command.

vimeo-download.py script should probably work fine with a Windows python and ffmpeg installation, but I decided to go with Linux. See my blog post about Linux VM. As mentioned, python comes pre-installed in Linux Mint, but not pip.

sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get install python-pip

Once pip in installed, it's time to install the additional required packages:

pip install -r requirements.txt

Got an error message saying: ImportError: No module named setuptools

sudo pip install -U setuptools

Next error message is about OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/asn1crypto'

sudo pip install -r requirements.txt

Which now works fine until we get to:

build/temp.linux-x86_64-2.7/_openssl.c:12:24: fatal error: pyconfig.h: No such file or directory compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

This requires additional packages to be installed.

sudo apt-get install python-dev

Then we get: build/temp.linux-x86_64-2.7/_openssl.c:434:30: fatal error: openssl/opensslv.h: No such file or directory

sudo apt-get install build-essential libssl-dev libffi-dev

All the packages from requirements.txt were installed after these additional commands.

Next up is the ffmpeg installation. As instructed in the installation notes, tried to set mc3man/trusty-media as a PPA repository. Got the below error message, which indicates xenial (Linux Mint 18) is too new and not supported by the PPA.

This PPA does not support xenial

Why not just get ffmpeg from the official repositories? Which is what I did.

sudo apt-get install ffmpeg

Next question: How do we extract the master URL of a segmented vimeo video?

  1. Enable Developer Tools (Ctrl + Shift + I)
  2. Go to the Network tab.
  3. Play the Vimeo video.
  4. Look for the entry which says master.json?base64_init=1
  5. Right-click and Copy link address

Usage syntax is:
python vimeo-download.py --url "http://...master.json?base64_init=1" --output <optional_name>

From that master.json URL, we get the base video and audio URLs, and all the segments are retrieved. The v.mp4 video file and the a.mp3 audio file are muxed using ffmpeg to come up with the final vimeo video in the output directory.

1 comment:

  1. hey i downloaded invidownloader for downloading segmented it worked fine but many times the video timing is lost i dont know why this is happening infact its all okay until i try to convert the mp4s file into mp4

    ReplyDelete