I have made programs for my windows phone that displays the camera feed on the screen. I have also sent/received data using the Sockets namespace. Is it possible to "combine" these to create a live video feed from the camera that can be connected to by a computer on my LAN?
Well, this is a very interesting question. In fact, it normally should be possible to create a live stream - but - and this is the "hard" point: You have to do it on your own, so you have to care about everything you need for a real live stream.
In detail, it's not very complicate to realise a kind of live-stream. Think about what you need:
1a) Image-Source (normally of course the cam)
1b) kind of Image-Copier
2) Streaming-Server
3) Streaming-Client
So if we talk about Windows Phone, you have many .NET classes available who are doing some work for you. For a good start you should consider the following reference:
http://msdn.microsoft.com/en-us/library/ff637518%28VS.92%29.aspx
If we go more into detail, you have to perform the following tasks:
1) Get your camera image ready
2) Copy the content of your video-brush/canvas ui-element into a stream
3) write the stream to a temp file
4) upload the temp-file over the server to the clients
5) go into a loop and start over by 3.
The big think in this case is, to get the video-brush copy done, so for this have a look at the connnected msdn reference for the video-brush
http://msdn.microsoft.com/en-us/library/cc189009%28VS.95%29.aspx
To have a good starting point for copying the content of the video-brush into a stream consider this document
http://msdn.microsoft.com/en-us/library/bb404773.aspx#anchor_videobrush_relationship
by using the media element as a host for the "live-pictures".
Another, better, but of course, more complicated way is to implement your own version of the video brush. Read this article to learn how to copy the preview-camera buffer
http://msdn.microsoft.com/en-us/library/microsoft.devices.photocamera.getpreviewbufferycbcr%28VS.92%29.aspx
So, i hope, i was able to give you an idea, how to implement your solution.
p.s.:
If you are able to speak german, I've kind of book recommendation for you:
http://amzn.to/wxfEzd
I'm the author of this book ;)
Related
I am trying to recreate some features of Spotify in C# using the PostgreSQL database.
The reason is simple, I want to gain more knowledge, and I think this is a good challenge.
But I ran into an obstacle that I've been standing for days. Spotify he doesn't download the music, he does her streaming, plays the music while it's downloaded.
However, I can't do this in C#, I'm using the PostgreSQL database.
I'm well locked in this part, I tried several implementations, but I think I'm not on the right track, and on the internet I imagine I'm looking wrong, otherwise I would have found it.
Do you have any guidance for this streaming process in C#? I've tried to read the large_object bytes from PostgreSQL, but couldn't.
Any suggestions or guides about the process are welcome.
You start by getting the file into the database or its network location into the database, whichever gives you better performance; Then start with creating an implementation of a bytestream. You want to be transmitting raw data to c#.
you then build a real time interpreter that takes in using your file format, one byte at a time, and plays the value associated with that section. does that make sense? this is simple to do with many libraries and the brunt of it is just figuring those out.
You seem like you've PROBABLY got that first part down, and are instead having issues with the database. A lot of things we did at my last company involved saving file network locations and indexing files on disk. You might be able to instead point your streamer to a file locally using a server, and instead transmit data from one point to another in that manner instead.
You seem more than capable of doing this just judging by your speech. I hope this comment was helpful, and if it was not I apologize as well. I would be interested in seeing your finished result.
for clarification here would be that workflow:
request for a song listed in table dbo.Songs
matches that song onto dbo.songlocation
streams from dbo.songlocation.location from the filename dbo.songlocation.songname = dbo.song.name and verified directory returns true
enjoyment of that music
So, I need to obtain the current audio playback that is happening on my pc programatically in real time. This includes all the audio(you can check this in the playback devices tab of the Sound settings). I need it because I'm doing an analysis over the stream which I then put into use in another software. Until now, I've used the 'StereoMix' option, which actually relay's the current audio as an input(something like an internal microphone). However, I can't use this method when I connect external speakers to my pc(through HDMI, PC/AUX works though).
Is there some way to obtain the audio stream no matter if external speakers are connected or not.
The programming language does not matter in the current case, everything is fine with me. However, I prefer if there is a C# / Processing solution.
EDIT:
Here's the technique(and method) I currently use to obtain the audio in http://code.compartmental.net/minim/minim_method_getlinein.html. The library/code is related to Processing: https://processing.org/.
Basically, NAudio would be a good place to look for a prospective solution. Its not quite clear what you intend to do with the audio such as if you're recording/dumping data, or simply analyzing live-data so I'm thinking NAudio is going to have something such as you're looking for, as far as getting your hands on live-data.
NAudio has an FFT, but not quite robust in the area of analysis as the JS-libs you may be accustomed to ;)
http://naudio.codeplex.com/
https://github.com/naudio/NAudio
There are plenty of examples provided to get you started, and many in the wild.
Though its pretty outdated and the API may or not look slightly different (in regard to...), the following video may provide a nice relaxing quick-start to help familiarize you with this lib.
C# Audio Tutorial 6 - Audio Loopback using NAudio
Let's say I have a file: test.txt and I save it on my harddisk.
Is there a way to determine on what (physical) spot the file is saved on the hard disk?
For example on vector 12 on track 10 of the hard disk.
I don't know if I got the terminology right of the above, but I hope you get what I mean.
I want to write of program wheer the user can point to a file and the program will find out where the file is on the HDD. Something like the old defrag (it's Windows ;) ) where it shows what parts of the disk is in use.
What is this called and can it be achieved? (I'm not looking for code (although exmaples are ok ofc), but rather whether it is possible)
P.S. The client will be Windows 7 (so think NTFS if it matters).
I'm pretty sure that doing that sort of low-level disk i/o in managed code is going to be...difficult, at best. Here's somebody that's done something like it:
http://codebrainz.ca/index.php/2010/05/23/low-level-disk-io-in-managed-net/
Anything you write to do something like this has to be hardware-dependent: unless you know what hardware you're talking to, you've got no idea how it physically stores data (e.g., a USB memory stick has neither platters, tracks nor sectors, nor does it spin. Yet, for all intents and purposes, it appears to be a disk).
Normally, you'd write some sort of device driver to accomplish this. This link
http://en.wikibooks.org/wiki/Windows_Programming/Device_Driver_Introduction
might help.
In Jeffrey Wall's WebLog you will find Defrag API C# wrappers. His GetFileMap method sems to come close to what you need.
It is possible from C++, so with a little interoping, you should be fine.
Look up FSCTL_GET_RETRIEVAL_POINTERS in the MSDN to get you started.
I'd like to create a simple remote desktop application (you can view the screen remotely and interact with it). As a first step, I've tried taking screenshots, 1 per second, compressing them to JPEG and sending them over (without interaction), but I've found that even over LAN this is very slow.
Do you have any hints on how to do this better? Is there C# sample code for projects like this?
You might consider looking at VNC's implementation. VNC is open source and does what you want. I know of an open-source .NET client for VNC:
http://dotnetvnc.sourceforge.net/
Hopefully this will give you some direction for your project.
Just-in-time idea, if you don`t want to use vnc - and want to implement this yourself (for learning, how to invent wheels, for example) - send not full screenshot, but changes from previous - somethins like *.avi format (I forgot details, but something like: one full card, 15 changes, one full card, 15 changes and so on).
Does anybody have a known reliable way to create a video from a series of image files? Before you mod me down for not searching for the answer before posting the question, and before you fire off a simple message like "use FFMPEG," read the rest of this message.
I'm trying to create a video, it doesn't matter too much what format as long as it's widely supported, from a series of images (.jpg, .bmp, etc.). My platform is Windows Server 2008, 64-bit. If I can make the video from within my C# program, that's great, but I'm not averse to writing a series of image files to a directory and then firing off an external program to make a video from those images.
The only constraints are: it must work on my Windows Server 2008 system, and be scriptable. That is, no GUI programs that require operator intervention.
I found a number of similar questions on StackOverflow, and have tried several of the solutions, all with varying degrees of frustration and none with anything like success.
FFMPEG looks like a great program. Maybe it is, on Linux. The two Windows builds I downloaded are broken. Given this command line:
ffmpeg -r 1 -f image2 -i jpeg\*.jpg video.avi
One of the builds reads the images and then crashes due to data execution prevention. The other reads the first file and then spits out an error message that says "cannot find suitable codec for file jpeg/image2.jpg". Helpful, that. In any case, FFMPEG looks like a non-starter under Windows.
One answer to a previous posting recommended Splicer . It looks like pretty good code. I compiled the samples and tried to run, but got some cryptic error message about a file not found. It looks like a COM class isn't registered. I suppose I need to install something (DirectShow, maybe, although I thought that was already installed?). Depending on what's required, I might have a difficult time justifying its installation on a server. ("What? Why do you need that on a server?")
Another answer suggested the AviFile library from Code Project. That looks simple enough: a wrapper around the Windows AviFile subsystem. Except that the AVI files the package creates appear to have all of the frames, but only the first frame shows when I play the AVI in Windows Media Player. Well, that and if you try to create a compressed video, the program throws an exception.
So, I'm left wondering if there is a good, reliable way to do what I want: on a Windows system, create an AVI or other common video file format from a series of images, either through a .NET API or using an external program. Any help?
After working with it a while and taking a look at x264 and VideoLan, I went back to Splicer. It turns out that the cryptic error message was due to an error in my code.
It looks like Splicer will do what I want: programmatically create videos from a series of images.
Thanks to all who responded.
You can use VideoLan and I'd recommend it.
I've had direct experience in a C# application with VideoLan doing these two things:
Embedding a VLC viewer in my C# application (there are 3-4 C# "wrappers" for the VLC veiwer).
Using vlc.exe in a separate Process by sending it command-line arguments.
The fact that VideoLan has a command-line interface is a great thing. And VLC supports a command-line option that disables any visual element; so the VLC GUI doesn't pop up and neither does a command-line window. Thus, in a C# application you can farm out the video-related work to the VLC client. C# has the Process class which can manage your vlc.exe instances for you. It ends up being a pretty neat solution.
The handling of video on Windows (encoding and playback) is a real quagmire. And .NET isn't going to help you at all - you're always going to be either PInvoking/COM-interoping native APIs or using a .NET wrapper that someone else has built to do the same.
Anyway, I can't say I've used it, but a good bet seems to be the x264 library that is part of the videolan project. That gives you a self-contained C library that you can PInvoke and you don't have to worry about installing and DirectShow garbage on your server. It'll generate H.264 format video which is playable in Flash as I understand it.
I've used mplayer's mencoder to create AVI (with codecs msmpeg4/mp3, readable by default with Windows Media Player) from TGA files on linux like this:
mencoder mf://*.tga -mf fps=25:type=tga \
-audiofile /tmp/test.mp3 -oac copy \
-of lavf -ovc lavc \
-lavcopts vcodec=msmpeg4v2:mbd=2:mv0:trell:cbp:last_pred=3:vbitrate=3000 \
-o /tmp/test.avi
I know mplayer does have a Windows version.
Instead of just going through all the hassle, you could coppy all the images that you want to be included in your video to the clipboard and have it imported into Windows Live Movie Maker (dynamically, of course!) and have it compile for you!
All of this CAN be done through code, but this way, you don't have to create it yourself. As you said that the platform was Windows, and ALL Windows comps have Windows Live Movie Maker installed, so it shouldn't be a problem for anyone using your application unless
a) They uninstalled Windows Live Movie Maker
b) They are using a computer running on a Windows Version more than 8 or 9 years old...