GstH264NalUnitType type = gst_h264_nal_unit_type(map.data[0] & 0x1F)用法不正确 在gstreamer1.16.3中提示没有gst_h264_nal_unit_type怎么修改
时间: 2023-12-06 07:02:35 浏览: 34
在 GStreamer 1.16.3 中,`gst_h264_nal_unit_type()` 函数已被弃用,所以编译时会出现找不到该函数的错误。可以使用新的函数 `gst_h264_parser_identify_nalu()` 替代。
例如,你可以这样修改代码:
```
GstH264ParserResult res = gst_h264_parser_identify_nalu(map.data, map.size, &type);
```
这里的 `type` 变量将会存储解析出的 NAL 单元类型。
需要注意的是,`gst_h264_parser_identify_nalu()` 函数需要在使用前初始化 `GstH264Parser` 对象,如下所示:
```
GstH264Parser *parser = gst_h264_parser_new();
...
GstH264ParserResult res = gst_h264_parser_identify_nalu(parser, map.data, map.size, &type);
...
gst_h264_parser_unref(parser);
```
这样就可以解决这个问题了。
相关问题
GstBuffer *buf = GST_PAD_PROBE_INFO_BUFFER (info); GstH264NalUnitType nal_type = GST_H264_NAL_UNIT_TYPE (GST_BUFFER_DATA (buf)[0]);提示error: subscripted value is neither array nor pointer nor vector应该如何修改
这个错误通常是因为缺少包含相应头文件的声明。你需要包含 `gst/codecparsers/gsth264parser.h` 头文件来解决这个问题,该头文件定义了 `gst_h264_nal_unit_type_get_type()` 和 `GST_H264_NAL_UNIT_TYPE()` 宏,使你能够使用 `GST_H264_NAL_UNIT_TYPE()` 宏来获取 `GstH264NalUnitType` 类型的值。修改后的示例代码如下:
```c
#include <gst/gst.h>
#include <gst/codecparsers/gsth264parser.h>
static GstPadProbeReturn
sps_pps_probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
{
GstBuffer *buf = GST_PAD_PROBE_INFO_BUFFER (info);
GstH264NalUnitType nal_type = GST_H264_NAL_UNIT_TYPE (GST_BUFFER_DATA (buf)[0]);
if (nal_type == GST_H264_NAL_SPS) {
// This is an SPS unit
guint8 *sps = GST_BUFFER_DATA (buf);
guint sps_len = GST_BUFFER_SIZE (buf);
// Do something with the SPS data
} else if (nal_type == GST_H264_NAL_PPS) {
// This is a PPS unit
guint8 *pps = GST_BUFFER_DATA (buf);
guint pps_len = GST_BUFFER_SIZE (buf);
// Do something with the PPS data
}
return GST_PAD_PROBE_OK;
}
int main(int argc, char *argv[]) {
GstElement *pipeline, *source, *h264parse;
GstBus *bus;
GstMessage *msg;
/* Initialize GStreamer */
gst_init(&argc, &argv);
/* Create the elements */
source = gst_element_factory_make("filesrc", "source");
h264parse = gst_element_factory_make("h264parse", "h264parse");
/* Create the pipeline */
pipeline = gst_pipeline_new("test-pipeline");
/* Build the pipeline */
gst_bin_add_many(GST_BIN(pipeline), source, h264parse, NULL);
gst_element_link_many(source, h264parse, NULL);
/* Set the input file */
g_object_set(G_OBJECT(source), "location", "test.h264", NULL);
/* Register the SPS/PPS probe */
GstPad *h264parse_src_pad = gst_element_get_static_pad(h264parse, "src");
gst_pad_add_probe(h264parse_src_pad, GST_PAD_PROBE_TYPE_BUFFER, sps_pps_probe_cb, NULL, NULL);
/* Start playing */
gst_element_set_state(pipeline, GST_STATE_PLAYING);
/* Wait until error or end of the stream */
bus = gst_element_get_bus(pipeline);
msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
if (msg != NULL) {
gst_message_unref(msg);
}
/* Free resources */
gst_object_unref(bus);
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);
return 0;
}
```
请确保你已经正确安装了 GStreamer 和相关的插件,以及包含了正确的头文件和库文件。
static GstPadProbeReturn probe_callback(GstPad *pad, GstPadProbeInfo *info, gpointer user_data) { GstBuffer *buf = GST_BUFFER(info->data); GstMapInfo map; if (gst_buffer_map(buf, &map, GST_MAP_READ)) { GstH264NalUnitType type = gst_h264_nal_unit_type(map.data[0] & 0x1F); if (type == GST_H264_NAL_SPS) { // Found SPS // Parse profile information from SPS } else if (type == GST_H264_NAL_PPS) { // Found PPS // Parse profile information from PPS } gst_buffer_unmap(buf, &map); } return GST_PAD_PROBE_OK; } GstPad *parser_src = gst_element_get_static_pad(parser, "src"); gst_pad_add_probe(parser_src, GST_PAD_PROBE_TYPE_BUFFER, probe_callback, NULL, NULL);中如何获取到profile_idc、constraint_setN_flag、level_idc
在probe_callback回调函数中,当解析出SPS或PPS时,你可以从相应的数据包中获取到profile_idc、constraint_setN_flag、level_idc等参数。具体的方法是,从SPS或PPS数据包的特定位置读取这些参数的值。具体来说,profile_idc位于SPS或PPS数据包的第二个字节的第5~8位(4个比特)中,可以通过下面的代码获取:
```
uint8_t profile_idc = map.data[1] & 0x7F;
```
constraint_setN_flag位于SPS或PPS数据包的第三个字节中,具体位置和含义可以参考H.264/AVC标准的相关文档。level_idc位于SPS或PPS数据包的第四个字节中,具体位置和含义也可以参考H.264/AVC标准的相关文档。你可以根据需要从相应的字节位置读取这些参数的值。
需要注意的是,由于SPS和PPS数据包的格式和语法比较复杂,需要使用一些H.264/AVC相关的库或工具来解析这些数据包。在这段代码中,使用了GStreamer提供的gst_h264_nal_unit_type函数,来解析SPS或PPS数据包中NAL单元的类型,以判断当前数据包是否为SPS或PPS。如果你需要更详细的信息和解析方法,可以参考H.264/AVC标准和相关的开源库或工具的文档。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)