Reputation: 9324
I would like to record a video and send it to the server. It has to be H.264
mp4, so the server does not have to convert it, and it can be displayed on the web.
This is how I currently create the Intent:
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
}
It works, but I don't know, how to set the codec to H.264
, or how to detect the default codec. I was able to find solutions for MediaRecorder, but I would like to avoid using that, because that is too complex for my needs, and I don't want to build a video recorder gui just for that. The MediaStore.ACTION_VIDEO_CAPTURE
would be perfect, because the user can record/replay the video, cancel or retry the recording, without any extra programming (and possible bugs) from my site, I just get back the video uri in onActivityResult
.
Upvotes: 0
Views: 623
Reputation: 2546
Unfortunately there does not seem to be a way of specifying the codec to be used. As you can see from https://developer.android.com/reference/android/provider/MediaStore#ACTION_VIDEO_CAPTURE, the supported EXTRAs are related to output Uri, duration and size limits, and a simple quality value (0 low quality, 1 high quality).
This is intentional; sending an Intent will result in starting an unknown (at compile time) app, that may or may not support all the functionality required. Also, since an external app is involved, the fewer parameter value ranges have to be established the easier it is to implement.
As you already realized, in Android operations can usually be performed two ways: a "simple" one, in this case asking for the default camera app to produce a video, usually by means of an Intent, and a "powerful" one, usually by means of an API, in this case the MediaRecorder API.
I'm afraid that if you are unable to successfully use the easy way you'll have to go the hard way; usually some boilerplate code can be readily found online.
Still though, for your specific case, I'd let the external app do the heavy lifting of capturing a video file, and later check if H.264 is the codec that has been used (it will most likely be, imho). If not you could work around that: depending on your use case, ask the user (if he/she is knowledgeable enough) to try changing settings in the recording app, or you could implement some form of video transcoding inside your app via a third-party library.
If your use case is so specific that you do always know which camera app will be used (i.e. you are the manufacturer of the devices, or your use case only allows for one specific model and custom android version of the hardware), and you happen to know that your camera app does indeed support specifying the video codec via some custom EXTRA value, you can also try passing that in the Intent data. Alas, I'm afraid this will not work with a generic smartphone target (i.e. you do not know the camera app that will happen to handle your intent).
Upvotes: 1