理解Gstreamer

1 投票
1 回答
1488 浏览
提问于 2025-04-19 23:34

好的,大家,我以为在玩了几天gstreamer之后我能理解它了。我写了一些看起来合理的管道,但在保存流到文件时我头疼。

gst-launch-1.0 rtspsrc location=rstp://ip/url ! decodebin ! textoverlay text="Work you damn thing " ! x264enc ! h264parse ! mp4mux ! filesink location=some_video.mp4

这是我的逻辑:

 1. rtspsrc - has one pad and it's src it outputs x/rtps
 2. decodebin - is a bin (bunch of elements) it has ghost pads and one of those
    sink pads accept x/rtps then on source pad it generates raw video
 4. x264enc - accepts raw video on sink pad and encodes it to a h264 raw
    video
 5. h264parse - accepts raw h264 on sink and it parse it to h264 video
 6. mp4mux - muxing it
 7. filesink - it sinks it to a file

一切都很好,但在我完成录制后,当我尝试播放它时却遇到了这个错误:

这个文件没有可播放的流

如果有一些gstreamer的老手在这里,我想请教一下我的逻辑哪里出了问题,以及这个错误的原因是什么?

1 个回答

8

你需要向管道发送一个EOS事件,然后在管道的总线上等待EOS消息,只有等到这个消息后才能关闭管道(把状态从播放变为准备或空闲)。

如果你使用的是gst-launch-1.0,可以加上-e这个参数。当你按下ctrl+c的时候,它会在关闭所有东西之前先完成这个步骤。

这样做是因为最后mp4mux需要完成文件的处理,并把完整流的信息写入文件里。否则,生成的文件就不是一个有效的MP4文件。

撰写回答