Concatenate Videos with node.js in AWS Lambda - node.js

Im wondering if it's possible to merge (concatenate) two video clips into one with an AWS Lambda function using Node.js?
The dependency that I was going to use is ffmpeg (or fluent-ffmpeg), but from what I can tell, all the APIs use the actual file path, not the file variables. I download the actual video files from an S3 bucket so I can't use the path's... can I?
I haven't found a single example that uses file variables. If there's a better way to do this that Im not thinking of, feel free to share! Thanks for the help as always.

I found a way around it! All I needed to do was save the object body from the item I get from S3 to a file on the local Lambda file system. Not sure why I didn't think of this in the first place. I ended up doing
fs.writeFile("out.mp4", item.Body, (err) => {
if(err) console.log(err);
console.log("Body saved!")
});
Hopefully this answer helps someone that comes across a similar mental block in the future.

Related

Autodesk Forge: Industrial Construction Demo bucket not working

I have cloned the Industrial Construction Demo code https://github.com/petrbroz/forge-industrial-construction but I am having issues with the 'bucket-name'.
In the launch file you need to specify "FORGE_BUCKET": "" instead of the usual URN.
I have written the name of the bucket that contains my file but it does not work. I have tried debugging it but still no luck.
There is no exemplary bucket or files, so I would really like to know:
-What do I need to put in as the bucket name?
-What files need to be in the bucket?
-What file types?
-Any extra information to help me figure out why it isnt working.
Many thanks,
Poppy
My apologies, I haven't explained this in the code sample very well. The demo requires files in Forge to be named in a specific way. I have just updated the README with more details: https://github.com/petrbroz/forge-industrial-construction.

how to check if a file path in cloud storage is valid or not using cloud function?

so I am trying to download an image from firebase storage like this using cloud function
const bucket = storage.bucket("myApp.appspot.com")
const filePath = `eventPoster/${creatorID}/${eventID}.png`
await bucket.file(filePath).download({
destination: tmpFilePath
})
but the problem is, I can't ensure the image is always in the png format, it can also be jpeg or jpg
I will get error like this if I hard code it like that
Error: No such object: myApp.appspot.com/eventPoster/user1/ev123.png
so how to check if a path is valid or not or how to make a code that can work dynamically with other image extension ?
Posting as Community Wiki, because I based part of it in a comment and so other members of the Community can feel free to edit it.
As mentioned in the comments, you can use the method exists(), to check if a specific file exists in your bucket. This way, you will not an issue, in case the file doesn't exist when you are trying to return it. This would be the best way for you to check only for files existing, with the name based in the ids as you are basing your name structure.
Besides that, as clarified in this other post from the Community here, you can restrict the file types in your bucket in case you are using the POST method to upload files, otherwise, you won't be able - which can also, be an alternative. In case you are not using POST, as mentioned as well in this other post, you can try to construct a Cloud Function that will check for the file type before it uploads the file to the bucket, which would make your application only upload specific files.
In case you would like to check on how to upload files to Cloud Storage using Cloud Functions, you can check this tutorial here: How to upload using firebase cloud functions
Unfortunately, these seem to be the only available options right now, but I think they are a good start for you.
Let me know if the information helped you!
You can use the exists method on a file to check if your PNG is present or not. You can also change your code and use the getFiles() method. As you can see, you can put options, and one named "prefix". In your case you can have this
bucket.getFiles({
prefix: "eventPoster/${creatorID}/${eventID}"
}, <callback>);
Here you will list all the file with the prefix: PNG, JPEG and others. make your code smarter to leverage this dynamic answer

ElectronJS - adding folder to favorites [macOS]

I am wondering if there is a way to add a folder to Favorites using Node?
I've found this issue, but the solution does not work anymore.
Basically the file that I'm interested in is located in:
/Users/USER_NAME/Library/Application\ Support/com.apple.sharedfilelist
The thing is I do not know how to modify it...
You can use try os module. Very easy to use.
Here is an example:
const home = require("os").homedir(); // This will get your OS based Home directory
const dirToSave = `${home}/Desktop/output.csv`; // Now you can add file or folder to any tree directory of home directory.
fs.writeFile(`${dirToSave}`, {csvData}, function(err, stat) {
if (err) throw err;
console.log("file saved");
});
There is a file that you need to edit
You can edit the sidebar on Mac using the com.apple.sidebarlists.plist preference file. The items will be in the favoriteitems dictionary.
The items you see are all set to being AlwaysVisible. You need to edit that file to add your own file.
I will give some links that might help you.
About the com.apple.sidebarlists.plist file, http://www.thexlab.com/faqs/finder.html
Finding the com.apple.finder.plist, https://discussions.apple.com/thread/4122582
Another post, https://apple.stackexchange.com/questions/139305/how-can-i-add-new-folders-to-the-favorites-in-the-finder-sidebar
About editing a file in Electron
There are tutorials about how to edit files with Electron, you can start from this example,
https://ourcodeworld.com/articles/read/106/how-to-choose-read-save-delete-or-create-a-file-with-electron-framework
What I've done is I wrote a python script based on the resource that #Royson posted in this question's comments (click).
It's available under a gist:
https://gist.github.com/Ancinek/6d6e34791c5a8674275560ae118848c7
Currently possible to add/remove one file at a time.
I will be creating a binary for this so it can be run without the need to installing the pyobjc on the user's machine - will post the update soon after I find out how to actually do this.
Hope this helps somebody!

Saving the stream using Intel RealSense

I'm new to Intel RealSense. I want to learn how to save the color and depth streams to bitmap. I'm using C++ as my language. I have learned that there is a function ToBitmap(), but it can be used for C#.
So I wanted to know is there any method or any function that will help me in saving the streams.
Thanks in advance.
I'm also working my way through this, It seems that the only option is to do it manually. We need to get ImageData from PXCImage. The actual data is stored in ImageData.planes but I still don't understand how it's organized.
https://software.intel.com/en-us/articles/dipping-into-the-intel-realsense-raw-data-stream?language=en Here you can find example of getting depth data.
But I still have no idea what is pitches and how data inside planes is organized.
Here: https://software.intel.com/en-us/forums/intel-perceptual-computing-sdk/topic/332718 kind of backwards process is described.
I would be glad if you will be able to get some insight from this information.
And I obviously would be glad if you've discovered some insight you can share :).
UPD: Here is something that looks like what we need, I haven't worked with it yet, but it sheds some light on internal organization of planes[0] https://software.intel.com/en-us/forums/intel-perceptual-computing-sdk/topic/514663
UPD2: To add some completeness to the answer:
You then can create GDI+ image from data in ImageData:
auto colorData = PXCImage::ImageData();
if (image->AcquireAccess(PXCImage::ACCESS_READ, PXCImage::PIXEL_FORMAT_RGB24, &colorData) >= PXC_STATUS_NO_ERROR) {
auto colorInfo = image->QueryInfo();
auto colorPitch = colorData.pitches[0] / sizeof(pxcBYTE);
Gdiplus::Bitmap tBitMap(colorInfo.width, colorInfo.height, colorPitch, PixelFormat24bppRGB, baseColorAddress);
}
And Bitmap is subclass of Image (https://msdn.microsoft.com/en-us/library/windows/desktop/ms534462(v=vs.85).aspx). You can save Image to file in different formats.

Node fs.watch to read changes only

fs.watch('log-file', function(event, filename) {}); only returns the file name that was changed.
Is it possible to only get what was actually changed? I don't want to read the entire file, and rather want to know what was modified from my file (in my case, there is always addition to a log file. nothing ever gets erased).
It seems that you are looking to solve a similar problem to How to do `tail -f logfile.txt`-like processing in node.js?
As per the first response I would look into the the node-tail module.

Resources