Convert byte[] to Video (mp4 or any other palyable format) - type-conversion

I am creating a bot that will record the Microsoft team live sessions. Audio recording is working fine but facing problems in generating the video file. The process I am following is that I am converting the video data into a byte array and then writing the data to a video format file.
I am adding some code snippets, I have examined so far.
1. Stream videoStream = new FileStream(videoFilePath, FileMode.Create);
BinaryWriter videoStreamWriter = new BinaryWriter(videoStream);
videoStreamWriter.Write(videoBytesArray, 0, videoBytesArray.Length);
videoStreamWriter.Close();
2. System.IO.File.WriteAllBytes(videoFilePath, videoBytesArray);
The generated files from the above code snippets are of an unsupported format.
It may be because of the data receiving from the session.
I am receiving the data through the Local media session's Video Socket on VideoMediaReceived Event (ICall.ILocalMediaSession.VideoSockets). The Video Color Format of the data that the socket is receiving is of H264 Format.
A similar problem I encountered when creating the audio file. For that, I utilized the WaveFormat package for creating an audio file.
So, Is there any library/method to convert the byte array to a video file of any format?

#Murtaza, you can try this and see if it helps. If the byte array is already a video stream then, simply you can serialize it to the disk with the extension mp4. (If it's an MP4 encoded stream).
Stream t = new FileStream("video.mp4", FileMode.Create);
BinaryWriter b = new BinaryWriter(t);
b.Write(videoData);
t.Close();

Related

mp4v2 extracting and decoding data from .M4A file

I have extracted the audio data from .m4a file using mp4v2 library (sample-by-sample). Does this library have function that decodes the data? Anybody with experience with this library and can provide some help?
The documentation says:
MP4ReadSample function reads the specified sample from the specified track.
Typically this sample is then decoded in a codec dependent fashion and
rendered in an appropriate fashion.
I am interesed in decoding the output.
Thanks in advance.
You tagged MP4(video data) and M4A(audio data). Since you are extracting from M4A, I can only imagine you actually have either AAC or MP3 audio data.
Each extracted sample (bytes) is audio frame.
To make a playable MP3 file : Simply join all MP3 frames' bytes together. Save as .mp3 to play later.
To make a playable AAC file : For each AAC frame, first create an ADTS header (7 bytes) followed by that frame's data. You can test your header bytes here (site shows what your byte values mean). When all your AAC frames each begin with an ADTS header, simply save as .aac to play later using some audio payer code.
I have researched everything and the answer is NO. There is no decoder in mp4/mp4v2 libraries. One has to use some other library to do that.

How to create an Mp4 file from H264 raw data that I am receiving from a live streamer

How to create an Mp4 file from H264 raw data that I am receiving from a live streamer (no predefined duration or moov atom), unfortunately can't use FFMPEG, I have to write my own code using live555. Can somebody help me with Mp4 container and how h264 data has to be pushed into it.? Thank you in advance : )
There are several operations to be made to store H.264 raw data into MP4, among them:
create box structures, in particular the moov box
store the NAL units in a mdatbox, possibly storing non-VCL NAL units in the moovbox
replace start codes with length fields
It also depends on your requirements. If you want to do the conversion on-the-fly, you have to use fragmented mp4. If you can store the H264 and then do the conversion, you may use non-fragmented mp4. In particular using MP4Box:
MP4Box -add file.264 file.mp4

how can i play pcm with AVPlayer

I'm using AVPlayer to play local .mp3 file and audio stream from server.
And i want to play local .pcm file too.
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory
, NSUserDomainMask
, YES);
NSString * voiceFile = [[paths objectAtIndex:0] stringByAppendingPathComponent:#"OutPut.pcm"];
But it didn't work. i got unknown error.
It seems AudioQueue can play .pcm correctly.
But is there a sample way can let AVPlayer direct play .pcm just like .mp3?
Neither .pcm as a file extension or PCM data specifies a readable format. The player cannot recognize an arbitrary data stream. It is certainly capable of reading file formats which contain PCM data, but this PCM representation is missing several things typical audio file formats represent:
Sample Rate
Sample Size
Sample Format
Channel Count
and so on.
You should instead save that PCM data in an audio file format the player supports (e.g. a WAV file).
If you prefer to simply stream PCM audio information and you know the stream format, you can approach that problem using an AudioQueue.

AVAudioPlayer returns error "pty?"

AVAudioPlayer seems not to handle some audio files that can be handled if using AudioStreamer (https://github.com/mattgallagher/AudioStreamer) even when played as a local file.
My questions:
1) What type of audio files generate the error code "pty?". NOTE: Audio file plays fine in QuickTime Player.
2) The following code generates the same error using this audio file:
UInt32 size;
OSStatus err = AudioFileGetPropertyInfo([self audioFileID], kAudioFilePropertyChannelLayout, &size, NULL);
But using the stream api on the same audio file this will work (ok different properties are fetched but then the question is why can't channel layout be asked?):
err = AudioFileStreamGetPropertyInfo(inAudioFileStream, kAudioFileStreamProperty_FormatList, &formatListSize, &outWriteable);
I know that if you stream audio you need to use the stream api because only a part of the file is available at the time. But when the complete file is in the filesystem the file audio api should be possible to use (?)
3) Is it recommended to use stream api even if the file is local? Good ideas how to implement it are welcome.
What puzzles me is why AudioFile* api fails were AudioFileStream* works.

how to convert byte array or binary data into audio file

I need help in my iphone application, I want to convert byte array or binary data into audio file.Please help me out and tell me any way so i con do it.
If your array is supposed to contain audio data in PCM format, than you can simply add WAVE header at the beginning to get ready to play audio file. Format of header is described here.