我用 Gstreamer 编写应用程序从电视台录制:
管道创建文件接收器:
#include <gio/gio.h>
Encoder* recording_start (const char* filename)
{
------------------------------------------------------------
GstElement *filesink;
gchar *path;
filesink = gst_element_factory_make ("filesink", NULL);
g_return_val_if_fail (filesink != NULL, NULL);
path = g_strdup_printf("%s.mov", filename);
g_object_set(G_OBJECT(filesink), "location", path, NULL);
gst_bin_add_many (GST_BIN (pipeline), source, encodebin, filesink, NULL);
if (!gst_element_link_many (source, encodebin, filesink, NULL)) {
gst_object_unref (pipeline);
g_return_val_if_reached (NULL);
}
gst_element_set_state (pipeline, GST_STATE_PLAYING);
Encoder *encoder = g_malloc0(sizeof(Encoder));
Encoder->filename = path;
return encoder;
}
录音站的文件名由以下方式生成:
/* args for this format are:
* path
* station title
* time
*/
char *filename = g_strdup_printf (_("%s/%s_%s.mov"), destination, station, time);
我使用 GFile 查询有关记录文件的信息(指向记录文件的指针):
file = g_file_new_for_path (encoder->filename);
用户可以从组合框中选择他们想要录制的电台,例如:
--------------
| STATION 1 |
--------------
| STATION 2 |
--------------
| STATION 3 |
--------------
当站名包含以下字符组合时:“< /” 例如:
-----------------------
| Canal Algérie </ 10 |
-----------------------
应用程序获取错误:
ERROR: from element /GstFileSink:filesink3: Could not open file "/home/ubuntu/</_20130728-044308.mov" for writing.
Additional debug info:
gstfilesink.c(420): gst_file_sink_open_file (): /GstPipeline:pipeline/GstFileSink:filesink3:
system error: No such file or directory
然后崩溃
当原始文件路径包含保留字符或不存在(GIO 返回有效路径)时,为什么应用程序会崩溃?
如果我从车站名称中删除“<”:“Canal Algérie / 10”,一切都很好,应用程序不会崩溃。
谢谢