shaka-project / shaka-packager

A media packaging and development framework for VOD and Live DASH and HLS applications, supporting Common Encryption for Widevine and other DRM Systems.
https://shaka-project.github.io/shaka-packager/
Other
2k stars 510 forks source link

How to use BufferCallbackParams with gstreamer #1268

Closed felibol closed 6 months ago

felibol commented 1 year ago

System info

Operating System: 18.04.5 LTS (Bionic Beaver) Shaka Packager Version: main branch https://github.com/shaka-project/shaka-packager/commit/cc9a691aef946dfb4d68077d3a741ef1b88d2f21

Question

I am trying to integrate shaka packager to gstreamer pipeline with using c-api. I have added gstreamer app sink and receiving encoded H265 video byte data. I have also configured shaka packager like below

    m_packaging_params.chunking_params.segment_duration_in_seconds = m_target_duration;
    m_packaging_params.output_media_info = true;

    m_packaging_params.hls_params.playlist_type = shaka::HlsPlaylistType::kLive;
    m_packaging_params.hls_params.master_playlist_output = pl_path;
    m_packaging_params.hls_params.target_segment_duration = m_target_duration;

    m_packaging_params.buffer_callback_params.read_func = [this](const std::string &name,
                                                                 void *buffer, uint64_t size) {
        return this->readInputBuffer(name, buffer, size);
    };

    shaka::StreamDescriptor stream_descriptor;
    stream_descriptor.input = "video";
    stream_descriptor.stream_selector = "video";
    stream_descriptor.output = video_folder + "init.mp4";
    stream_descriptor.skip_encryption = true;
    stream_descriptor.hls_playlist_name = "playlist.m3u8";
    stream_descriptor.hls_only = true;
    m_stream_descriptors.push_back(stream_descriptor);

Inside read_func, I am filling buffer and expecting packaging to produce fragmented mp4 HLS stream. But I am getting below error

[0925/201922:ERROR:demuxer.cc(205)] Failed to detect the container type from the buffer: 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
[error] Packager running failed. 3 (INVALID_ARGUMENT): Failed to detect the container type.

As I understand packager expect already packaged content at the input not the raw encoded data. My question is can I use shaka packager to directly package raw encoded video and encoded audio data? If possible can you also share a minimal example to show buffer callback params usage?

Thanks.

felibol commented 1 year ago

I even tested with first muxing to mpegts at gstreamer and then fill buffer with the mpegts packets but still getting same error at packager.

rantoniello commented 6 months ago

Hi Felibol,

Recently I came across this issue, despite is a bit old: are you still trying to solve it?

Your code should work perfectly, just be careful your TS stream is standard thus having the necessary tables (PAT, PMT, ...), and in the implementation of the function 'readInputBuffer', respect the TS packet boundary (that is, do not "cut" de buffer in the middle of a TS packet). In consequence, for each input buffer, make sure you are synchronizing to TS packet boundary (start code 0x47) and you are sending entire TS packets (once synchronized, you should fill the buffer with a multiple of 188 bytes). Using exactly the same code as yours, I can confirm this works.

Kind Regards.

github-actions[bot] commented 6 months ago

Closing due to inactivity. If this is still an issue for you or if you have further questions, the OP can ask shaka-bot to reopen it by including @shaka-bot reopen in a comment.