aspt / mp4

Creative Commons Zero v1.0 Universal
43 stars 5 forks source link

raw h264 to mp4 #2

Open e1ioan opened 3 years ago

e1ioan commented 3 years ago

First of all, this is not an issue, is a question. Can you please point me in the right direction on how to convert a raw h264 stream file to mp4? I tried to follow the test application, but I'm not sure I understand where the raw data will go.

In the test application you have the following code:

    // == Append video data
    for (i = 0; i < 30; i++)
    {
        MP4E__put_sample(mp4, id_video, idr, sizeof(idr), 0, MP4E_SAMPLE_RANDOM_ACCESS);
        MP4E__put_sample(mp4, id_video, frm, sizeof(frm), 0, MP4E_SAMPLE_DEFAULT);
    }

Is the frm constant the array that contains the data for one frame?

aspt commented 3 years ago

Re: [aspt/mp4] raw h264 to mp4 (#2)

Hello Ioan,

Yes, this code repeats 30 frame pairs. All pairs are the same. Each pair have IDR and P frame, which are both pre-calculated constants, taken from some h264 raw stream. Note that frame data must not include 3 or 4-bytes start code (0 0 1  or 0 0 0 1)

-- Best regards, Andrey                            mailto:audio.video.dsp@gmail.com

===== Original Message ===== Andrey Wednesday, January 6, 2021, 9:55:51 PM, First of all, this is not an issue, is a question. Can you please point me in the right direction on how to convert a raw h264 stream file to mp4? I tried to follow the test application, but I'm not sure I understand where the raw data will go. In the test application you have the following code:    // == Append video data    for (i = 0; i < 30; i++)    {        MP4E__put_sample(mp4, id_video, idr, sizeof(idr), 0, MP4E_SAMPLE_RANDOM_ACCESS);        MP4E__put_sample(mp4, id_video, frm, sizeof(frm), 0, MP4E_SAMPLE_DEFAULT);    } Is the frm constant the array that contains the data for one frame? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

e1ioan commented 3 years ago

Thank you for your prompt answer! So, if it was to make the conversion from a h264 raw stream, do I just parse the stream, ignore all the codes between frames, and when I have a frame I use: MP4E__put_sample(mp4, id_video, idr, sizeof(idr), 0, MP4E_SAMPLE_RANDOM_ACCESS); and if the frame is a P frame I use: MP4E__put_sample(mp4, id_video, frm, sizeof(frm), 0, MP4E_SAMPLE_DEFAULT);

Am I understanding right?

aspt commented 3 years ago

Re: [aspt/mp4] raw h264 to mp4 (#2)

Hello Ioan, Yes, that's correct for most of 264 streams, except those, which are using slices. If you need more features, the best way is to use https://github.com/lieff/minimp4 - it is a successor of my code with the same API, but with more features.

-- Best regards, Andrey                            mailto:audio.video.dsp@gmail.com

===== Original Message ===== Andrey Wednesday, January 6, 2021, 11:15:06 PM, Thank you for your prompt answer! So, if it was to make the conversion from a h264 raw stream, do I just parse the stream, ignore all the codes between frames, and when I have a frame I use: MP4E__put_sample(mp4, id_video, idr, sizeof(idr), 0, MP4E_SAMPLE_RANDOM_ACCESS); and if the frame is a P frame I use: MP4E__put_sample(mp4, id_video, frm, sizeof(frm), 0, MP4E_SAMPLE_DEFAULT); Am I understanding right? — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

e1ioan commented 3 years ago

Yes, I saw minimp4 and tested it, it works well. My only problem is that the code I'm going to use will have to be converted to BrightScript (for Roku players) and minimp4, yes it has more features, but it will also be more code to convert. My only need is to be able to convert h264 stream to mp4. I'm hoping to get your code working with my raw h264 stream and then try to get it working on Roku.