hello all i am building a video hosting site and wanted to know what are the video formats which my php code should convert the user's video so that all the major browsers support the file.
by searching on internet i got to know that mp4,swf,avi,ogg are the formats but if i convert one video to all these formats then there will be 4 times the space of a single video and also there will be server load and time consuming process for the conversion.
so i was wondering if there is one or two formats which i should take with me so to reduce the server load and conversion time.
i am converting the video by this code (ffmpeg)
if (move_uploaded_file(#$_FILES['profileimage99']['tmp_name'], $uploadfile)) {
$base = basename($uploadfile, $safe_file['ext']);
$new_file = $base.'flv';
$new_image = $base.'jpg';
$new_image_path = $live_img.$new_image;
$new_flv = $live_dir.$new_file;
require 'vendor/autoload.php';
//ececute ffmpeg generate flv
exec('ffmpeg -i '.$uploadfile.' -f flv -s 768x432 '.$new_flv.'');
//execute ffmpeg and create thumb
exec('ffmpeg -i '.$uploadfile.' -f mjpeg -vframes 71 -s 768x432 -an '.$new_image_path.'');
also please tell me will it be good to use exec in php code ??
The most common web video formats are WebM, OGG, and MP4 with MP4 being supported in IE, Chrome, Safari, Opera, and FireFox.
Therefore, it would be prudent to stick with MP4.
Related
I am playing mp3 files on the JW player but i am facing a strange problem.
JW player is playing mp3 files having mime type "audio/mpeg" but it is failed to play mp3 files having mime type "audio/x-mpeg". It is such a strange problem for me because both files are mp3 JW player should play both.
I have also tried to convert mp3 file to mp3 file using ffmpeg in php but it is still producing mp3 file having mime type "audio/x-mpeg".
exec(ffmpeg -i $input_file -vn -ar 44100 -ac 2 -ab 192k -f mp3 output.mp3)
one thing i need to mention that this file type is generating from ios app.
I am stuck from 2 days in this issue. Your help would be really appreciated .
Thanks
You need to keep the mp3 with supported mime type.
Jwplayer does not support audio/x-mpeg format. Check here
Update:
1) audio format for iOS and Android
2) What are the audio-format encoders that Android and iOS have in common?
Hope this helps
So, i have kind of accepted this task on work but im really not sure if its possible.
We are going to build a website where users can upload videos from their computers and mobile phone browsers. The video files can be a large range of aspect ratios, width, height, codex and file formats.
I will have access to ffmpeg from php exec command on a web server.
Is it possible to use this to convert the user files to one file format that works on computers, android and iphone.
The requirements is that we can set a max width, to witch the video will be scaled, dynamically to match height.
Does anyone know is this can be done, and be done in a reasonable amount of time. Will do project on 2 days. And if so some pointers in the right direction would be nice.
Had the same problem but solved by using HandBrake the open source video transcoder
https://handbrake.fr/
If your target can only be one file format, then I would choose mp4 baseline. (However some browsers won't play it, which is why the html tag offers multiple source flags, which usually include webm and ogg video...)
Using ffprobe -show_streams $uploadedFile you can get the dimensions (and aspect ratio) of the file. Using math you can get the new dimensions based on your needs.
$newDim=$new_width.":".$new_height;
$output = shell_exec("/usr/bin/ffmpeg -i $uploadedFile -f mp4 \
-c:a libfdk_aac -b:a 128k -c:v libx264 -vprofile baseline \
-movflags faststart -vf scale=$newDim $output");```
Here is the breakdown:
f mp4 > format mp4
c:a libfdk_aac > audio codec
c:v libx264 > video codec
vprofile baseline > minimal codec usage for mobile
movflags faststart > put the moov atom at the beginning of file
$output > should have '.mp4' as a file ending
Of course the devil is in the details (and the number of processing cores you can throw at an online converter), but this will get you up and running at least.
Edit: Actually answered the question. :)
By the way, ffmpeg does offer the vf flag: -vf scale=320,-1, but sometimes it gives you a dimension not divisible by 2 which throws an error in x264 encoding. Its better to do the math yourself.
I want to upload a file (Indeed, I already did it using PHP and JQuery) but I want to encode it to MP4 and/or WebM in the process of the upload, such as Youtube does when you upload a video there. Is there a option to be able to do it in the server during the process?
Do I have to encode them first and then upload?
You can do it at the end of file upload, which is after you moved the file to a specific location (below code)
move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
You can use a free and well-known library called FFMPEG which supports a wide range of formats. Please take a look at these two links for example and better explanation:
https://www.phpro.org/tutorials/Video-Conversion-With-FFMPEG.html
https://trac.ffmpeg.org/wiki/Using%20FFmpeg%20from%20PHP%20scripts
Basically, you can call the FFMPEG function from PHP like this
<?php
/*** convert video to flash ***/
exec("ffmpeg -i video.avi -ar 22050 -ab 32 -f flv -s 320x240 video.flv");
?>
I have compressed MP4 video using FFmpeg in a PHP environment. Videos are being compressed, but they are not playing in Firefox, showing an error:
Video can't be played because the file is corrupt
while this video is playing fine in VLC media player and also in the Chrome browser. My code of compression is as-
exec("ffmpeg -i input.mp4 -acodec mp2 output.mp4");
I struggled with this problem until I discovered this gist entitled 'ffmpeg convert gif to mp4, for best cross browser compatibility'. It uses this command:
ffmpeg -f gif -i FOO.gif -pix_fmt yuv420p -c:v libx264 -movflags +faststart -filter:v crop='floor(in_w/2)*2:floor(in_h/2)*2' BAR.mp4
It has these notes on how it works:
output mp4 is encoded with h264, support Firefox/Chrome/Safari in Windows, Mac OSX, Android, and iOS.
one mp4 file for all platforms, there is no need to encode an extra webm movie, which encoding speed is pretty slow.
format as yuv420p for Firefox compatibility, the downside is color becomes less-saturate than original gif.
yuv420p only support even width/height, so crop filter is required
-movflags +faststart flags are optimized for online view in browser
compression ratio typically 10:1, pretty awesome. note that if original gif is < 512KB, convert as mp4 is less efficient.
Incorporating that into my ffmpeg command, I find that the videos now run in Firefox, Safari, Opera and QuickTime (where previously only Chrome and VLC worked for me).
Credit to ingramchen, who wrote the gist.
I know this is a few months old, but in case anyone is still intereste: I had this same thing happen and I found it was because my MP4s were encoded in "MPEG-4 Simple profile" a.k.a. H.263/MPEG4 part 2/xvid. These formats are not supported for playback in most browsers any more.
Transcoding the files to H.264 fixed the problem.
I'm converting from WMV to FLV using FFMPEG, and my problem is that the FLV videos are so big! the 15 minutes video's size ranges between 150MB and 1GB!
I'm using the following FFMPEG command to convert and split WMV videos :
nohup nice -1 ffmpeg -y -ss 00:00:00 -t 00:15:00 -async 1 -i INPUT.WMV -acodec libmp3lame OUTPUT.FLV
And I've tried converting to MP4 before and the video size was much smaller than the FLV video.
So my questions are:
Would the MP4 videos have any
compatibility issues browsers?
Would it work on iPhone, iPad? (I
know FLV videos doesn't work on
iPhones or iPads)
What is the best FFMPEG command to
convert to MP4 without losing the
quality of the video?
A few points...
Video size has to do with the bit rate, dimension, and codec. It does not have anything to do with the container.
You can certainly expect 15 minutes of video to be large, assuming you want more than a postage stamp for viewing area. This is normal.
Any time you re-compress something, you are going to lose quality. There is no way around this. You might be able to keep most quality by recompressing at a higher bitrate, but this defeats what you are trying to accomplish.
Bottom line, unless you need to, don't do it. Simply encode your videos at the appropriate bitrate to begin with.
For converting any video to mp4, use:
ffmpeg.exe -i INPUT.wmv -vcodec libx264 -sameq OUTPUT.mp4
If the quality is too low on that then set the bitrate to be around what you want:
ffmpeg.exe -i INPUT.wmv -vcodec libx264 -b 500k OUTPUT.mp4
The output mp4 file plays in Flash, browsers that support H.264 MPEG4, iOS, and Android.