Server-side generated video with custom texture - Where to start? - php

I am working on a project in which a user can upload an image and then after uploading the image, a video is generated and then displayed, containing the image which was uploaded as some sort of texture/mask. (Like they do in Elf Yourself).
The original video should contain some sort of placeholder for the image to allow it to move around and be transformed on a matrix.
I'm not really sure where to start off or how I should even call such a merging/blending process in the first place.
A few requirements I've came up with so far:
- The server runs PHP
- I am able to use GD, Imagick and FFMPEG
Regards

Related

Laravel Progressive Image using Image intervention

I want to know how to apply progressive image in my website.
I'm using Image intervention. I search some way to apply image intervention
but I did not understand. Like
$img = Image::make('public/foo.png');
$img->interlace();
the original image and image that interlace don't have difference.
Can anyone help me to understand progressive image and how to apply it using image itervention in my website?
As you can see in this illustration:
Interlacing (also known as interleaving) is a method of encoding a bitmap image such that a person who has partially received it sees a degraded copy of the entire image.
...
For example: Interlaced GIF is a GIF image that seems to arrive on your display like an image coming through a slowly opening Venetian blind. A fuzzy outline of an image is gradually replaced by seven successive waves of bit streams that fill in the missing lines until the image arrives at its full resolution.
~ Interlacing (bitmaps) on Wikipedia
In another word, you won't see any visual difference between two images unless you try to load them with a low-speed connection within a modern web browser.
(See: Firefox DevTools has now a network throttling tool to simulate slow connections)
And BTW, your code was correct. I guess you were just trying to see a difference between interlaced and non-interlaced images which you will not be able to as long as they are not huge and they'll load fast.
For better understanding:
Videos of SCTP vs TCP in progressive vs non-progressive

Insert Image into MP4 video by PHP

I would like to insert still images into a mp4 sequence by PHP on server side, where the position of the placed image would move, for example I'd place an image into a photo frame with chroma-key color (or specified coordinates) in a room and the position of this photo frame would move in the video (if possible..). Much similar to Facebook's "Friends Day" Video. See this example link.
Is there any class or function that would allow me to do so?
Check-ed out this previous question but seemed inconclusive? Inserting an image inside a video at particular position via PHP and a video extension
Thanks in advance for your help!
You're gunna need more than PHP. You need to understand some things about pixel programming and its sub-category : computer vision.
Before I show you the reality check, let's assume the task is really as simple as to just "...Insert still images into a mp4 sequence by PHP". What would you need?
Try PHP :
If you prepare your input footage to have something like a green colour box where image should be inserted then you can consider this PHP method for replacing the green pixels with user photo.
You will have to do this for every single frame. To get video broken down to single frame PNGs try a tool like FFmpeg...
Try FFmpeg :
First have FFmpeg installed on your server (there's even a FFmpeg to PHP connection, ie: send commands and receive the result). This will be used to extract from source, overlay images and later encode the new output video. You can see this answer for overlaying images at specific positions.
In the snippet below, two input images are specified (vid_frame1.png is a video grab which needs an image to be inserted, over_image1.png is the to-be-overlaid image). overlay=75:200 means position overlay image at 75px across (x) and 200px down (y).
ffmpeg -i vid_frame1.png -i over_image1.png -filter_complex "[0:v][1:v] overlay=75:200" new_frame1.png
As you can see, you have to specify the position so in a moving video (where placement position will change over time) you need to keep track of expected image position in each frame. In a 24 FPS video that means a possible 24 unique positions per second which might get tedious. You would run the above command 24 times, each time changing the overlayposition.
note : If you install FFmpeg and use it with PHP then you could also do a stdinput / stdoutput process. This means you can output directly to video file instead of outputting "edited frame" PNGs. The video is generated as your program runs and when it's finish, there's a complete video file. This is too long to explain but you can information about it.
The reality check...
What you're talking about is called "dynamic video". You need a system in place to handle tasks like pixel tracking, perspective distortion and motion blur amongst others. This system would be a server based app (made using Java? or C#?). Here is one example of a dynamic editing tool. Also try coding something like this distortion tool (found here) so if we take that green block idea, now you simply find the four corners of green block in source video frame and position those distort points to each corner and you have persective distortion etc. For motion blur via PHP (I never tried that but) there is Google search...

Inserting an image inside a video at particular position via PHP and a video extension

What I am trying to do is, placing a small static image on inside a video clip at server side, by making use of PHP.
For example, in TV news, you might see the culprit's photo at a corner when the anchor describes about a crime incident.
I've tried doing some research. And found the ffmpeg-php extension for PHP. When going through the docs, I couldn't find any ready made methods or classes that would insert a picture at a particular position if we pass the x and y positions like in GD.
But there is a ffmpeg_frame object available and I think it could be used to fetch frames one by one as an image. And we would do the insertion of our required image inside this using the GD functions. After insertion of the image in all the frames, we would generate the video using these frames. That's my idea. But that extension's docs doesn't reveal anything about creating the video from frames. Only talks about creating animate GIFs !
Would it be a big load for PHP by using the above way of inserting image in each frame and then generating the video from it(if it is possible) ?
Or are there any better ways available to do this insertion process. I mean any other better extensions or video libraries available ?
The aim is to insert an image in a video, which would be at a particular position through out the video.
Thanks in advance.

Is it possible to run AfterEffects on a server to render videos on the fly with dynamic images?

I'm trying to figure out if this is possible:
web server running PHP collects a number of images from user input
web server takes those images, runs AfterEffects which uses the images instead of placeholders in a template video to create a personalised video for the user
web server makes the video available for download to the user.
Cheers,
Mark.
This would be mighty complex, but I think it might be possible. Here's how I think the process might go down:
Make your After Effects project, importing some placeholder images. Save the project.
Client uploads images. Those images need to be converted to the same image filetype (PNG, JPEG, TIFF, whatever) as your placeholder images, renamed to the same name as your placeholder images, and placed in the same directory as the placeholder images that were referenced in your After Effects project.
Run After Effects from the command line using aerender. More info on that here.
Render to a public directory and give the link to the client.
Delete the client's uploaded images to make room for the next client.
Heres where things would get tricky:
I don't think it's feasible to edit the After Effects project file, so I think the client would be limited to the exact number of images you made in your template. Any more would not appear in the rendered movie, and any less would give a media offline error. I do not think it is possible to have After Effects import media via a script.
Yes. It is possible, our stack is fairly involved. We are doing it at my startup, lumin8.me. Doable but complex, yet fun :)

How to resize linked images dynamically in PHP?

On my site I have given an option to user to choose thier profile image
Type link of an image
Image is a url link, and first I want it to resize to 400x300 (image's original size doesn't matter), and then display it on my web page.
Something like below:
<img src="http://mywebsite.com/resize.php?image=http://someotherurl.com/upload/image2.jpg&width=400&height=300" />
anyone knows this kind of script, please tell me how to solve this issue.
Thanks
A recent post:
https://stackoverflow.com/questions/1302464/php-image-resize-my-upload-script
has some code and comments that may give you some pointers. Otherwise may I suggest
http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php.
Good luck!
If you have the GD extenstion, you can use imagecopyresampled (the documentation also features some examples). However, if the image to be resized is large and there is a low memory limit on your server, you may run out of memory.
I don't have ready to use source code, but it should look like:
Load image pointed by image parameter into object of ImageMagick (or other graphics library).
Resize it.
Send content to output stream.
Optionally you could:
Check if loaded file is image (plus other validation checks).
Save resized image on disk and serve it from disk next time (if you do it often).
Check docs of you favorite graphics library used in PHP for details.
Good luck!
Use the Class called - class.upload.php.
Find it at: PHP Classes
We use it at all times in many of our work.
The name is deceptive but actually it is an uploader as well as image processor. It has a very big list of functionality for resizing images, adding text to images, converting formats, etc. etc.
There is sample code which shows how to read an Image from server, modify it and finally send it directly to browser without having to create a temp file on server.
HTH

Categories