I am working in a node.js project in which I need to upload .mp4 files to amazon s3.
I have 2 questions:
QUES 1: I have uploaded the mp4 file into a private type bucket lets say the name of bucket is 'videobucket'. To view the video in the browser, I created it's signed URL.
My question is:
Is the signed ULR that am getting, different from the STREAMED URL. IF yes, what steps should I perform for generating the streamed URL?
QUES 2: I need to create the thumbnail of the video that I am going to upload to amazon s3. How can I do it in node.js?
I am newbie in amazon and node.
Thank you all in advance!
The code that I have written to upload the files is as follows:
var file = req.files.video;
var fileName = new Date().getTime() + "_" + file.originalname;
fs.readFile(file.path, function(err, data) {
if (err) throw err;
var s3bucket = new AWS.S3({
params: {
Bucket: 'myvideos'
}
});
s3bucket.createBucket(function() {
var params = {
Key: fileName, //file.name doesn't exist as a property
Body: data,
ContentType: file.type,
};
s3bucket.upload(params, function(err, data) {
fs.unlink(file.path, function(err) {
if (err) {
console.error(err);
}
});
if (err) {
res.status(500).send(err);
} else { console.log("file uploaded"); }
});
});
});
Nodejs is very good to streaming audio and video, but nodejs is a new technology, so it's don't have a lot of softwares yet.
You can use Amazon S3 with Amazon CloudFront to host videos for on-demand viewing in a secure and scalable way. Video on demand (VOD) streaming means that your video content is stored on a server and viewers can watch it at any time.
S3 is a more professional image hosting choice; it offers tighter control along with a full set of developer APIs.
This is the answer of my first question. I found this after so many hours of search in google.
Uploading Media and JW Playerfiles to an Amazon S3 Bucket:
Step1: Download the player from the Features page on the JW Player website. Then extract the contents of the .zip file. Step2: SignIn to aws management console https://console.aws.amazon.com/s3/
Step3: Create a public type bucket Step4: Select the bucket and click on Upload Step5: Upload the below files into the bucket
jwplayer.flash.swf
jwplayer.html5.js
jwplayer.js and
Your .mp4 and .flv media files
Set permission to public
Creating CloudFront Web and RTMP Distributions
To configure CloudFront to stream a media file, you need a CloudFront web distribution for the JW Player files and an HTML file, and an RTMP distribution for the media file.
Steps
Step1: Open cloud front console https://console.aws.amazon.com/cloudfront/
Step2: Create distribution
Step3: On the first page of the Create Distribution Wizard, accept the default selection, RTMP, and click Continue.
Step4: On the second page of the wizard, click in the Origin Domain Name field, and select the Amazon S3 bucket that you created in the procedure To upload media and JW Player files to an Amazon S3 bucket. If you have a lot of Amazon S3 buckets, you can type the first few characters of the bucket name to filter the list.
Step5: Create Distribution
Step6: After CloudFront creates your distribution, the value of the Status column for your distribution will change from InProgress to Deployed. This should take less than 15 minutes.
The domain name that CloudFront assigns to your distribution appears in the list of distributions. The domain name also appears on the Distribution Settings page for a selected distribution.)
EMBEDDING RTMP MEDIA:
<div id='mediaplayer'>This text will be replaced</div>
<script type="text/javascript">
jwplayer('mediaplayer').setup({
'id': 'playerID',
'width': '720',
'height': '480',
'file': 'rtmp://s1cxpk7od1m10r.cloudfront.net/cfx/st/your_streaming_file.mp4',
'primary':'flash',
'autostart' : 'true',
});
</script>
The answer to the second part : you can use fluent-ffmpeg to extract video thumbnails https://github.com/fluent-ffmpeg/node-fluent-ffmpeg
var ffmpeg = require('fluent-ffmpeg');
var screenshot = new ffmpeg({source:'./1.mp4'}) // put in the source path of the video
.withSize('200x200')
.takeScreenshots({count:1,timemarks:['50%'],filename:"screenshot.png",folder:"./"});
For newer versions of ffmpeg:
ffmpeg('/path/to/video.avi')
.screenshots({
timestamps: ['50%'],
filename: 'screenshot.png',
folder: '/path/to/output',
size: '200x200'
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With