Downloading 360 Videos from YouTube (and playback in Linux)

by @edent | # # # # #

Inspired by this conversation on Mastodon

YouTube hosts 360 videos. Here’s one of mine, wandering through the Houses of Parliament. You can drag the video to see all around.

If you let YouTube-DL download the “best” version, you’ll end up with a video which looks like this:

An over-under video.

Each lens’ view has been horizontally stretched, and then stitched into an over/under view. This is in Google’s Equi-angular Cubemap format. Grim!

There are two options available to you to get the equirectangular version needed to playback easily on Linux

Easy Way

Running youtube-dl -F https://www.youtube.com/watch?v=... will show you all the formats available.

136          mp4        1280x720   720s 2325k , avc1.4d401f, 30fps, video only, 24.94MiB
248          webm       1920x960   1080s 2375k , vp9, 30fps, video only, 25.53MiB
137          mp4        1920x960   1080s 4127k , avc1.640028, 30fps, video only, 41.92MiB
18           mp4        640x360    360s  705k , avc1.42001E, 30fps, mp4a.40.2@ 96k (44100Hz), 7.63MiB
22           mp4        1280x720   720s 2514k , avc1.64001F, 30fps, mp4a.40.2@192k (44100Hz) (best)

I found that -f 22 worked. And there’s a way to test that!

If you run ffmpeg -hide_banner -i filename.mp4 then you should see this in the metadata:

Side data:
   stereo3d: 2D
   spherical: equirectangular (0.000000/0.000000/0.000000) 

That’s the magic which tells a video player that this is a spherical / 360 video.

If you play back the video in, say, the default Linux video player, it will look like this:

A distorted video.

It’s a weird view out of both lenses simultaneously. Yeuch!

But if you play it using VLC version 3 or above, you’ll be able to drag the video around.

There is a downside. This only gets the 720p version. If we want the full resolution version, we need a bit more trickery.

Hard Way

There’s a bug in YouTube which means YouTube-DL sometimes gets served up slightly weird formats. The fix is to pass a blank user agent:

youtube-dl --user-agent "" ...

Now, when you download the video, you’ll get the full resolution copy in equirectangular format. HORRAY! But without the correct metadata. BOO!

This is because ffmpeg strips out Side data. *sigh*

So, run this:

youtube-dl --user-agent "" -k https://www.youtube.com/watch?v=...

That tells YouTube-DL to keep the original video and audio separate. They need to be merged with the standard compliance mode to unofficial .

ffmpeg -i video.mp4 -i audio.m4a -c:v copy -strict unofficial spherical.mp4

Phew! Easy when you know how, eh?

Leave a Reply

Your email address will not be published. Required fields are marked *