Using a CDN for user Image and Video uploads - php

I am planning on using a CDN for user image and video uploads for my site. The only problem is I cannot upload direct to a CDN as I need to process and manipulate the image and videos before they get stored on my server using GD Image Library and FFMPEG.
What is the best way for me to get the capacity and delivery benefit of a CDN but still be able to process the files that get uploaded there?
I want the videos and images to be available for review after upload almost instantly. I don't want the user to have to experience a double upload time (sent to my server, then sent to CDN).
The only solution I can think of is storing a temporary version of the files on my server and then behind the scenes sending a copy to the CDN. Once the upload to the CDN is complete all paths to the file would be switch to the CDN instead of my server. Does this make sense?

Use a CDN that provides an API.
A great CDN service in the UK and USA is Rackspace. They provide an API for a lot of programming languages such as PHP.

You may have to spend processing power but from then on bandwidth can be on the CDNs back. You can also outsource video encoding with a service like panda stream

Related

Handling large file uploads and sending to API

I'm stuck wondering what the best solution is to handling large file uploads and sending them to a third-party API. Any pointers on what would be a good solution would be very welcome. Thank you in advance.
The end goal is to send video files to this API - https://docs.bunny.net/reference/manage-videos#video_uploadvideo. The complication is that the files are often large - up to 5GB in size.
I have an existing website built in PHP7 that runs on a LAMP setup on Amazon Lightsail and I want to add a feature for users to upload video files.
Currently I'm uploading the files directly to Amazon S3 using a pre-signed URL. This part is working fine.
But I need to send the files to the API mentioned above. This is where I get stuck!
I think there's two options to explore - (1) find a way to upload directly to the API and skip the S3 upload or (2) continue with uploading to S3 first and then transfer to the API. But I'm not sure if option 1 is even possible or how to do option 2!
With option 1, I'm wondering if there's a way to upload the files from the users directly to the API. If I do this using the regular HTML form upload, then the files are stored temporarily on my server before I can use cURL through PHP to transfer them to the API. This is really time consuming and feels very inefficient. But I don't know how else to send the files to the API without them first being on my server. Maybe there's an option here that I don't know about!
With option 2, I can already upload large files directly to S3 with pre-signed URLs and this process seems to run fine. But I don't know how I would then send the file from S3 to the API. I can use an S3 trigger on new files. But when I looked at Lambda, they have a tiny file size limit. Because my site is hosted on Lightsail, I noticed they have a container option. But I don't know if that can be used for this purpose and if so, how.
Basically, I'm not sure what solution is best, nor how to proceed with that. And maybe there's an option 3 that I'm not aware of!
I would welcome your input.
Many thanks in advance.

How to upload videos to Vimeo programmatically in PHP?

I have a an input for uploading videos on my site. The videos get uploaded on my server and then it is presented via video tag. But as you can imagine, the user uploads only one video with one extension (e.g. mp4), in that case I can't use that video in all the browsers. So, maybe what I could do is upload the same video to vimeo (via their api) and then host this video via "iframe code" or something. My question is: Is it even possible? And is it a good idea?
This is definitely possible, you can and should use the Vimeo API: https://developer.vimeo.com/api
Also it is pretty a good idea, because Vimeo is suited to transcoding and serving millions of videos every day and by definition is way more stable than your own video service. Unless you are facing the legal requirement to host the video on your own server, it is probably better to use external CDN (like Vimeo) for it.
But you will have to use cURL or some other HTTP requests library to access the functions and perform tasks. Check it out here: http://php.net/manual/en/book.curl.php

Flash player disable download of flv files

We have a video streaming website, and the company decided to make some of the video content paid.
So we built an authenticated area and finalized all the payment issues, and now we are down to the security part.
The videos have a .flv extension, and I want restrict their downloads.
I know restriction is kind of impossible for flash players and flv files, it's a client side issue, but the least to say I want to make it as long and complicated as possible for the videos to download.
There are alot of options for video download so I want a to disable the
Realplayer download,
Chrome and firefox extensions,
and any other way that can easily access the video.
My other option (very hard to go through again) to re-encode the original .mov to some other format that can be a bit more secure.
I am using the open source JWplayer.
I made it with 2 servers in one network. One of them is public server. I wrote small php media proxy, so the links to the media files go trough it (you can now to check where are requests from). The data server (with the media files) is with internal ip(not public) and if someone tries to get the media file directly, will fail.
I think this is good solution if you have own servers.
If you have only one server media proxy is good enough, but can be easly traced from man with good knoledge.

How to reliably upload large files through a web interface

Background:
I have a site that deals with large video files (sports videos). The site allows users to upload any source file, but most of the videos come from DVDs. I am currently using a modified version of jumploader to encode and upload files to the webserver with an HTTP request. The jumploader is a java client, and looking at my webstats, only about 75% of my users have java installed.
What I want:
I have looked for a flash based uploader that transfers a byte stream to a server. Byte streams would be ideal so I can capture partial videos for failed uploads. I have also looked for flash-based ftp clients, but I haven't found anything promising. There are some flash-based uploaders that post via HTTP, and I'm considering this. I do not want to use a simple file post. Some upload methods also put the full file into memory first, and this obviously is not an option for me.
Does anyone have experience uploading large (up to 2-3GB) files to a web (or ftp) server from a web frontend (PHP) with any reliability?
as a flash based solution you can use swfupload, which is widely used because you can display a progress bar. It sends answers back to you which you can read with JavaScript.
We decided upon using Transloadit, a service which is specialised in uploading and encoding video files. You can even track whether a download was aborted by closing the browser window, it has realtime encoding and supports multiple formats. Moreover your files are stored at Amazon S3 so you can easily stream them with AWS CloudFront and JWPlayer or Flowplayer.
See also zencoder.
Cheers

How to record voice files using PHP, FLASH

I am developing an application where I need to record voice(for those who does not have a webcam so they can use only microphone to record voice) or video(those who have a a webcam - like laptop or external) files and save them on server, thereafter save the file name and logged in users id on database for later access.
I know I need to use some sort of flash app for this. But is there any free one which could server this purpose or even if there are paid ones which could serve this purpose that would be great. I tried google but may be I was not being able to go after the proper term or something, I could not succeed finding a proper solution for this.
Please, help me out!
You can do that simply using jRecorder, a jQuery plugin. You don't even need a Flash Media Server or RED server. JRecorder is same as jPlayer, you can use jQuery and HTML to design your recorder and you don't even need Flash or Action script knowledge for this.
jRecorder uses 1 pix hidden swf file which manages all the recording / previewing and sending the file data (wav file) to a URL you defined (Where you can write code in PHP or Java to receive a POST file)
It is quite simple and tidy.
You can download this Plugin from:
http://www.sajithmr.me/jrecorder-jquery
I have same feature in our latest project, the client want to have video recording from webcam and the video appear in the user's profile page.
For the server, we implement the RED5 server. It need a Java virtual machine in your hosting. You can read the detail requirement and installation instruction in the website.
To handle recording, we develop our own flash application, because the client request a custom interface to match with the overall website interface. I don't know the detail, since we outsource it to a fellow flash developer. Maybe you can see follow this thread, the development of flash recording by JeroenW.
To play recorded video, you can use any flash video player that support playing rtmp video source. You cannot play the recorded flv file in RED5 directly, since the file lack of metadata required by the player. Serving the recorded file as rtmp is done by RED5.
In addition to red5 there is Adobe's own Flash Media server that allows you to record audio/video straight to the server.
Or if you feel geeky you might be able to put together your own solution for this using a socket connection to the server and decoding the stream yourself on the server side. You should be able capture the audio/video locally into memory and then feed the byte stream up to your own server application.
There are Open Source solutions but you will need an own server to run them.
There is no way to run these things from shared hosting except if your provider is really nice, and ready to install the necessary software.
I asked the same question a few weeks back, check out the answers.
This question when googling "How to record audio php" comes up first so here for anyone from the future.
A simple way to record audio with flash and save it with PHP:
https://github.com/clouddueling/SimpleRecorder
Record audio, post audio data to your choice of url.
You could try recordmp3online.com which has an SDK. The nice thing about this one, is that it doesn't need a third party server(ala Red5), and supports mobile devices that don't have flash installed.

Categories