AAC & AVC byte stream data into ts file - h.264

Background:
I am trying to build my own RTMP server for live streaming. (Python3+)
I have succeeded to establish an RTMP connection between the server and the client (using OBS). The client sends me the video and audio data. (audio codec: AAC, video codec: AVC).
I also built a website (HTTP), with HLS (hls.js) player (.TS & .M3U8) that works properly.
Goal:
What I need to do is to take the video and audio data (bytes) from the RTMP connection and join them into a .ts file container so it could be playable on my website.
Plan:
I planned to join them into an FLV file and then convert it to TS using FFmpeg. which actually worked with the audio data because FLV support AAC, so I generated FLV files that contained audio-only.
Problem:
The problem started when I tried to add the video data into the FLV file, but it is not possible because FLV does not support AVC.
What I tried to do:
I can choose another file container to work with, that supports AVC/AAC but they all seem really complicated and I don't have much time for this.
I tried to find a way to convert the AVC to H.263 and then put it inside the FLV (Because it does support H263) but I couldn't find a way.
I really need help. Thanks in advance!

Related

Record rtmp stream to multi flv files

I'm currently write rtmp server to receive rtmp stream, then record to multi flv file, segment base on time.
Example: 1 minute -> 1 flv file, 2m -> 2 flv file...
Problem: only the first flv file is playable, from the second onwards, they are not playable, maybe they miss some metadata of the codec (h264).
How can I resolve that problem?
Yes, there is a header, as well as sequence headers depending on the codec used. The segments must also be split on keyframes. The FLV formate is well documented here https://www.adobe.com/content/dam/acom/en/devnet/flv/video_file_format_spec_v10.pdf

Export dynamic audio from Flash

I'm generating a 44100hz dynamic audio stream in Flash using a flash.media.Sound object and the SAMPLE_DATA event. I'd like to be able to analyze the output instead of just listening to it.
What would be the most straightforward way of converting my Flash stream of float samples to an audio file, in a standard format that can be opened by an audio editor? Is there any audio format that would be particularly suitable for this?
If you don't want to listen to it, there's no need to use Sound or the Event.SAMPLE_DATA at all. Just create the numbers and store them in a ByteArray or other data structure.
Is there any audio format that would be particularly suitable for this?
A format that can be opened by your audio editor would be preferable.
Otherwise, this totally depends on what you want to do with the sound data.
What would be the most straightforward way of converting my Flash stream of float samples to an audio file, in a standard format that can be opened by an audio editor?
To use an existing library that encodes the data into the specified format.
tonfall supports "various audio formats Wav AIFF RAW PCM (no header) "Encoder/Decoder
WaveEncoder from Nicolas Bretin apparently encodes to WAV
Of course, if you know the specification, you can write your own encoder.

How to merge to sound files in WP8?

It it possible to merge sound captured from microphone with an mp3 file selected and save as a new mp3 file in windows phone 8?
Does naudio have wp8 support??
Possible, yes. But you would have to decode the mp3 file into raw PCM data that matches the waveformat of the captured audio data, merge the pcm data (either an additive or mean merge or you'd simply add the captured audio data to the end of the pcm data from the mp3) and encode your new pcm data to MP3. There are plenty of libraries out there that support encoding/decoding of mp3 data and you might even find one that would let you decode/re-encode only the sub-sample of the mp3 file that you're interested in merging with captured audio data.
NAudio has, AFAIK, no WP8 support. I believe that they're currently working on Windows Store App support.
You would need to use WASAPI - which is a native-only API - or the Microsoft.XNA.Audio.Microphone-class to capture data.

Reconstructing fragmented H.264 stream

I have H.264 stream stored as a file. I am trying to create a MPEG4 file by adding this stream to MDAT BOX. I have created other headers required by MPEG-4 standards. But I am unable to read the MPEG-4 file.
I parsed the H.264 stream and I see that there are multiple I-frames in the file. It seems to me that this is fragmented H.264 stream.
Is there any way in which this fragmented H.264 stream can be combined into a single I-frame?
I have gone through the link Problem to Decode H264 video over RTP with ffmpeg (libavcodec).
I implemented what was mentioned in the link but i am still unable to run the MPEG-4 thus created.
With the above technique, I get the fragmentType = 5. I get the following nalTypes (8, 2, 1, 0, 0, ...). I get the startBit as specified and for the other fragments, I get the 00 (for StartBit|endBit). I do not get the endBit.
When i try using FFMPEG to reconvert the MPEG-4 file that was created, i get the following error: "header damaged". It looks like the reconstruction of IDR frames is not working properly.
Please let me know if the method that I am following has any issues.
The H.264 stream file is around 100KB. When this file is converted to MP4 using FFMPEG, I get around 38KB. Does it mean that FFMPEG is re-encoding the file once again inorder to recreate the MP4 file?
With the above technique that was mentioned in the link, the MP4 that I have created is around 100KB itself.
Please let me know what I am doing that is wrong.
Thanks in advance.
It sounds like you'd like to wrap an H.264 elementary stream in a mp4 container so that you can play it back.
A tool like mp4box (http://gpac.wp.mines-telecom.fr/mp4box/) will enable you to wrap you elementary stream into a mp4 file. For example:
mp4box -add MySourcFile.h264 MyDestFile.mp4

Converting Mpeg file to flv and simultaneously playing the converted file in flash cs3 using as3

I have an mpg file which I want to convert to flv format, but I have a requirement that while converting the mpg file, I also have to simultaneously play the converted flv file in the flash cs3. How to do it? I am using cs3 and as3.
If you want to convert your files programmaticly then use ffmpeg. This is a commandline tool which can convert video files to nearly everything. You have to execute ffmpeg with the correct params and wait until the video is ready. This works only on serverside. Means the flash client loads up the video file to the server. There it gets converted. You can execute ffmpeg with any serverside language like php.
Sadly I have no idea if it is possible to watch the video while converting. I think not but maybe someone else knows more.