I am using a RPi camera to capture video in a MJPEG format to file. However, when I attempt to do so, the application freezes up and requires me to manually kill it. I am not sure why it is freezing up, but any ideas to resolve this problem would appreciated.
This program entails the following code in accord to the documentation from the following website under the section "start_recording": https://picamera.readthedocs.org/en/release-1.10/api_camera.html#picamera.camera.PiCamera.start_recording
The actual program is as listed below:
start_recording('/home/pi/testVideo.mjpeg', format = 'mjpeg')
camera.wait_recording(5)
stop_recording()
Related
I have written a code, which puts on a live webcam recording various filters, and gives me at the end again a video as output (with cv2.imshow). Now I want to use the output video in another code at the same time. Bringing the two codes together is not possible.
Does the output video have an address where I can call it? Is there an OpenCV function, (like cv2.VideoCaputere), with which I can read open videos?
Saving the video and then reusing it does not work, because the other code must process the output video at the same time.
I am using ffmpeg to take screenshots of a video file. It seems some video files end up looking squished because ffmpeg is automatically rescaling them for some reason. I am using a python package to do this, not the CLI tool. The only options I am using are specifying the timestamp to capture and quiet output. I am try to get a lossless shot. I don't know why it is resizing automatically. I tried using the force_original_aspect_ratio option and setting it to -1 but it does not work without specifying the height. Is there any way to prevent this from happening without needing to provide the height? I can do that for my script but it seems unnecessary. It should just keep it as-is.
EDIT:
BTW, the video is 720x480. Oddly, the metadata on the video and the screen shot are both 720x480. However I lined them up and the video is clearly wider. VLC takes a screenshot just fine. Someone told me ffmpeg just has issues with SD files. I don't know.
I am using Airnef to download pictures from my Canon DSLR camera through python.
I can download one picture without problems so the whole setup seems to work. However, as soon as I want to download another image the software hangs. The code to me looks quite complex.
Two months ago I did post a thread on TestCams.com. Since I haven't gotten a response, I post this as a python-related question here.
The thread
I start airnef from the command line.
python airnefcmd.py --ipaddress 192.168.188.84 --action getfiles --realtimedownload only --downloadexec open #pf# --transferorder newestfirst --outputdir "/Users/besi/Desktop"
I connect the camera and I’m shown some information about my connection:
Connection established to 192.168.188.84:15740
Camera Model “Canon EOS 200D”, S/N “XXXXXXXXX”
Now airnef tells me:
Waiting for realtime photos from camera to download.
Press to exit |
I take a picture and it downloads it as expected:
Downloading “IMG_0084.JPG”: 96%
Airnef then shows some more information about this image:
/Users/besi/Desktop/IMG_0084.JPG [size = 4,602,357] in 1.94 seconds (2.26 MB/s)
I take some more pictures but they’re not downloaded and the software is stuck at the prompt:
Waiting for realtime photos from camera to download. Press to exit \
Source code
The source code is available at the Airnef Website. I created a github repository for tackling this issue: https://github.com/besi/airnef
The place where the code is stuck is at airnefcmd.py:3203
Update: Forum Post
Here is the link to the forum post on testcams.com
Update: Debugging
The first image called IMG_0182 was downloaded successfully.
In the debug output I can see a new picture being taken, but the download is skipped because the prior image was already downloaded:
See airnef.log:433:
filename = DCIM\100CANON\IMG_0183.JPG
captureDateSt = 20180926T071759
modificationDateStr= 20180926T071758
A new image called IMG_0183.JPG was found.
Skipping IMG_0182.JPG - already downloaded this session
The old downloaded image seems to block the further processing of the current image.
Skipping 100CANON - object is not file - MTP_OBJFORMAT_Assocation (0x3001)
Skipping DCIM - object is not file - MTP_OBJFORMAT_Assocation (0x3001)
Waiting for realtime photos from camera to download. Press <ctrl-c> to exit -execMtpOp: MTP_OP_GetObjectHandles - CmdReq payload:
Now we end up again in the loop waiting for more pictures.
When a new picture is taken, the same procedure happens again.
I don't have a compatible camera, so I'm basing my answer solely on the logs (in Debug mode) posted on the forum. Also it was a trial and error suggestion in one of the comments, so it's not the "scientific" approach (where the cause is being identified, and then fixed).
A team (#Besi and I) effort was required in order to come up with this answer (and the credit should be split accordingly).
According to logs, there is a difference between how the 2 files are handled:
...
filename = DCIM\100CANON\IMG_0182.JPG
captureDateSt = 20180926T071747
modificationDateStr= 20180926T071748
Download history file “/Users/besi/Library/Application Support/airnef/appdata/Canon EOS 200D-SN59074c1578e347a3bf1f6f85e8dec624-downloadhist” loaded – 53 entries
>> MTP_OP_GetObject
Downloading “IMG_0182.JPG”: 0%IMG_0182.JPG – downloading next piece, offset=0x0, count=0x100000
...
filename = DCIM\100CANON\IMG_0183.JPG
captureDateSt = 20180926T071759
modificationDateStr= 20180926T071758
Skipping IMG_0182.JPG – already downloaded this session
Skipping 100CANON – object is not file – MTP_OBJFORMAT_Assocation (0x3001)
Skipping DCIM – object is not file – MTP_OBJFORMAT_Assocation (0x3001)
Waiting for realtime photos from camera to download. Press <ctrl-c> to exit -execMtpOp: MTP_OP_GetObjectHandles – CmdReq payload:
...
As seen when handling the 2nd file (IMG_0183.JPG), the existence of the 1st one (IMG_0182.JPG), triggers everything to be abandoned.
Browsing [TestCams]: airnef - Wireless download from your Nikon Camera!, one of the command line argument (actually, there were more that I suggested) caught my eye: --rtd_mtppollingmethod_newobjdetection, and I suggested specifying numobjs (and thus, overriding the default). Apparently, this was the (main) problem. The other part was the presence of --transferorder newestfirst. By default, in Realtime Download mode, it's set to oldestfirst (see below). Removing it (or redundantly specifying --transferorder oldestfirst) did the trick.
Conclusion
In order to fix the problem, 2 things were necessary (in terms of cmdline args for airnefcmd.py):
Specify --rtd_mtppollingmethod_newobjdetection numobjs
Remove --transferorder newestfirst
According to [GitHub]: besi/airnef - (master) airnef/airnefcmd.py#3403:
g.args['transferorder'] = 'oldestfirst' # so that downloadMtpFileObjects() will properly enumerate through multiple realtime images as we add them
I consider this a bug on airnef's side (regarding --transferorder). It's located in either
Code: --transferorder should be ignored when in Realtime mode
Doc: Specify that --transferorder newestfirst is not compatible with Realtime mode
I have been working with some drones and robotics projects using arduino and python. There was a kickstarter project for a neat little hex copter, that hasn't been managed well.
I was lucky, i got my copter and then some time later after some frustrated email exchanges, i finally recieved the camera as well. To this day, their forum has people still complaining. Their maker forum is now down and their wiki hasn't been updated with any specifics on the camera.
http://www.flexbot.cc/wiki/index.php?title=Main_Page#Hardware
Their app to accompany the drone still doesn't support the camera module. Not that it'd matter, as their code isn't very well documented or annotated.
https://github.com/HexAirbot
There are some tips on switching the camera on the comments page of their kickstarter campaign.
https://www.kickstarter.com/projects/1387330585/hex-a-copter-that-anyone-can-fly/posts/1093716
So, sob story over, i'm stuck with this neat little wifi camera that i am unsure on how to connect to. I know how to switch it on and it does have a micro-usb port on it.
What library in Python could i use to stream an image from this camera given that it is a wifi camera. If i wanted the video stream as a numpy matrix.
I need to interface with the camera, so i can connect and disconnect.
Then, be able to read images frame by frame with ffmpeg. I have some python modules that can detect and read from a camera, but how can my code ensure that the camera is connected?
Totally stuck. Any help would be appreciated.
Considering you are building for the android platform, you will more than likely need to use some sort of java/python driver/interface, unless you just use java.
Here is an article on java/python, and using python from within java.
Using Python from within Java
Background
I'm attempting to craft a simple video playback script for a small cinema that automates the playing of videos and control of the projector, sound and lighting systems. I have two video outputs, one goes to a monitor in the projection booth, and the other directly to the projector. I desire to play video (and only video) fullscreen to the projector while putting controls and a small (~1/4 screen) preview on the monitor. This will allow the projectionist to view the video being output and control the playback from the monitor in the booth while all the audience ever sees is the video output.
Problem
I am currently using Python to control VLC player (with libvlc Python bindings) to playback videos. I have everything working fine except that I can't figure out how to get a preview (direct copy) of the video being played fullscreen on the projector output into my GUI.
I have tried using the clone filter, but I cant get the cloned window to automagically appear full screen nor in my GUI. The clone filter seems like the logical choice but it seems to be VERY inflexible when it comes to specifying destination screens, fullscreen, etc. I must be able to open video windows full screen on the projector monitor. Professionalism is key and it would look bad if the projectionist had to drag a window over and double click on it when the movie started.
Currently Using:
Debian Linux
Python 2.7
wxPython
libvlc
I would like to continue using Python as I already have the code for controlling the projector, sound processor, lighting and curtain written and tested. I chose VLC because it really seems bulletproof when it comes to video playback but am not committed to it's continued use. I also chose wxWidgets for my GUI as a result of past experience but I am not stuck on that either.
This describes the direct solution and does not concentrate on any alternative or the overall design of your application.
As Your Application and VLC media player are separate processes, you will not be able to get what you want directly because there is no "shared memory" between those 2 applications. The best shot to "copy" the decoded frames from VLC will be to e.g. send a RAW Video .mts stream (ts is usually used for this kind of usecase) and send e.g. to udp://localhost:1234.
In your application, you will need to be able to receive the ts stream, "decode" it and display at the spot of interest.
For start, i would try if you are able to do this using 2 vlc players that you control manually. When you achieved that the first VLC streams to udp and outputs on the main display at the same time, and the other VLC player receives and plays the udp stream you can go on:
Find a player library that you can use directly in your wxpython application and check if it can receive the udp stream as well E.g.
https://wxpython.org/Phoenix/docs/html/wx.media.MediaCtrl.html
This player lib for example requires gstreamer as a base.
As a result, main display and the picture in your applicatoin might have a latency of some seconds. To come around this latency, the best way that i currently know is using WebRTC but this is a lot more complex setup than the above.
https://www.sipwise.org/news/technical/tv-over-webrt/
Sure in case you do some "encoding" for WebRTC or even for UDP, you would need to utilize some hardware encoder, e.g. Nvidia NVENC in order to be able to guarantee the needed resources are always there.