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).
Related
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.
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.
What is best way to convert mkv to mp4, with default subtitle (that mkv have), and keep same quality of video / audio ?
Currently I'm using this command
ffmpeg -y -i filename.mkv -vf subtitles='filename.mkv' -disposition:s default+forced -c:v libx264 -c:a libmp3lame -crf 27 -preset ultrafast filename.mp4
But the command still not perfect, the mkv have better quality than mp4 generated. Any advise?
Thanks
your preset is lowest possible quality, and crf could be lower, 18 is more or less lossless, this will make the transcoding slower. of course
So suggest -crf 18 and -preset slow
If you aren't bothered about which codecs you use you could just copy everything into the mp4 container, which would be megaquick
I need to covert 720p or 1080p video to 480p mp4 video , i found below code
ffmpeg -i input -vf scale=-1:480 -vcodec mpeg4 -qscale 3 output.mp4
and please help me , i am unable to give it INPUT VIDEO ex.
$video='/path/to/mp4/video';
exec('ffmpeg -i $video -vf scale=-1:480 -vcodec mpeg4 -qscale 3 output.mp4');
why above code is not working
i used that code and it worked flawless. maybe you werent in the dir with the vid files? or something? you should replace YOURVID.mkv with your file OR /path/to/your/file.mkv as well as replace /path/to/output.mkv with the file name or a file path to the converted output 480p file. easiest thing to do though is be in the dir with the original 720p/1080p video and just use the filename.mkv then output it to that same dir by just using an output.file.name.mkv and not a path. then all files will be in that one directory. i may have over explained it. sorry. lol. and THANK YOU for posting this. it did, indeed, work great for me on my freebsd machine with ffpmeg installed.
ffmpeg -i YOURVID.mkv -vf scale=-1:480 -vcodec mpeg4 -qscale 3 /path/to/new/output.mp4
I have an old 32bit Intel Atom Acer netbook, its not much good for anything. I have batocera installed on it and i need 480p video to play on it.
P.S. with a 320GB HDD, the prev mentioned netbook, some retro game roms and some 480p video files makes an excellent mobile entertainment center.
I have series of jpegs , i want to make flv or mpg from all the images . How can i do it with using imagemagik and php .
exec(convert image1.jpg image2.jpg one.flv) make blank flv
Well I would jump stright into using ffmpeg. You can also do it using ImageMagick; however the docs state you need ffmpeg installed, so why have the middleman?
I haven't tested this, fair warning.
/* cmd img series codec bitrate framerate optional -s WidthxHeight and output filename */
exec(ffmpeg -f image2 -i image%d.jpg -vcodec mpeg4 -b 800k -r 12 video.avi);
/* For Mpeg4 *
/*For FLV */
exec(ffmpeg -f image2 -i image%d.jpg -vcodec flv -b 800k -r 12 video.flv);
If you want to use the outdated mpeg2 or mpeg1 formats you can do that as well.
I would suggest connecting via ssh and testing these commands, and hopefully you have ffmpeg installed.
a ffmpeg -formats will show you which formats are supported:
See the docs:
http://ffmpeg.org/ffmpeg.html#Video-and-Audio-file-format-conversion
and this great answer which I stole various things from:
Image sequence to video quality