1

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!!!

ucMedia
  • 4,105
  • 4
  • 38
  • 46
sergioBertolazzo
  • 585
  • 2
  • 11
  • 27

1 Answers1

2

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.

Harry
  • 1,233
  • 10
  • 24
  • Thank you for awser. I read about this ffmpeg, but i can't install anything in my server side (i dont have permission to acess te server, i just send code) you know any librarie .jar that do this? – sergioBertolazzo Oct 29 '17 at 18:12
  • 1
    It is a very hard way to get done what you like, you should open another question for "native way to use ffmpeg in java". Or do some research on that topic. One possible way might be here: https://stackoverflow.com/questions/1281353/use-java-ffmpeg-wrapper-or-simply-use-java-runtime-to-execute-ffmpeg But where is the difference for you to place a new jar on the server vs placing a portable binary file there? - ffmpeg is portable. – Harry Oct 29 '17 at 19:21
  • Thank you, i just send my code modifies via IBM Jazz (is a tool to send code font), i can't acess the server. – sergioBertolazzo Oct 29 '17 at 19:52