Linking PHP audio and video uploads to FFMPEG on a linux server - php

I host a site on a Linux server that I built with php where I am able to upload audio files in one section and video files to another.
Each section uses php to upload a single audio file and a single video file. Each upload is assigned a unique filename so they can be viewed separately on an individual page where the uploader can post comments about their audio or video.
I want to be able to allow musicians and performers in the local area display their work. The site works, but large video files do not upload and my audio player only plays a few formats, and I like to convert them all to mp3's.
I installed ffmpeg on my linux server to help me with this and am able to connect to it with my terminal. My question is how do I get ffmpeg to interface with my uploaded php files.
For example, as the user uploads an audio file, can I have ffmpeg convert it while it's uploading, or do I need to set up a temporary folder for uploads, store it there, then have ffmpeg compress the file, convert it to a specific format and save it in another folder?
I would prefer to have it compress and change the format while it's uploading so as not to use server space, but if this is not the way ffmpeg works, then I don't have a choice. Any help would be appreciated.

It is NOT possible to transcode while uploading. But, it is possible to transcode all your videos to mp4 files and all your audio files to mp3 files using ffmpeg command which you can call from your PHP code using exec statements.
H264 BP is the video codec which is almost universal and supports most of the platforms devices, browsers, players etc. AAC is the best audio codec to use for online streaming.
So, convert all your videos with following exec statementin PHP.
exec("ffmpeg -i INPUT.avi -r 25 -b:v 1M -pass 1 -c:v libx264 -profile:v baseline -c:a aac -strict experimental -b:a 192k OUTPUT.mp4");
And convert all your audios with following exec statement in PHP.
exec("ffmpeg -i INPUT.wav -c:a aac -strict experimental -b:a 192k OUTPUT.mp3");

I once had the opportunity to work on such task around 4 years back. I still remember how I did this.
I installed ffmpeg and it should work using commands as well on shell. I used exec library of php to execute ffmpeg commands which converted video files into desired format i.e mp4. You better check out exec and learn ffmpeg command to convert file into desired format. Hope it helps

Related

How to reduce video size with php script?

i have an PHP Application where registered users upload their video. Here i want to reduce file size of video while uploading.
Is there any solution with PHP language?
I don't know about php but i can suggest you to upload to a web server that supports FFMPEG Project
so by specifying video resolution you can reduce file size
ffmpeg -i <inputfilename> -s 640x480 -b 512k -vcodec mpeg1video -acodec copy
hope this will help you

playing video while encoding with ffmpeg

in my Webapplication the user should be able to upload his own videos (either format).
I am using ffmpeg to encode the video to .mp4 and .flv using the command:
ffmpeg -i uservid.whatever output.mp4 output.flv
while ffmpeg encodes the video, it's loaded in the flowplayer on the users-page. But flowplayer always says "file not found" cause ffmpeg is not yet finish with encoding.
Is there a possibility to load the video in a certain player even if it is not yet completly encoded? maybe there is a ffmpeg option?
Thanks
FLV yes, mp4 no. with flv you can have ffmpeg write to stdout and do whatever you need to with the output. mp4 requires a frame index (moov) that is not known until the entire file is encoded. flv encodes the information in every frame.

Generate image from a swf file issue

I am trying to generate first frame of a swf as a thumbnail image so the user can see it before they open the swf file.
1.Using FFMpeg
ffmpeg -i movie.swf -f image2 -vcodec png movie%d.png
using command line with ffmpeg to generate images. the above command will
give me errors saying
[swf # 0x17937a0] Compressed SWF format not supported
2.Using swftools
Their website provide a tar file to download however, I only have the command line access in the server so I won't be able to install the tools.
I need to use server side technology because I have hundreds of swf files.
p7zip e movie.swf
ffmpeg -i movie~.swf movie.png
Most SWF files are compressed to save space, similar to a .tar.gz or .zip. So before you can use it with FFmpeg, you need to extract or decompress the file.
p7zip is a
command line program
that can extract SWF.

Convert audio files from various formats to mp3 and ogg

I'm setting up a podcast. For cross-browser support, I currently need to upload a mp3 file and an ogg file. I'd like to simplify that process to uploading one of many audio files, that converts on the server into one mp3 and one ogg, then drops it into a folder. Is this possible?
Thanks!
For your purpose you need to use ffmpeg for the conversion and eventually ffmpeg-php.
Like:
<?php
system ('ffmpeg -i /tmp/a.wav -ar 22050 /tmp/a.mp2', $retval); // took from the ffmpeg documentation. it's just an example
// add " > /dev/null &" if you want to execute in background
?>

Create Thumbnail from Office Files, Videos, Images with PHP

My company is building an internal app where they need to upload videos (most probably almost all of them in MP4 format), PDF files, Word, Excel, PowerPoint, Images (jpg, png, etc) and then it should be able to make a thumbnail out of it. I have had a look at other questions here but they are too old and some of the recommended services were too old and not being updated.
I would love to know your suggestions. I heard that with Images I might be able to use ImageMagik, and also heard of FFMPEG once that could retrieve a still image from a video (I saw this when I tried to build a site with Drupal).
Thanks in Advance
I used this command to create thumbnails from videos with ffmpeg:
/path/to/ffpeg -i /path/to/video_file -vcodec mjpeg -vframes 1 -an -f rawvideo -r 1 -ss <time> -s <size> -y /path/to/save_image.jpg
# <time> with format hh:mm:ss
# <size> with format WIDTHxHEIGHT (ex: 240x320)

Categories