I am using FFMPEG to convert all kind of media files to mp3. Files are being Converted Perfectly.
But files give error MPEG HEADER 30 is missing at 31576bytes. In All converted files I see this. And On Some MP3 Players, It do not play.
Here is my conversion Command what i use
$bitrate = '128k';
$command = "ffmpeg -i /home/musicupl/public_html/musicuploads/SavetoAccount/abc.mp4 -ar 44100 -ac 2 -b:a ".$bitrate." -acodec libmp3lame /home/musicupl/public_html/musicuploads/SavetoAccount/Output.mp3;
Is there any more tag to add MPEG Headers during the conversion. I have researched on this and found the -acodec libmp3lame but still same issue.
Is there any other way or attribute to add in command line.
Related
I'm trying to convert a video that lives on my server from a .webm to a .mp4.
shell_exec('ffmpeg -i file.webm output.mp4');
However, this results in an empty mp4 (0 bytes - or, sometimes, and very weirdly, 28 bytes.) The input file exists, and is 45MB.
This answer recommended explicitly copying the input codec, but same result.
shell_exec('ffmpeg -i file.webm -vcodec copy -acodec-copy output.mp4');
What am I doing wrong?
[ ===== EDIT ===== ]
After trying a few more things, inspired by the comments, I'm still having no joy converting to MP4.
It seems I'm running FFMPEG v.2.8.15. This seems quite a lot lower than the current release of 4~, however I only installed this a week or so ago so I'm not sure why this is the case and I don't know how to update it (I'm on WHM Cpanel.)
Anyway, my problem is NOT to do with pathing, because the same command works fine if I change .mp4 to .webm - I get a successfully converted .webm file.
But when I run:
$foo = shell_exec('ffmpeg -i file.webm -vcodec copy -acodec copy output3.mp4 -report');
...I get this FFMPEG log output.
I've also tried:
shell_exec('ffmpeg -fflags +genpts -i file.webm -r 24 KKK.mp4 -report');
...from this answer, and
shell_exec('ffmpeg -i file.webm -c:v copy III.mp4');
...from this article.
Both result in the same problem, i.e. an 0-bytes .mp4 file.
Problem
You're trying to mux VP9 video and Opus audio into the MP4 container. Currently, muxing Opus into the MP4 container is considered experimental and requires -strict experimental (or -strict -2), but your ffmpeg is too old to support that. Download a new version.
Solutions
Do not mux typical WebM formats (VP9 or VP8 + Opus or Vorbis) into MP4. You can re-encode it to H.264 (or H.265) with AAC audio if you want a more common set of formats for MP4:
ffmpeg -i input -c:v libx264 -c:a aac -movflags +faststart output.mp4
Or upgrade your ffmpeg and add the -strict experimental (or -strict -2) output option to your command if you know you want VP9 + Opus in MP4:
ffmpeg -i input -c copy -strict experimental -movflags +faststart output.mp4
Or don't re-mux into MP4 in the first place. HTML5 video supports VP9 + Opus in WebM so just use the original file if it is supported by your target browser(s).
I am using both commands in my controller, but sometimes they are not working properly.
Sometimes the compressed file size is larger than size of the original file.
exec(FFmpeg -i old.mp3 -ab 64 mp3 newfile.mp3)
And
exec(ffmpeg -i old.mp3 -acodec libmp3lame -ab 48k new.mp3)
Please, help me.
Above both command is different:
Option Description
-ab bitrate : set audio bitrate (in kbit/s)
-acodec codec : force audio codec ('copy' to copy stream)
That's why In the first command set audio stream in 64 bit, and in the second command is do the stream copy to copy.
I hope this helps.
Create custom video convert plugin - MP4 format
Bellow upload code work fine but how to convert MP4 format after
insert media library.
media_handle_upload('upload_video_file', 0)
exec("ffmpeg -i $fullsize_path -ar 22050 -ab 32 -f mp4 -s 320x240 $value");
<form method="post" enctype="multipart/form-data">
<input type='file' id='upload_video_file' name='upload_video_file'></input>
<?php submit_button('Upload') ?>
</form>
If you are using ffmpeg to convert video,first make sure its installed properly on your server and running.
Check ffmpeg installed or not on your server.
$ffmpeg = shell_exec('which ffmpeg'));
$ffmpeg = shell_exec('type -P ffmpeg');
If $ffmpeg return empty then it means its not installed on your server, if its return absolute path it means installed on your server.
Then you can execute exec commond Just like below
exec("ffmpeg -i {input}.mov -vcodec h264 -acodec aac -strict -2 {output}.mp4");
-vcodec parameter to specify the encoding format to be used for the output video.
-acodec codec (input/output)
Set the audio codec. This is an alias for -codec:a
For more commond check ffmpeg link https://ffmpeg.org/ffmpeg.html
I have created a PHP code which compresses mp3 while uploaded to 32kbps bit rate I have referred this thread
How to compress or convert to low quality Mp3 file from PHP
used this code
exec("ffmpeg -i inputfile.mp3 -ab 24000 outputfile.mp3")
but the problem is I can't compress more than 32kbps .my code instruct to compress up to 24kbps but after execution, I can see the output file is 32kbps. can anyone tell what should I do so that I can compress more than 32kbps .or is there any limitation of ffmpeg ??
The reason you cant achieve lower then 32kbps is because of the sample rate most likely is still 44100-Hz meaning larger stream size, you have a few options 44100-Hz, 22050-Hz, and 11025-Hz as valid frequency's.
Try (very low quality):
ffmpeg -i inputfile.mp3 -acodec libmp3lame -b:a 8k -ac 1 -ar 11025 outputfile.mp3
-b:a = audio bitrate
-ar = sample rate
I have installed ffmpeg on my server.
Now I am looking for a php library which can perform ffmpeg functionality, like retrieving video information, converting it to FLV or in any other format, and streaming video.
Please help, Thanks!
You can use below function to convert mp4 video to flv
function mp4toflv($in, $out)
{
//echo $in.' '.$out;
$thumb_stdout;
$errors;
$retval = 0;
// Delete the file if it already exists
if (file_exists($out)) { unlink($out); }
$cmd = "ffmpeg -i $in -ar 22050 -acodec libmp3lame -ab 32K -r 25 -s 320x240 -vcodec flv $out";
//$cmd = "ffmpeg -i $in -b 1024k -s 352x264 -r 25 -acodec copy $out";
//echo escapeshellcmd($cmd);
exec(escapeshellcmd($cmd));
unlink($in);
}
similarly you can also convert other video formats to flv or any other format. Below are some help to convert videos to mp4(h264)
1]. ffmpeg -i input.mp4 -vcodec libx264 output.mp4
2]. ffmpeg input.AVI -vcodec libx264 -sameq output.mp4
option 1 can use for :- (mp4,mov,flv)
option 2 can user for :- (3gp,avi,mp4,mov,flv)
execute above commands using "exec(escapeshellcmd($cmd))" where $cmd will be any from above two options.
Hope this will help someone :)
We have been using ffmpeg-php without any major problems, just make sure you are using supported ffmpeg version. If you need any special behaviour, you can always additionally wrap it using exec().