I developed a socket based p2p system where i stream mp4 video from a client to a server. The video data are transferred using byte[].
The transfer works, however i am struggling to figure out how i could play, in continuous, a mp4 file being transferred to another PC? The PC application, that would play the file, is in WPF.
I tried using a MediaElement to play the file, being written to the disk, but for some reason it doesnt play at all. I can play it with VideoLan tho.
Any hint of where to look? I am lost from here!
Thanks in advance!
Its going to be different with every player. Mp4 is probably the worst possible container for this application. The container is designed to be used with random access media, such has a hard disk. The player has the ability, and sometimes requirement to seek around within the file, and not just plat start to finish. Either you need to make the protocol mp4 aware (parse the file, and download the block that will most like be needed next), or use a streamable container such as TS, or flv.
Its is also possible that the player knows the file is incomplete. The atoms sizes are encoded within the file. If the file size doest match, the combined atom sizes, the player could assume a corrupt file.If this is what is happening, you can try to pre allocate the file. it may trick the player enough to play
Related
I’m developing an UWP app that should be able to play videos transferred through a custom TCP protocol implementation.
Videos are MP4, so there’s no need to decode frames.
My current solution is to download the file first, and then allow the user to play it, but with big files this is quite annoying.
As a workaround I tried to implement IRandomAccessStream to feed the MediaPlayer while the file gets downloaded, but this isn’t a good solution for sure as there’s no buffering (and the video is just laggy on bad networks) nor visual download progress in the TransportControls.
I know it is possible to create a custom MediaStreamSource, but it requires known encoding properties to be created and anyway it sounds like an overkill to have to decode frames by myself to feed it.
So I’m wondering if there’s any solution to my problem.
Ok so there are a couple inherent understandings
1) I know the SoundPlayer class, despite being able to load System.IO.Stream interfaces, is 100% incapable of playing more than one sound at once, despite all the multithreading and multiple-property usage.
2) I know WMPLib is the go to answer for playing multiple files. Sadly, it requires a URL, and according to MSDN, that URL cannot point to a resource. WindowsMediaPlayer class is also incapable of loading IO.Stream interfaces.
3) I saw a hack where you write out a temporary audio file to disk and have WMPlib play that, and to that I say "polite pass"
Simply put, I do not want users messing with the source audio files. I intend to distribute just the executable and not a zip containing a tonn of files. This is why I opted for the .resx
Is there not another audio player available to C# that can take an IO.Stream that is capable of playing more than one thing at a time?
My little program is a text adventure, and I intend to have a little ambient loop playing in the background while some sound effects play to reflect what's happening on the screen.
I´m doing a "Whatsapp" like app and I need to send user videos (from camera/gallery).
I need to send video from ios to android and from android to ios (windows phone in the future).
First thing I thought is to use camera params to record the video in low resolution, but that won´t help with recorded videos stored in the phone already.
Second thought was to zip the video file, but I guess this is not enough for very large files.
Third: actually compressing the video file generating a new file, and then zip it before sending it through the network.
So this is what I need before actually sending the video:
Compress the video file, generating a new file that will play nicely in
both platforms (ios and android)
Make the compressing process aysnc(as I don´t want to block the UI
thread for a really long time)
Zip it (this is the easy part, just for the record)
Any ideas or help are appreciated
You would best need to use your platforms framework to also leverage existing hardware support for encoding (mainly h.264 hardware encoding). A PCL solution would eat to much battery as it would need to run on CPU only giving you bad performance and even worst battery live.
This ties in with 1. Just use your platforms native method to execute the frameworks methods async.
Skip this part. It will increase overhead and disallow video streaming There are virtually 0 benefits from using a zip algorithm on top of an already compressed video stream.
Just make sure that you end up with a cross platform compatible video format like H264.
This is a bit of a weird question but, with the functionalities of C++, c# and objective C as we speak is there any possible way for video content to be uploaded whilst its recording. So as you record the video it would be being compressed and uploaded to a website.
Would this involve cutting the video into small parts as you record, hardly noticeable stops and starts during the recording?
If anyone knows if this is at all possible, please let me know.
Sorry for the odd question.
You've just asked for streaming media -- something that's been done for over a decade (and, if you overlook "television", something that's probably been underway in research settings for several decades).
Typically, the video recorder will feed the raw data through filters of some sort -- correct white balance, sharpen or soften the video, image stabilize, and then compress the raw data using a codec. Most codec designs will happily take a block of input, work on it, and then produce a block of encoded data ready for writing. Instead of writing to disk, you could "write" to a socket opened to a remote machine.
Or, if you're working with an API that only writes to disk, you could easily re-read the data off disk as it is being written and send the data to a remote site. You'd have to "follow" the writing using something like tail -f's magic ability to follow the file as it is written. (Heck, if you're just bodging something together for a one-off, I'd even recommend using tail -f as part of your system.)
It depends on if the application recording to disk is locking the file. My guess is that, unless you wrote the recording software, the application locks the file(or doesn't even create the real file) until it stops recording. If you are writing the recording software as well, then yes, you can do this. you would just use sychronized threads.
I need to play back 30 second audio clips, 1 per second, in winforms dotnet.
I am currently loading/playing the wav files from the filesystem, which works fine on a notebook, but is causing problems on a netbook. Can I pre-load all sound files into memory, if so how?
If you use the SoundPlayer to play your files you can preload the file with SoundPlayer.Load.
SoundPlayer sp = new SoundPlayer("filename");
sp.Load(); // preload
sp.Play();
Edit:
As noted by the documentation you may also use SoundPlayer.LoadAsync to load the sound in the background.
I'm inclined to say that you would load the file into a system.io.memorystream of some sort. Hopefully the libraries that play your file, will take a memorystream or memorystream can be converted into the data structure that this library takes.
Here's a recent example that creates a .wav file (a sine) in memory entirely from scratch and plays it. What you're trying to do should be much simpler, and you should be able to derive it from the sample posted.
Real low level sound generation in C#?