YouTube 视频 ID 的最大长度是多少? [英] What's the maximum length of a youtube video id?

查看:43
本文介绍了YouTube 视频 ID 的最大长度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个显示 youtube 视频的应用程序.我想将视频 ID 存储在数据库中,但是因为会有很多视频,我想尽量减少所需的空间,所以有人知道 youtube 上视频 ID 的最大长度吗?

I'm developing an application that displays youtube videos. I want to store the video id's in a database, but because there are going to be a lot of videos, I want to minimize the required space, so does anyone know the maximum length of a video id on youtube?

推荐答案

几乎肯定会保持在 11 个字符.单个字符来自一组 64 种可能性 (A-Za-z0-9_-).

It's almost certainly going to stay at 11 characters. The individual characters come from a set of 64 possibilities (A-Za-z0-9_-).

64^11 略大于 2^64.(10 个字符是不够的.)所以基本上每个 youtube ID 实际上是一个 64 位数字.我很怀疑他们永远不会用完这些.

64^11 is somewhat more than 2^64. (10 characters would not be enough.) So basically each youtube ID is actually a 64bit number. And I quite doubt they will ever run out of those.

如果您想节省数据库空间,理论上可以将 ID 转换为 64 位数字,然后再将其转换回来.但是您需要知道 youtube 是如何进行转换的,因此它不切实际.(由于 64^11 大于 2^64,您无法存储所有可能性,因此您需要知道哪些是不可能的,而 google 没有说.)

If you want to save space in your database you could theoretically convert the IDs to 64bit numbers then convert them back later. But you would need to know how youtube does the conversion so it's not practical. (Since 64^11 is more than 2^64 you can't store all possibilities, so you need to know which ones are impossible and google doesn't say.)

存储所有可能性需要 66 位.所以你实际上可以存储一个 64 位数字加上一个 2 位数字,这样可以节省一些空间.或者更实际地存储 9 个 8 位值 - 尽管将其存储为文本,但每条记录只会节省 2 个字节,因此可能不值得.

It takes 66 bits to store all possibilities. So you could actually store a 64bit number plus a 2 bit number and save some space that way. Or more practically store 9 8bit values - you would save only 2 bytes per record though over storing it as text, so it's probably not worth it.

这篇关于YouTube 视频 ID 的最大长度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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