Video Recording from Browser using Flash, PHP, Red5 - php

I wish to build an application using which I can record video (along with audio) and also audio (only audio preferably in mp3 format).
From some research I did, I found I need a client app in flash or flex, a RTMP Server (RED5 preferable as its free)
This is the code which I used to get cam working flash.
var camera:Camera = Camera.getCamera();
var video:Video = new Video();
video.attachCamera(camera);
addChild(video);
The problem is, I don't know how to send the stream to RED5.
Also, what do I need to do so that I can store the video according to the user. The website I am creating is in PHP/MySQL and need to have their own videos and audios recorded. I love the way facebook has integrated Video Recording.

Check this: http://www.actionscript.org/resources/articles/615/2/Getting-started-with-red5-server/Page2.html
It explains how to connect and use RED5 and gives you an example.

Here's the exact AS3 code for publishing video from Flash to a media server like Red5, Wowza or AMS:
//init vars
public var nc:NetConnection;
public var ns:NetStream;
//net connection to media server
nc = new NetConnection();
nc.connect("rtmp://yourmediaserver/oflaDemo/instance");
//net stream through which the recording data is sent
ns = new NetStream(nc)
//attach cam and mic to net stream
ns.attachCamera(Camera.getCamera())
ns.attachAudio(Microphone.getMicrophone())
//send the data to the media server
ns.publish("streamName","record");
For just audio comment the ns.attachAudio line .
Flash Player can't encode mp3 sound (it can decode). You'll get sound encoded with NellyMoser ASAO. Speex is also an option. See this answer for more details.
oflaDemo is a Red5 app that supports video recording that's shipped with Red5.
For a (commercial) Flash/HTML video recording solution that supports Red5 and PHP you should check out https://hdfvr.com.
Also, what do I need to do so that I can store the video according to the user.
Just execute a PHP script (from the Flash client) that saves the info in the database. You can use POST or GET to send the video data and sessions or cookies to retrieve the user data.

var video:Video;
var camera:Camera = Camera.getCamera();
camera.addEventListener(ActivityEvent.ACTIVITY, active);
video = new Video();
video.attachCamera(camera);
function active(event:Event):void
{
addChild(video);
camera.removeEventListener(ActivityEvent.ACTIVITY, active);
}

Related

How can I save an image received from a Webhook? (WhatsApp API)

So, I'm starting to understand a bit more of WhatsApp API and all the messages that my number received are sent to my server via Webhook. The text messages are fine, but I'm struggling with the media messages.
When the user sends an image for example, Facebook's Webhook only sends me the mime_type and the sha256 of the image.
Can anyone please guide me the steps of what I need to do?
Do I need to convert it to base64, and then write the file in my server? Do I need to use a specific function? Do I need to use another programming language that's not PHP?
I'm totally lost on this one.
The way to do this, as pointed out by #CBroe is to use the media endpoints.
Assuming message is the message from the Webhook
// Get the image information, including the download link
$image_url_handle = fopen("https://graph.facebook.com/v13.0/" . $message->id);
$image_url = "";
// Read all of the data before parsing
while (!feof($image_url_handle)) {
$image_url .= fread($image_url_handle);
}
// Close the stream
fclose(image_url_handle);
// Get the url from the image information
$image_url = json_decode($image_url)->url;
// Start a request to the download URL.
$image_stream = fopen($image_url);
Note: There is no error handling or frameworks, though this should work most of the time

giving access token to file in cloud storage using PHP [duplicate]

I'm able to upload a file to my firebase storage bucket via nodejs using the firebase-admin but when I go to the firebase UI I cannot open the file. I noticed that uploaded files via firebase UI will have an access token automatically generated but no for files uploaded via nodejs.
I already tried several things like setting metadata with downloadtokens and making the file public after it is uploaded. None has worked.
How can I generate the access token via API call rather than having to go to hi and click generate token for each uploaded file?
Full answer as of July 2020:
It is possible to generate a uuid and use it as a token when uploading a file to Firebase Cloud Storage (aka Google Cloud Storage)
First import this package:
const uuidv4 = require('uuid/v4');
or
const { v4: uuidv4 } = require('uuid');
Then, generate a unique id before uploading the file:
const uuid = uuidv4();
Finally, upload your file:
The most important is to embed
metadata: { firebaseStorageDownloadTokens: uuid, }
in the metadata field of upload function
await admin.storage().bucket().upload(filePath, {
destination: thumbFilePathForUpload,
metadata: {
metadata: {
firebaseStorageDownloadTokens: uuid,
}
},
});
In order to check if it worked, click on the newly uploaded file directly from Firebase Console, you should have a blue, clickable link along your file. You can also find the access token under File Location, right under the preview.
For instance:
I use the below command and it is working perfectly
const uuidv4 = require('uuid/v4');
const uuid = uuidv4();
metadata: { firebaseStorageDownloadTokens: uuid }
To clarify #Rawan-25's answer further, what you want is:
bucket.upload(filename, {
destination,
metadata: {
metadata :{
firebaseStorageDownloadTokens: uuidv4(),
}
},
})
This is per this Github issue.
It's currently not possible to generate an access token with the Firebase Admin SDK. You'll have to do it using one of the client SDKs with the getDownloadUrl method on the StorageReference object. The token is only really intended for use with Firebase client apps.
However, the fact that you can't load a preview in the Firebase console for files uploaded with the Admin SDK is a known issue, and not the way that the console was intended to work. The Firebase team knows about this, but you should still file a bug report anyway with Firebase support to know them know you are impacted by the issue.
after an extensive search I managed to get the answer through a reddit post that referred to another stack overflow post lol.
Please take a look at answer #2! Get Download URL from file uploaded with Cloud Functions for Firebase

Make google drive fmt stream map stream links works when load on server

When I attempt to access video links on my google drive via my server, using via fmt map, they are not working on the client side because of ip tracking.
I have researched all stackoverfow similar topics but there is no solution.
you can check this for reference :
https://www.digitalocean.com/community/questions/google-get-video-fmt-stream-map
I know it's all about ip adresse so how some people make this works ?
Regards.
This answer is not the final solution but it can hopefully bring some new info.
I have tried two ways already. One PHP from the site you suggested and one Javascript.
PHP gives me a link that has similar parameters as a working link that I got from browser developer tools so it could work. The problem as you say is IP because through PHP there is IP of the server and the rest is generated upon that. So I have tried to stream it through PHP to use the same IP address by readfile()
/*code follows code from the link*/
$gdrive = new gdrive;
$drive_link = 'https://drive.google.com/open?id=videoID';
$gdrive->getLink($drive_link);
$theFile = json_decode( $gdrive->getSources() , true );
//echo $theFile[0]['src'];
/*header('Content-Type: video/mp4');
header('Accept-Ranges: bytes');
header('Content-Length:'.filesize($theFile[0]['src']));*/
readfile($theFile[0]['src']);
but it doesn't work anyway. I don't know if that is right way or if there is another google security obstacle?
From Javascript, when trying to request docs.google.com/get_video_info or drive.google.com/file/d/videoID/view, it gives me a CORS Cross-Origin error (in Web Console) that I can't resolve.

Streaming video from server to mobile using base64

We are building an application that deals with images and videos and the privacy requirement is high , where users are not allowed to gain access to the images and videos at all time (privacy option) ,
therefore we went with the option of having a php api that clients request the file and the api returns a base64 encoded response that the client decode and display ,that is for image side ,as for video we are having a trouble finding the right logic .
does VideoView in android helps me achieve this ?
does the api needs to send the video in chunks instead of one large base64 ?
is base64 even right for this requirement ,noting that user should not have direct access to the file at all times .
php api function :
function viewFile($data) {
$file = file_get_contents($data['file_path']);
$mime = mime_content_type($data['file_path']);
return ['status' => 200, 'file' => ['mime' => $mime, 'base64' => base64_encode($file)]];
}
Security with base64? That does not exist. I made a text (in Portuguese) that might help you. Read.
I do not recommend using a very large base64. The server will have a lot of load, the download will be slow, etc.
The ideal is to divide it into smaller pieces. For this you can use bento4 e o ExoPlayer.
For images, I recommend using Cipher. More information for Android and More information for PHP
I made this code to encrypt images. It is already quite old, but I think I can help you enteder this issue.
https://github.com/valdeirpsr/estudo-openssl/blob/master/library/OpensslEncrypt/OpensslEncrypt.php

must i have FMS to publish a stream from my camera?

i am building an live streaming website and i am use
1- FMS
2- Apache webserver
i have made the subcriber and i works well .
but i need to build the publisher to allow users to broadcast thier stream from thier cameras.
i have tested a publisher which was build using actionscript and it didn't work untill i have installed the fms on my localhost , but i need a publisher which any user can use in his web browser .
my publisher :
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
connection = new NetConnection();
connection.connect("rtmp:/live");
connection.addEventListener(NetStatusEvent.NET_STATUS,onConnected);
}
private function setupVideo():void
{
//setting up outgoing devices
camera = Camera.getCamera();
camera.setMode(640,480,30);
mic = Microphone.getMicrophone();
//setting up outgoing Stream
outStream = new NetStream(connection);
outStream.attachCamera(camera);
outStream.attachAudio(mic);
outStream.publish("EraMaX-Live");
//setting up outgoing video & attach outgoing devices
outVideo = new Video();
outVideo.attachCamera(camera);
//setting up incomming Stream
inStream = new NetStream(connection);
inStream.play("EraMaX-Live");
//setting up incomming video & attach incoming Stream
inVideo = new Video();
inVideo.attachNetStream(inStream);
//wrap video object
outVideoWrapper = new UIComponent();
outVideoWrapper.addChild(outVideo);
addElement(outVideoWrapper);
inVideoWrapper = new UIComponent();
inVideoWrapper.addChild(inVideo);
addElement(inVideoWrapper);
inVideoWrapper.move(400,0);
//setting up incomming video
}
so my question must i have FMS to publish a stream from my camera to my website ?
If you want to stream live video, you need a streaming server. Not definitely FMS, you also can use Red5, Wowza, or even open source solutions such as RTMPD or RTMPLite.

Categories