0
所以,我对于视频上传到我的节点服务器以下节点代码:节点JS&videogular加载视频使用节点
var fs = require('fs');
var videoExtensions = ['mp4','flv', 'mov'];
//Media object
function Media(file, targetDirectory) {
this.file = file;
this.targetDir = targetDirectory;
}
Media.prototype.isVideo = function() {
return this.file.mimetype.indexOf('video') >= 0;
};
Media.prototype.getName = function() {
return this.file.originalname.substr(0, this.file.originalname.indexOf('.'))
};
router.route('/moduleUpload')
.post(function (request, response) {
var media = new Media(request.files.file, '../user_resources/module/'+request.body.module_id+'/');
if(!fs.existsSync('../user_resources/module/'+request.body.module_id+'/')){
fs.mkdirSync('../user_resources/module/'+request.body.module_id+'/', 0766, function(err){
if(err){
console.log(err);
response.send("ERROR! Can't make the directory! \n"); // echo the result back
}
});
}
convertVideos(media);
response.status(200).json('user_resources/module/' + request.body.module_id + '/' + request.files.file.name);
});
function convertVideos (media){
var ffmpeg = require('fluent-ffmpeg');
videoExtensions.forEach(function(extension){
var proc = new ffmpeg({source: media.file.path, nolog: false})
.withVideoCodec('libx264')
.withVideoBitrate(800)
.withAudioCodec('libvo_aacenc')
.withAudioBitrate('128k')
.withAudioChannels(2)
.toFormat(extension)
.saveToFile(media.targetDir+media.getName()+'.'+extension,
function (retcode, error) {
console.log('file has been converted succesfully');
});
});
}
现在,而不是使用直接路径加载视频我希望使用节点加载它
但是我不太知道如何做到这
使用直接的路径,我会做这样的事情:
$scope.videos.push(
{
sources: [
{src: $sce.trustAsResourceUrl($scope.component.video_mp4_path), type: "video/mp4"}
]
}
其中video_mp4_path变量将是视频的直接路径,即:myproject/resources/video.mp4
但是不知何故,我需要调用节点而不是即时路径。
正如我所说的我不是很清楚如何做到这一点可能有人点我在正确的方向
这是上传我需要下载文件并将其插入到视频 –
@MarcRasmussen - 抱歉,误读。添加了代码以响应您的角度应用与服务器的视频列表。 – Mick
将上述代码串流的视频,所以我不使用直接路径,而是使用nodejs流视频播放器 –