Bug Report: Unable to Convert H264 Encoded Buffer to MP4 File
Sulthan Amanu
sulthan4380 at gmail.com
Wed Oct 4 14:32:56 UTC 2023
Fwd..
On Wed, 4 Oct 2023 at 19:35, Sulthan Amanu <sulthan4380 at gmail.com> wrote:
> Dear Team,
>
> I have encountered an issue while attempting to convert an H264 encoded
> buffer to an MP4 file using the appsrc element. Unfortunately, I am unable
> to successfully perform this conversion, and I have attached the relevant
> pipeline and code snippet for your reference:
>
> *Pipeline:*
>
> gst-launch-1.0 -e v4l2src device="/dev/video0" ! videoconvert ! queue !
> x264enc tune=zerolatency ! identity ! fakesink
>
>
> I'm utilizing the `identity` element to capture the buffers and store them
> in a buffer list. Subsequently, I am using the following code snippet to
> convert the H264 encoded buffer to an MP4 file:
>
> *Code Snippet:*
>
> void convertToMP4(GstBufferList *buflist)
> {
> // Create pipeline for MP4 conversion.
> GstElement *pipeline, *appsrc, *videoconvert, *x264enc, *h264parse,
> *videoencode, *muxer, *file_sink;
> pipeline = gst_pipeline_new("MP4-pipeline");
> appsrc = gst_element_factory_make("appsrc", "source");
> h264parse = gst_element_factory_make("h264parse", "app-h264parse");
> muxer = gst_element_factory_make("mp4mux", "mux");
> file_sink = gst_element_factory_make("filesink", "filesink");
>
> g_object_set(G_OBJECT(appsrc),
> "stream-type", 0,
> "format", GST_FORMAT_TIME, NULL);
>
> g_object_set(muxer, "fragment-duration", 2000, NULL);
> // g_object_set(h264parse, "config-interval", -1, NULL);
> // g_object_set(x264enc, "tune", 4, NULL);
>
> // Set the resolution and framerate caps
> GstCaps *caps = gst_caps_new_simple("video/x-h264",
> "stream-format", G_TYPE_STRING,
> "byte-stream",
> "width", G_TYPE_INT, 1280,
> "height", G_TYPE_INT, 720,
> "framerate", GST_TYPE_FRACTION,
> 10, 1,
> NULL);
>
> gst_app_src_set_caps(GST_APP_SRC(appsrc), caps);
>
> gst_caps_unref(caps);
>
> g_object_set(file_sink, "location", "DIA_VIDEO_AUDIO.mp4", NULL);
>
> gst_bin_add_many(GST_BIN(pipeline), appsrc, h264parse, muxer,
> file_sink, NULL);
> if (gst_element_link_many(appsrc, h264parse, muxer, file_sink, NULL)
> != TRUE)
> {
> g_printerr("Elements could not be linked in the pipeline.\n");
> gst_object_unref(pipeline);
> exit(1);
> }
>
> copy_buflist = gst_buffer_list_copy_deep(buflist);
> g_print("isbuffered is filled and Buffer size is %d\n",
> gst_buffer_list_length(copy_buflist));
> // Set the pipeline to the PLAYING state.
> gst_element_set_state(pipeline, GST_STATE_PLAYING);
>
> // Push video and audio buffers into appsrc.
> GstFlowReturn retval =
> gst_app_src_push_buffer_list(GST_APP_SRC(appsrc), copy_buflist);
> if (retval != GST_FLOW_OK) {
> g_printerr("Error pushing buffers to appsrc: %s\n",
> gst_flow_get_name(retval));
> // Handle error and cleanup if needed.
> }
>
> bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
> gst_bus_add_signal_watch(bus);
> g_signal_connect(bus, "message::error", G_CALLBACK(cb_message_error),
> NULL);
> g_signal_connect(bus, "message::eos", G_CALLBACK(cb_message_eos),
> NULL);
> }
>
> However, I am encountering the following error:
>
>
> *ERROR*
>
> is buffered is filled, and the Buffer size is 70
>
> MP4 converted /n0:00:08.391637077 18811 0x7fcd6c0040f0 FIXME default
> gstutils.c:3981:gst_pad_create_stream_id_internal:<source:src> Creating a
> random stream-id; consider implementing a deterministic way of creating a
> stream-id
>
> I kindly request your assistance in resolving this issue promptly. Your
> guidance in rectifying this problem will be greatly appreciated.
>
> Best Regards,
> Sulthan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20231004/18bfe4e5/attachment-0001.htm>
More information about the gstreamer-devel
mailing list