Showing posts with label mplayer. Show all posts
Showing posts with label mplayer. Show all posts

Monday, September 9, 2013

Raspberry Pi Journal #20


Installing Web Camera

Or How to Get a High End Deer Camera Really Cheap

I was shopping around at MicroCenter when I saw this cheap HP webcam HD 2200 for sale. I couldn't resist and bought one. So, the first thing to see if the camera would work right out of the box. And what do you know? It works fine.

There's a program called lucview that you can use to see if the webcam works, but I simply use the mplayer program that I already downloaded.

mplayer tv://

That will work just fine. Apparently, though, the cheap webcam has bad adjustment. It's fine under sun light, but when the room is dark, the blacks become blue and green. So freaky!

Next, it's video capture time. I'm using a program called motion. The program uses configuration file. It took me a while to notice that there is no command line parameters. In the end, I simply create a file called motion.conf and put it in my directory. Also notice, that if you have more than one, you also need to create motion1.conf, motion2.conf, and so on. Not that I will have more than one. Even using one, my Raspberry Pi goes to max CPU so easily.


pi@rustypi ~ $ cat motion.conf
#motion -c /home/pi/motion.conf
auto_brightness off
brightness 200
contrast 200

control_port 9001
control_localhost on
webcam_port 9090
webcam_localhost off
framerate 2
noise_level 255
noise_tune on
threshold 16400
threshold_tune off
max_mpeg_time 540

ffmpeg_cap_motion off
ffmpeg_cap_new on
ffmpeg_timelapse 2
on_motion_detected echo "motion is detected"
on_movie_start echo "Movie  %f is starting"
on_movie_end echo "End of Movie %f"

jpeg_filename cap%M%S
#jpeg_filename preview%T
movie_filename Movie%v
snapshot_filename shot%M%S
timelapse_filename tlapse
target_dir /home/pi/webcam_images

height 640
width 480
output_all off
output_motion off

Quite a long list of options, right? It uses 2 ports. One is for control, or the user interface for the program. Another is for webcam, or the viewfinder of the program. The viewfinder uses MJPEG stream, something Midori cannot handle. I eventually relented and use my Kindle Fire for it.




You can see the big monitor that is running Raspberry Pi, and I'm holding the webcam next to my Kindle Fire that is acting as my viewfinder. Talk about technological overkill! It works well enough, but that's quite a bit of technologies involved here. Oh, the blue box? That's my Nintendo 3DS XL. I'm using it to take the picture.

Hmmm. It looks like I'm using a bunch of cheap technologies, doesn't it? Does that means I'm a cheapskate?





Here is the view of the directory. I created a special "webcam" directory to hold the images. I'm thinking of moving it to external SD card, because of SD write wear problem.

The name of the files are different according to what you want to use. In this case, I'm using capHHMM format. There are lots of different format, depending whether or not you're capturing time-lapse and whatnot. The only thing I can tell you is for you to experiment.





I thought I was being clever and decided to capture screenshot via webcam. It turns out the lighting was atrocious and all I got was a bunch of colored dot. Not at all what I was looking for. I set the brightness manually, and brought it extremely bright lights. It works, in that the screen looks normal. It doesn't work in that the lighting was uneven. Either way, the result is unusable.

You know, I was thinking how this Raspberry Pi is really compact and that motion program is really powerful. Then it occured to me that I can duplicate the project as Deer Cameras.

I was looking through the Cabela's catalog, and it features lots of deer cameras, starting from $80 and up. So, I'm thinking, Raspberry Pi, battery, webcam, Wifi dongle. Those probably costs about $60. Tupperware for rain-proof enclosure, and you have the redneck equivalent of Raspberry Pi powered Deer Camera!

You'll run it headless, for sure. You can set it up anyway you want. In short really nice functionality of a high end deer camera for the price of the cheapest kind.

Well, there's one thing missing. It can't take picture in the dark. I suppose, you'll need infrared spotlight. Or heck, since we're talking about redneck version, just hook up multiple Million Candlelight Spotlight, set to trigger when the deer is in range. Just freeze those deer in multitude spotlights, good for taking pictures with webcam in the middle of the night!




Sunday, August 11, 2013

Raspberry Pi Journal #4

Video Playback Trouble
OMXPlayer Trouble. MPlayer2 works fine.

So, I was connecting my USB flash drive to Raspberry Pi, and I played some videos I have that I recorded using my Windows 8 camera. The resolution is HD. Omxplayer plays fine as usual, but somehow, there's no sound! That's strange. I looked at the boot configuration, it says hdmi_force=2, which means HDMI output. Furthermore, I believe that I did play the video with sound before.

Putting in -o hdmi didn't work, believe it or not. I was very disappointed. So I tried various options. This works:

omxplayer -r -o hdmi filename

I was so very happy, until it reaches the end of the video, and the whole screen went blank! Uh-oh. Not good. So very not good!

I wasted several hours trying to debug the process. In the end, though, I gave up. It's nice to be able to use hardware decoding, but if in the end I have to shutdown the computer and reboot, then that's not the way I'm going to do it! Maybe there is a command that I can use to reset the display. If so, then I can simply write a script just to make sure the command to reset the display is run after omxplayer finished playing. I don't know such command.

Obviously, I'm not going to use that program ever again.

So, I went to the package directory. I did a search and found mplayer2. Looks good. The package seems to be rather well-developed. So it's pretty simple to just download the whole package.

sudo apt-get install mplayer2

Curiously, when I did a which mplayer2, I came up blank. So, I did which mplayer. Bingo! There it is! Obviously, there'd be a conflict if I ever install mplayer, instead of mplayer2. Will have to be careful in the future.

Then I ran some test videos.

  • Nintendo 3DS video: Ran fine, no problem.
  • Flip Videos: Ran fine, no problem. Can do Full Screen. 50% CPU
  • WIndows 8: Ran slow. Out of sync. 100% CPU

None of the videos ran smooth, BTW. I had to use -framedrop option to run it. I was extremely disappointed that the Windows videos can't be shown. I'll have to make sure to record in low resolution mode from now on. Or, I can simply use my Nintendo 3DS to record the video. It ran just fine!

Here's the screen capture of the video in action:

Not bad for a windowed application that does not take over the whole screen. Unlike omxplayer, I may add. So, I'm happy for now.


EDIT:
Finally figured out the command to refresh the screen. There is a couple seconds delay at the end, but at least I get my screen back! I ended up making a script called "omxplay", do a chmod 755 and put it in /bin

#!/bin/bash
omxplay -o hdmi -r "$1"
fbset -depth 8 && fbset -depth 16