这是今天我发现的第二件我认为不可能的事情是真的。我获取了一个小型 MP4 视频文件 (86KB),然后将其编码为基于 64 的数据 URIsite http://dopiaza.org/tools/datauri/index.php。我做了一个简单的测试页面<video>
设置了 src 属性的元素:
`src="data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZj....
所以一串文本可以是一个视频,虽然我在我的驱动器上找不到50KB的视频文件,但我相信86KB的文件大小就足够了。你可以在这个上看到它Plunker http://plnkr.co/edit/nK4trpyRhgB4bETbr3kU?p=preview
从这里找到了这个article https://davidwalsh.name/convert-image-data-uri-javascript:
function getDataUri(url, callback) {
var image = new Image();
image.onload = function () {
var canvas = document.createElement('canvas');
canvas.width = this.naturalWidth; // or 'width' if you want a special/scaled size
canvas.height = this.naturalHeight; // or 'height' if you want a special/scaled size
canvas.getContext('2d').drawImage(this, 0, 0);
// Get raw image data
callback(canvas.toDataURL('image/png').replace(/^data:image\/(png|jpg);base64,/, ''));
// ... or get as Data URI
callback(canvas.toDataURL('image/png'));
};
image.src = url;
}
// Usage
getDataUri('/logo.png', function(dataUri) {
// Do whatever you'd like with the Data URI!
});
You can modify this script to use videos instead of images.