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!!!
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.
Related
I am working on a chat application like whatsApp, I want to transcode media file before uploading to server,I have gone through so many links but not able to decide which method i should use, is there any straight forward way of transcoding in android ?
FFMPEG i found it is highly cpu intensive process ,it will consume more battery power
Media Codec i want to do the transcoding using mediacodec but not able to get proper steps to understand the process.
Best link to give idea about transcoding
Library to transcode using media codec (It has many bugs)
We used both implementation for our video editing app. Basically we used MediaCodec implementation if android version >= 4.3 and use FFMPEG otherwise.
The problem with using FFMPEG:
As you said, cpu intensive process thus consume more battery
x264 encoder is licensed under GPL, so you might want to use OpenH264 encoder instead which only support Baseline Profile, therefore video quality is not the best
Since it used software encoder, processing speed is relatively slow, at least compared to the MediaCodec implementation
MediaCodec also have some cons though, for example:
If you want to do transcoding, android version need to be >= 4.3 unless you want to deal with color format conversion yourself, which is completely mess, since each vendor may have it's own color format implementation. (Since 4.3, MediaCodec support encoding using input surface)
Hardware encoder may behave differently for different models. (For example some encoder may produces B frames which is not supported yet by android MediaMuxer, so you may want to use ffmpeg for the muxing part)
So I should say if you only support new android version, you should use mediacodec, but if you want to be safe (easier to write code that works on all device) and does not really mind the performance, use FFMPEG with OpenH264
Android's MediaCodec is a relatively better way to transcode on the client since it uses its own low level buffer processing. But then it doesn't provide elaborate tweaking freedom as FFMpeg does.
As to MediaCodec source code, it also is CPU intensive for holding the buffers and processing them but its actually way lesser than FFmpeg.
First of all, I haven't started the implementation of the system I'm about to describe, as I didn't want to commit on implementing something I did not know if was possible.
So, what I'm trying to achieve is to build a chrome-app to download the audio from certain websites (e.g. youtube and soundcloud) using youtube-dl, post process it using ffmpeg and then upload it to a cloud service via some api. The reason I want to do it via a chrome-app is because I could do all the work on the client side (no need for servers) and I'd have the ability to insert javascript into the pages using content scripts, which would make the app pretty simple to use (I could create buttons such as 'download song' and stuff like that).
Although I have already read the documentation explaining the NaCl Technical Overview and some of the Application Structure, I still am not sure as to whether I would be able to make these calls via some C/C++ module or if I would get denied due to security reasons.
To summarize: considering that the user has the needed dependencies in his system (youtube-dl, python, ffmpeg and etc.), is it possible to make calls to third party APIs such as the ones described before via a chrome-app using NaCl ?
Thank you all in advance,
Chrome apps are normally sandboxed.
Less so than extensions - they can reach much more system resources via app APIs.
But still, what you mention is executing libraries / utilities out of browser, and it's not normally allowed.
(P)NaCl is tightly sandboxed in this regard. See this old question, it still applies: you can only use 3rd-party code that compiles into NaCl along with your app, not just link to a library. There are some library ports to NaCl, but it's not automatic.
Normally, a few years back you would use a mechanism like NPAPI to reach out and use a library out of browser. It's deprecated, and won't work anymore. In its place, Chrome offers a pipe-like (through stdio) connection to an external program called Native Messaging. You could use it to perform operations with system-level libraries and tools, but the downside is that you can't bundle the native host with your app, you'll need a separate installer.
Is it possible to hash flv videos so it is unplayable by itself and the format is unrecognizable by softwares, but i could actually de-hash them and play in my as3 script?
This is going to be realized on a CD so I can't use server scripts.
no, you can't. not with flv. you could however embed the video into an swf and encrypt the SWF. please note however, using a strong encryption for video data may lead to performance problems.
anyhow: you can load the binary data into a ByteArray, perform the decryption and then load the SWF from the ByteArray.
I'm assuming you mean that you'd like to do this "real time" in the app.
If so, there are two issues with that:
you will have to decrypt your custom video in software, so its going to run very slow. And depending on the end user's computer, unpredictably so.
As ALOToverflow previously mentioned, the key to your hashing algorithm will be in your .swf which can be simply be decompiled to reveal it.
Assuming you are using as3 with adobe AIR you could potentially ship your users "broken" flv's and then simply repair them before you attempt to play them back.
Depending on the resolution and length of the videos this might be a viable alternative.
(you'd utilize the FileStream Class for this.) http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html
FLV's all start with a standard header, so you could start by just breaking the header, and repairing it later. (I'm talking about getting down and dirty with the binary code btw.)
http://en.wikipedia.org/wiki/Flash_Video
I created a similar project once.
this is what I did:
I encrypt the videos somehow, does not mater how, put them into one single big file.
A bulk data file. Then I run the swf, NOT from browser but rather run it from a JAVA application, which can decrypt the bulk video-file waaay faster, than the Adobe swf interpreter.
In the Java app, I pass the decrypted video to the swf as a parameter.
It is good to use Java, because all the clients can open it. Mac users, Windows users, anyone. It is possible to do it with C++, but that would limit your user-base.
Of course anyone with decent knowledge can reverse-engineer the encryption process, but it is harder to get the encryption from a Java compiled software, than from an AS3 swf.
Use Blowfish, Twofish or DES. Do not use RSA, it is slow.
You have to make the Java app extremely fast and simple, so also it is advised, not to use external cryptography libraries.
Currently I am using nochump library for unzipping files. But its very slow(around 30 seconds for 2 mb file). Is there any other libraries available which are fast. Or is thaere any better way to unzip by communicating with os?
I have used FZip, but it wont work in mac. So cant use it.
Not that I'm aware of... AS3 is quite slow in these areas...
A possible workaround, if you are using zips for loading images, could be using a big JPEG with all of your images inside it (eventually using an aditional XML to determine dimentions, or maybe even custom metadata). Uncompressing images in Flash is quite fast (and asynchronous).
It might be possible using Alchemy (there are very fast Alchemy librairies to encode JPEG and PNG), but I can't find any existing one for unzipping.
Otherwise, you can use the AIR 2.0 beta (not great for production code... depends on your project) to call a native application which will do the job for you.
Anyway, it might get tricky to retrieve progression information if you need it.
I'm wondering about MP3 decoding/encoding, and I was hoping to pull this off in Flash using AS3
I'm sure it'll be a right pain...
I have no idea where to start, can anyone offer any pointers? reference material?
----much later---
Thank you all very much for your input... It seems I have a long road ahead of me yet!
You could also theoretically do this as a PixelBender filter, and should get significantly better performance than using a pure ActionScript 3 implementation.
More info on PixelBender here:
http://labs.adobe.com/wiki/index.php/Pixel_Bender_Toolkit
mike chambers
mesh#adobe.com
this would help
http://labs.adobe.com/technologies/alchemy/
See LAME MP3 Encoder. You can checkout their source code and their link page. Mpeg.org should have documents too.
I've got a project converting WAV files (actually Asterisk voice mails) into MP3's. If I remember correctly there are some oddities about Lame's license, so I've downloaded and compiled first LAME, then SOX by hand.
I have a web process written in PHP to actually convert the files from WAV to MP3 on the web server's local file system (actually PHP is just supervising the command-line sox tool via exec()). Then I attach all the metadata the MP3 needs using the PEAR Mp3_Id package.
Then I move the newly constructed MP3 file into a folder Apache is sharing, and point the outstanding SoundManager2 flash-based MP3 player at it.
For small transactions this works very well -- converting a minute or two voice mail does not add any appreciable lag to actually rendering and returning the rest of the page. As I get more users on a single server, it will probably eventually become necessary to write a cron job or something to do the conversion before the user actually asks for the file the first time.
It's going to be VERY slow doing this in AS3. You really need a C/C++ implementation if you care at all about how long it will take.
Andre Michelle and the Hobnox guys pulled off something similar with their Hobnox AudioTool, they ported a Java Vorbis encoder to AS3. They supposedly ended up with encoding taking twice the time of the audio duration.
Don't know what your use case is, but in the Hobnox tool apparently audio is created at the client side, encoded as Vorbis, sent to the server, converted to mp3 and stored in the users library.