Video Recording on Android Using Kivy (Python) - java

I am trying to record video through Kivy (http://kivy.org/#home) and am not sure what direction or libraries to use.
Currently I have the camera widget working with the code below, which gets the camera to display on the screen, but I am not sure how to get it to record and save the video file. Any help is greatly appreciated!
class MyApp(App):
# Function to take a screenshot
def doscreenshot(self,*largs):
Window.screenshot(name='screenshot%(counter)04d.jpg')
def build(self):
camwidget = Widget() #Create a camera Widget
cam = Camera() #Get the camera
cam=Camera(resolution=(640,480), size=(500,500))
cam.play=True #Start the camera
camwidget.add_widget(cam)
button=Button(text='screenshot',size_hint=(0.12,0.12))
button.bind(on_press=self.doscreenshot)
camwidget.add_widget(button) #Add button to Camera Widget
return camwidget
if __name__ == '__main__':
MyApp().run()

Kivy support only playing video / camera widget. There is nothing in the framework for encoding video and save it into a file.
Try to use directly gstreamer instead, maybe you'll have more chance.

Related

Android Camera2 Preview Image Decoding fails on car head unit

I am pretty new to Camera2 API and currenty trying to implement a camera preview into my own car application on an Android head unit (Model YT9213AJ). The preview should show the image of the reverse camera.
I've tested the following code on a Samsung Tablet (SM-P610) and it shows the camera preview images as expected, from both, rear and front camera.
private void bindPreview(#NonNull ProcessCameraProvider cameraProvider) {
CameraSelector cameraSelector = new CameraSelector.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_FRONT)
.build();
CameraManager manager = (CameraManager) context.getSystemService(CAMERA_SERVICE);
Size previewSize = getPreviewSize(manager.getCameraCharacteristics("1"));
Preview preview = new Preview.Builder()
.setTargetResolution(previewSize)
.setDefaultResolution(previewSize)
.setMaxResolution(previewSize)
.setTargetRotation(Surface.ROTATION_270)
.build();
preview.setSurfaceProvider(previewView.getSurfaceProvider());
Camera camera = cameraProvider.bindToLifecycle((LifecycleOwner)this, cameraSelector, preview);
}
With this function to get the preview size:
Size getPreviewSize(CameraCharacteristics characteristics) {
StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
Size[] previewSizes = map.getOutputSizes(SurfaceTexture.class);
return previewSizes[0]; // for the camera just one resolution is given, so this should be sufficient
}
This is what the image looks like, if I run it on the car head unit:
Example image preview from car head unit
(Sorry, can't embed images into post yet)
I've also run the App "Camera2 API probe", please find the results here on AirBeat. The camera with ID 5 seems to be an placeholder, I assume that the other two cameras (ID 0 and ID 1) are the representations of the two hardware inputs into the head unit.
Do you have any clue how I can correctly decode the image for this camera model? Thanks for your time.
You could try seeing if not rotating the output helps - the size listed by the camera is already portrait aspect ratio.
In general, though, it looks like whoever made this head unit didn't take a lot of care in making sure the camera output works with the display side, I'm guessing. So it may not be possible to get it to work with the CameraX PreviewView as-is. The PreviewView tries to select the best kind of output View for the API level that the device is, but it may be picking a path the manufacturer didn't actually test with. There's no built-in way to have it select the other option (SurfaceView or TextureView are the choices), so you'd have to modify PreviewView code or build your own Preview surface provider.
There's also no guarantee that'll help, depending on exactly how badly this device implements things.

turning on off flash light while open camera android?

i am using CameraView api 'com.otaliastudios:cameraview:2.6.4' for camera live preview , i want to turn on camera and according to document i can do it with CameraView by turning on but it does not works .
i tried to do it with CameraManager but it is not working either giving me exception that i can not use Flash light when camera is in use . i found some other similar question on stackoverflow . they seem to work but code is not making sense to me , i am not able to understand the code because code is not full .
do you have idea how can i do this , i have already defined permission AndroidManifest file for FLASHLIGHT and CAMERA .
Thank You In Advance .
I am facing the same issue. Try this solution, or read this blog: CameraX: Learn how to use CameraController
val cameraInstance : Camera = cameraProvider?.bindToLifecycle(viewLifecycleOwner, cameraSelector, previewUseCase)
private fun flashToggle() {
// My toggle flash function
val cameraController = cameraInstance?.cameraControl
if (cameraInstance?.cameraInfo?.torchState?.value == TorchState.ON) {
cameraController?.enableTorch(false)
binding.barscanfFlashToggle.setImageResource(R.drawable.ic_baseline_flash_off_24)
} else {
binding.barscanfFlashToggle.setImageResource(R.drawable.ic_baseline_flash_on_24)
cameraController?.enableTorch(false)
}
}

codename one mediaplayer not working on android device

i am creating a mediaplayer app which is supposed to stream mp3 files from remote url.the problem is that the everything works fine on the codename one simulator but not on an actual android device.I want the app to show native player controls like on the simulator.below is my code and screenshots
try {
video = MediaManager.createMedia(sample_url,true);
Display.getInstance().callSerially(() -> {
if (mp != null){
mp.getMedia().cleanup();
}
Image samp = theme.getImage("sample.png");
Label samlabel = new Label();
samlabel.setIcon(samp);
mp = new MediaPlayer(video);
mp.setAutoplay(false);
video.setNativePlayerMode(true);
sample.add(BorderLayout.CENTER,BorderLayout.centerAbsolute(samlabel));
sample.add(BorderLayout.SOUTH,mp);
//songDetails.add(mp);
});
the first image is the simulator screenshot and the second image is the actual android device screenshot
It's unclear from your post if this is an mp3 which is audio and doesn't have media control or an actual video. The MediaPlayer class is strictly for video and you passed true to indicate that this is a video file so I'll treat it as such.
Notice that if this is an audio file then you need to add/create your own controls and shouldn't use the MediaPlayer class.
We recently defined behaviors for native media control rendering as explained here.
Just use:
video.setVariable(Media.VARIABLE_NATIVE_CONTRLOLS_EMBEDDED, true);

How to use flash without stopping camera feed?

I am currently working on a barcode scanning app, which uses the mobile vision api for the majority of processes. I am trying to implement a flash button so that a user may scan in low light, but for some reason the activation of flash freezes the camera feed. Is there some way to start flash with a button while the feed is active? To activate flash without interfering with other threads? Thanks!
i used this code in my custom camera Application.when User clicks the FlashOn Button then Flash will be start.i think this code will help to you.
try this code (OnButton Click) :
private void btnFlashOnClick() {
if (mCamera != null) {
// First get the Camera Parameters.
Camera.Parameters parameters = mCamera.getParameters();
// set FlashMode to camera parameters.
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
// set Parameters Objects to Camera.
mCamera.setParameters(parameters);
// Finally, Start the Preview Of a Camera
mCamera.startPreview(); // this Line is Usefull for MyApp.If you don't need then Remove this Line.
}
}
this code is works fine in my App..Hope this will helps you...(:
It really depends what camera api you are using as there are few.
CameraManager has
void setTorchMode (String cameraId, boolean enabled)
that lets you operate flash regardless of current state of the camera (and without a need to restart one), but it could be overridden by other apps too

Blackberry: how to embed youtube video inside an application

I need to play a youtube video from my bb application. Does anyone know how to do that? Can I have a youtube video player directly inside my app or can I at least have a link to open youtube video in the browser?
What you want to do is get the rtsp streaming URL for the video. When I browse to YouTube on a BlackBerry with the native browser, it serves a page with links to this format. If you know exactly which video to play at build-time, great. If it's going to be picked by your users, you'll have to figure that out.
Then, with that URL, you can create a Player like this:
Player p = Manager.createPlayer("rtsp://SOME_YOUTUBE_VIDEO_ID_HERE/video.3gp");
p.realize();
VideoControl vc = (VideoControl)p.getControl("javax.microedition.media.control.VideoControl");
Field f = (Field)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field" );
The Field f can be added to your screen. And you can start the video with
p.start();
References:
http://docs.blackberry.com/en/developers/deliverables/11942/Create_BB_app_that_plays_streaming_media_739691_11.jsp
http://docs.blackberry.com/en/developers/deliverables/11942/Create_BB_app_that_plays_a_video_in_a_UI_field_739692_11.jsp

Categories

Resources