Reputation: 604
I have developed a website where the user can upload videos. Everything worked fine until I discovered that if the video codec is not supported, it will not be displayed by the browser. I realized that this same video that is not displayed by my site, is displayed perfectly by youtube.
is there a way to support all video formats in html 5? If it does not exist, is there any way I can convert the video to another format with javascript or java on the backend?
Every help is welcome!!!
Upvotes: 1
Views: 174
Reputation: 1263
Current HTML5 implementations do not provide any way to get to your goal, even if they did, it would be very OS and browser specific. What i do to get this done is to install a local application that "live encodes" the stream locally and streams the output to the html5 video element.
In fact, there is no way at all on this world to support "all video formats" in one shot. The best you can currently do is to use ffmpeg on the backend to transcode.
Simply install ffmpeg on the backend and from your backend java, you just use the Runtime.getRuntime().exec method to call an ffmpeg commandline, like this
ffmpeg -i "%yourvideo%" "%youroutput".mp4"
It is a totally different topic to get a ffmpeg commandline done that is compatible to a lot of input formats, but using the above command you might hit already lots of formats.
Edit: please be aware of the consequences of "transcoding" on your server. It uses huge amounts of CPU and GPU usage is extremely complex. Due to this fact, you should not expect any really native way in java to do the same job as it would cost even a lot more CPU than the compiled C and assembler code of ffmpeg uses. Even if you find a native way how to use it natively in java, it will take weeks or months of R&D to get the same job done than a simple commandline exec could do for you.
Edit2: it might be a way for you to go through online encoding services like encoding.com and similar. But those do cost lots of money compared to running ffmpeg locally.
Upvotes: 2