Search code examples
phpvideobase64decodingvideo-encoding

How to convert base64 string to video in PHP?


I have a base64 encoded string which my frontend team has provided me with.The string is a video which was encoded using base64. I want to convert that back into a video file using Php.

I am currently just using the following to decode the string but I don't know how to proceed further.

$decoded = base64_decode ($encoded_string);

There seems to be a way to convert images from string using imagecreatefromstring() function, but I could not find a way to convert it into a video.

Thank you


Solution

  • you should know the video file type. you can decode to original format

    $fp=file_put_contents('sample.mp4',base64_decode($encoded_string,true));