mp3 to flv on the server side how to? - php

I googled it for a long time, all I found was the ffmpeg php api, and a site called mp32tube .. now I was to have the exact same functionality of mp32tube I want to give my users the ability to upload an mp3 add a picture, then compile an FLV on the server that contains the picture and the mp3...
the rest I can do, like uploading the video to youtube, it's simple with their own API ..
can anyone please guide me to something that automatically does this on my server? (a centos powered VPS)
thank you very much.
Rami

You should read FAQ first.
http://www.ffmpeg.org/faq.html#SEC14
then to add sound you may try;
ffmpeg -ar 22050 -ab 128k -i song.mp3 -i videoHaveNoSound.flv VideoWithSound.flv
Let me know the result.
in addition:
you findout a shorter way;
ffmpeg -r 12 -b 1800 -i img.jpg -i yourSound.mp3 -acodec copy outVideo.flv

There is no "automatic" way to do this. You'll have to have the user upload the 2 pieces of data, then run them through ffmpeg. There is tons of documentation for ffmpeg out there, just research the command you'll need to run, test it outside of php first, then once you get it working, implement it in your script. After its gone through ffmpeg, delete the files used for creation, and let them download the resulting flv.

Related

How to mix/merge 2 mp3 files in PHP?

I need a tool to join 2 mp3 files in 1.
The first file ( background ) will be some sound ( music, submitted by user ),
second file will be a machine (google) speaking text, which was submitted ( by user ).
In output I need a single mp3 file, with background music and speaking robot text playing together.
I can't really find any PHP standalone solution like some library or something like, only shell commands atc.
So are there some libraries?
or there's some unique shell command which works on all OS to combine files?
Or how do I complete the task?
Based off of this question, you should be able to install FFMPEG onto your server (hopefully not a shared host?) and use
//Reduce background volume, assuming it's input2.mp3
shell_exec('ffmpeg -i input2.mp3 -af "volume=0.3" backround.wav');
//Merge the two
shell_exec('ffmpeg -y -i input1.mp3 -i background.wav -filter_complex amerge -c:a libmp3lame -q:a 4 output.mp3');
Then you can simply serve up the output.mp3 file. If this is being performed by PHP running under apache (or other web host, instead of CLI) you'll need to make sure your www-data user has read access to the input files, and write access to the output directory.
All your temporary output, like the background, should be saved as .wav, and only converted back to .mp3 for the final output. Recompressing the audio at each step may result in a very poor final output.
I am making assumptions about how FFMPEG works here, so you may need to consult the documentation for it in order to build a functioning or more efficient set of commands.
You can simply do this
file_put_contents('combined.mp3',
file_get_contents('file1.mp3') .
file_get_contents('file2.mp3'));

How can I get a thumbnail from a video that a user has uploaded to my server?

I'm working on a video sharing website where people can upload their own videos and I want the most recent uploads to be shown on the index page, but not as videos but thumbnails, so that when you click on the thumbnail you get to the video page. You guys all know how youtube's index looks/works -- that's what I'm trying to simulate.
I read about ffmpeg but it seems to me it would only work if you have ffmpeg installed on your computer. I want this to be an automated process though without the user having to first install something on their pc.
Is there a way I can code this? Or do i have to use some kind of framework or CMS? Could this problem be solved by simply getting ffmpeg hosting (example)?
If there is no manual way to do this in php, is there way using python?
Fyi, my website is written in php and i use jwplayer to stream the videos. Please note that I want to get a thumbnail from a video that's been uploaded on my server and not a youtube or vimeo thumbnail.
I have worked on this kind of issue and I am sure that user don't need ffmpeg on there pc instead you need a server which has ffmpeg installed.
To create thumbnail from video try the code below.
<?php
$video = 'path/to/video.flv';
$thumbnail = 'path/to/thumbnail.jpg';
shell_exec("ffmpeg -i $video -deinterlace -an -ss 1 -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $thumbnail 2>&1");
?>

PHP Script for FFMPEG conversion

Not been programming for long, so go easy.
Basically I'm attempting to write a PHP script that'll be able to automatically convert a folder full of .mp4's for me, and make them .flv's. This will be done for my entire TV collection (which is quite large) to allow for streaming over my local network within browsers.
I've currently got the following code:
// Save video files into an array
$vid = glob("../../*.mp4");
// Open text file in write mode
$fp=fopen("test.txt","w+");
// Write contents of array to file
foreach($vid as $key => $value){
fwrite($fp,$value."\n");
}
This is taking all of the mp4 files within the folder, and saving their filenames into a text file. The next step I need to take is to read each line, one by one, and perform an FFMPEG command on them until each line has been completed.
Any idea how I can achieve this? I know I'll have to use shell_exec somehow, but I've never used this before, and I'm a little bit stuck as to what to do next.
Thanks for any help
Here is the ffmpeg command line to convert all the mp4 files in a directory to flv files
for i in *.mp4; do ffmpeg -i $i -ar 44100 $i.flv; done
Here it is in php
// Change directory to the directory of the videos
chdir('../..');
// Run the command
exec('for i in *.mp4; do ffmpeg -i $i -ar 44100 $i.flv; done');

Create Video File using PHP

I have scenario for creating a video files using diff. assets like images, audio file.
What I want to do is, Find audio files from the particular folder and set it as background music, and fetch images from particular folder and show those images one by one.
So basically I have images and audio files and I want create a video file using those assets using PHP.
Can any one please suggest the start up point for this? Have done image capture from video and converting the video using Ffmpeg so I have think of Ffmpeg but, I think it will not allow to create a video.
ffmpeg will allow you to create videos from still images.
For example, to create a video with a 10fps frame rate, from images 001.jpg .... 999.jpg:
ffmpeg -r 10 -b 1800 -i %03d.jpg test1800.mp4
You can mux streams (audio and video) like (add relevant codec options for bitrate, etc)
ffmpeg -i video.mp4 -i audio.wav -map 1.1 -map 2.1 output.mp4
I'm not going to go into more detail, as ffmpeg is a pain (args change in incompatible ways between versions, and depending on how it was compiled), and finding a rate/compression/resolution setting that is good for you is trial-and-error.
Under Ubuntu you need PHP5, ffmpeg and access to ffmpeg binary, this can be easy achieved with:
apt-get install php5 ffmpeg
I'm using this php function to generate an mp4 video from one gif image and one mp3 file, both source image and output video files are 720x576 pixels:
function mix_video($audio_file, $img_file, $video_file) {
$mix = "ffmpeg -loop_input -i " . $img_file . " -i " . $audio_file . " -vcodec mpeg4 -s 720x576 -b 10k -r 1 -acodec copy -shortest " . $video_file;
exec($mix);
}
example use:
$audio_file = "/path/to/mp3-file";
$img_file = "/path/to/img-file";
$video_file = "/path/to/video-file";
mix_video($audio_file, $img_file, $video_file);
Phil's solution is the correct approach. Work out what needs to be done by documenting yourself on ffmpeg (it's messy, and I can't blame him for not wanting to do your homework), and then call it from within php.
Cursory googling reveals php wrappers (e.g. http://ffmpeg-php.sourceforge.net/). If none are recent/complete enough, stick to issuing the needed shell commands from php.
ImageMagick convert -delay 100 -quality 75 photo1.jpg photo2.jpg movie.mpg
Or
http://dvd-slideshow.sourceforge.net/wiki/Main_Page

.mov file to .flv file conversion issue for ffmpeg using PHP

Is there any possible way to convert .mov file to .flv file conversion issue for ffmpeg using PHP. If yes, kindly let me know how to do?
Thanks in advance,
Fero
I agree with Kemo, though following the conventions of Stackoverflow, I'll offer the key bit provided by the link given:
ffmpeg -i <filename.mpg> -deinterlace -ar 44100 -r 25 -qmin 3 -qmax 6 <filename.flv>
I often transcode with ffmpeg and I don't ever bother to give all those flags, so you may find my typical use works well enough for you too:
ffmpeg -i inputFile.mov outputFile.flv
That's supposed to just change container formats and it tries to keep everything else as close as possible. I just did that and it seemed to work fine, though I'm uploading my flv somewhere it I'm having an issue, but that's probably totally unrelated to ffmpeg. Any tips?

Categories