Video file splitting on the fly - php

I'm downloading videos from a 3rd party server (mostly flv, mp4) using php script, after download I'm cutting video at 1:30 mins - now it's ready to be played. Is it possible to download only part (1-2 mins) of the video instead of whole file and still being able to play it (the way it's now it's simply wasting bandwidth, CPU...)?

This is very hard to do, as it requires your script to understand MP4 or FLV. However, this may help you (please note that it still requires ffmpeg, FLVTools2 and Mencode to be installed).

Cutting a flv or mp4 involves some index updating, looking for a possible cutting point etc. Building that in php seems overkill. Look into some Tools that can download and cut in one step and call those from your php. FFMpeg and MPlayer may be able to do that.

Related

Playing large videos online

I have a few videos (avi, mp4, mkv) each is around 1 GB and I have one around 7 GB.
I want to play these videos online, so I tried FlowPlayer which seems to be broken with videos larger than 600MB.
is there any solution that will allow me to play these videos online? without converting to flv as I intend to allow downloads for these videos too.
I've been thinking of red5, but I don't know if it will work for this kind of videos nor if it works with the above-mentioned extensions + I am not familiar on how to make its applications and get direct downloads links (I don't want duplicated files for watch/download).
I will also need a timed captioning support like '.srt' files.
Your suggestions are highly appreciated.
You won't find a web-based player that supports all of the features you mention. However, you can get folks to install VLC's browser plugin. This is not ideal, as most folks won't do this, but it will do what you ask.
Otherwise, I suggest keeping the original available for download, and converting the videos to FLV as well. For the captions, you will need to convert the file to whatever format the player you end up using supports.
For the player, I recommend looking into Longtail.

Audio watermarking with Ruby, PHP or Python

I'm working on a project where I need to post-process a bunch of audio files in various formats.
Firstly, the files need to be converted to .WAV format.
Secondly, depending on their length, I need to insert a short audible watermark at certain intervals in each of the new .WAV files.
The first part is easy, using the LAME encoder cli.
The second part is where it get's difficult - I've tried a few method with both LAME and FFmpeg, but can't seem get it working.
The script is running as a cron job in the background, so full cli access is available.
If possible, it would be great if someone could point me to an example script/gem or class that does this in some related way.
This gets complicated. You need to actually mix the audio, which to my knowledge, isn't possible with FFMPEG. The other problem you're going to have is loss of quality if you take an MP3, convert it to WAV so you can work with it, and re-encode it back to MP3.
I think you can use Sox for this: http://sox.sourceforge.net/
Use FFMPEG first to decode the audio to WAV, adjusting sample rate and bit depth as necessary.
Then, call out to soxmix: http://linux.die.net/man/1/soxmix
If you're ready to take the Python route, I would suggest SciPy, which can read WAV files into NumPy arrays:
from scipy.io import wavfile
fs, data = wavfile.read(filename)
(the official documentation contains details).
Sounds can be conveniently manipulated through the array manipulation routines of NumPy.
scipy.io.wavfile can then write the file back to the WAV format.
SciPy and NumPy are general scientific data tools. More music-centric Python modules can be found on the official web site.

Save audio file in chunk from original file

I actually want a demo version for audio file. I uploaded audio file in mp3 format on server with php script. I want that it run for 30 seconds in demo mode and for register user it play whole file.
There is a solution using ffmpeg library while uploading split file in frames and save one for demo and one for original. But I need some different solution because ffmpeg not available on shared server.
Please help me to solve this problem.
You can't cut an MP3 (reliably) on frames alone. There is something called a bit reservoir, where basically frames can rely on other frames. Most frames will be using this feature. If you cut on the frame, you will undoubtedly end up with a corrupt file, and have a few artifacts in your clip.
To do what you are asking, you have two options:
Parse the MP3 data and cut only on frames not using the bit reservoir
Write an encoder that can cut on any frame and fix the bit reservoir so that prior and latter frames are not needed.
Neither of these are good options. Call your web host, get FFMPEG installed. If they won't put it on there for you, get a new hosting provider. Don't waste your time with anything else.

automatically composite sound - php or something like that - GD library for sound?

I am looking for a way to accomplish the following: A user programs some drum loops in flash and is somehow able to download or save an mp3 of the loop.
I thought that the pattern could be composted on the server side. Then a link to the file is sent to the user.
I had thought there might be something like imageGD or imageMagick for sound out there?
Also, if it is possible for flash to generate something that the user could save on the fly? That would work too, but I am unaware of any such functionality in flash.
I suppose something could be done in processing, but I am totally unfamiliar with that.
How might this sort of thing might be accomplished?
Take a look at SoX.
SoX is a cross-platform (Windows, Linux, MacOS X, etc.) command line utility that can convert various formats of computer audio files in to other formats. It can also apply various effects to these sound files, and, as an added bonus, SoX can play and record audio files on most platforms.
If you have control over your server environment, I suppose you could use ffmpeg to do the job.
In your PHP code:
exec(escapeshellcmd("/path/to/ffmpeg -i /path/to/audiofile1.mp3 -i /path/to/audiofile2.mp3 -itsoffset 10 -i /path/to/audiofile3.mp3 -itsoffset 20 -acodec mp3 /path/to/outputfile.mp3"),$output,$status);
Notice that -itsoffset is the offset in seconds you want the audio file to be placed in. So this is not ideal if you want very minute control over the timing, but I don't know if you need that.
Check out this MP3 class.
I'm using it for a project that was deployed just today.
It can read MP3's, extract a part of them, and merge files, among other things, except it doesn't overlap sounds.
Provided you already have those sound pieces (drums, guitar, etc) and that you don't need overlapping, it seems this is what you're looking for.

PHP Extract audio from video

I need a way to extract the audio from some video (in PHP). I have the video streaming in from YouTube, so I would really like it if it were on the fly streaming, not I have to save it to a temp directory and process it there (though that is acceptable.) Thanks, Isaac Waller
Edit: to be more specific, I have a MP4 and I want it to be a MP3.
You're going to want to use something like ffmpeg and call it using php's exec command. If you look around in the docs, I'm sure you can figure out what flag to use to only get the audio.
I've used this app before on a project for live transcoding of video, works like a charm. Just make sure your server has it correctly installed.
Mplayer should do this for you, and there are libraries and codecs that you can call (PHP supports C libraries) which will strip the video from the AV stream on the fly.
Given that you're targeting youttube your job is a bit easier because they use a very small subset of file encodings.
If you take the time to learn the format, you can very easily remove the video stream on the fly and return only the audio stream.
If you give a little more information, such as what you're encoding it to, or where it's going to end up we may be able to help more specifically.
-Adam

Categories