One advantage of using the Shotstack API is how seamlessly it scales this process without worrying about the rendering infrastructure. The final rendered MP3 is ready to be hosted or transferred to your application: Converting a list of MP4 videos to MP3 audioĪs you can see, creating an MP3 file from an MP4 video is very simple. If everything ran successfully, you should now have the URL of the final video, similar to the one in the example below. If an error occurs, the status will return as failed. Re-run the status.php script every 4-5 seconds until the status is done and a URL is returned. try with the render id returned from the mp4-to-mp3.php script. The Shotstack SDK converts our objects to JSON and adds our key to the request header before sending everything to the API. > setOutput ( $output ) Send the edit for processing and renderingįinally, let's use the API to send the edit for processing and rendering. The preview resolution only affects video so we can use the lowest resolution available. To convert to an MP3, let's set the file type using setFormat to mp3 and setResolution to preview. $timeline -> setTracks ( ) Configuring the final output Let's add the videoClip in the track and then place the track on to the timeline. Tracks on the timeline allow us to layer clips over each other. Now, let's create a timeline, like a container for multiple video clips that play over time. > setStart ( 0 ) Adding a video clip to the timeline The variable videoClip below will add the 'videoAsset' to the timeline at second 0 using setStart and play for 25 seconds using setLength: $videoClip = new Clip ( ) We can customize attributes such as length and start time. Next, add the code below to create a VideoAsset using the video URL: $videoAsset = new VideoAsset ( ) Ī clip is used to manage different asset types such as video, images and audio files. You can replace it with your own video url if you have one. We will use the following transcription example video from this AWS transcription tutorial. The video must be hosted somewhere accessible via a public or signed URL. A timeline acts as a container for multiple tracks, each of which contains multiple clips that play over time. The Shotstack API follows many desktop editing software principles, such as using a timeline, tracks, and clips. Replace 'your_key_here' with the sandbox API key provided, which is free for testing and development. $client = new EditApi ( null, $config ) > setApiKey ( 'x-api-key', 'your_key_here' ) // use the API key issued to you $config = Configuration :: getDefaultConfiguration ( ) Next, set up the client with the API URL and key. Let's import the required SDK modules for the project from the Shotstack SDK, as shown below: Set up the API client Then, select the file and begin editing it. Use your preferred IDE or text editor for this tutorial to create a PHP script called mp4-to-mp3.php. Install the Shotstack PHP video editor SDK using the following command: composer require shotstack/shotstack-sdk-php Converting a single MP4 file to MP3 Make a PHP script that converts an MP4 to an MP3 The recommended way to use install the SDK is using composer. PHP should be available on your path, you can check it is installed correctly using php -version. You need to have PHP 7.3+ and the Shotstack SDK for PHP. However, Shotstack's rendering infrastructure simplifies the development and scaling of media applications. Editing and creating videos on a large scale takes a lot of resources and can take hours. Shotstack is a cloud-based video editing API. This tutorial will teach you how to do this, providing a great starting point for creating your own media app. With Shotstack and PHP, you can create a simple web application to upload an MP4 video file and convert it into an MP3 file programmatically. An easier solution is to use Shotstack, a cloud-based video editing API, and PHP, a popular scripting language. Sometimes, you may need to extract the audio from an MP4 file and convert it into an MP3 file for compatibility or editing purposes.įFmpeg is a powerful tool to do this, but it can be intimidating for non-technical users. MP4 and MP3 are popular audio and video file formats.
0 Comments
Leave a Reply. |