gstreamer:将音频流拆分为文件
我有一个音频流,我想保存为单个可播放的文件,按时间分割 如果我理解正确,splitmuxsink会对视频文件执行此操作,但不会对仅音频文件执行此操作 这里有一些关于如何实现这一点的提示:gstreamer:将音频流拆分为文件,gstreamer,Gstreamer,我有一个音频流,我想保存为单个可播放的文件,按时间分割 如果我理解正确,splitmuxsink会对视频文件执行此操作,但不会对仅音频文件执行此操作 这里有一些关于如何实现这一点的提示: 我正在努力重现这一点,提到的函数是针对gstreamer-0.1的。从splitmuxsink的描述来看,似乎包含了音频: Pad Templates: SINK template: 'video' Availability: On request Capabilities: A
我正在努力重现这一点,提到的函数是针对gstreamer-0.1的。从
splitmuxsink
的描述来看,似乎包含了音频:
Pad Templates:
SINK template: 'video'
Availability: On request
Capabilities:
ANY
SINK template: 'audio_%u'
Availability: On request
Capabilities:
ANY
SINK template: 'subtitle_%u'
Availability: On request
Capabilities:
ANY
所以我不明白为什么纯音频文件不能与它一起使用。尤其是因为视频文件通常被视为仅包含音频的视频文件
编辑以下命令应生成每1分钟长的AC3/MP4文件:
gst-launch-1.0 -e audiotestsrc ! avenc_ac3 ! ac3parse ! mux.audio_0 splitmuxsink name=mux max-size-time=60000000000 location=out_%d.mp4
在C语言中,我使用动态流水线进行ogg编码的音频文件分割 Florian Zwoch在前面的回答中展示了splitmuxsink如何分割音频流 使用动态管道拆分文件的解决方法:
#include <stdio.h>
#define GLIB_DISABLE_DEPRECATION_WARNINGS
#include <gst/gst.h>
static GstElement *pipeline;
static GstPad *queue_src_pad;
static GstElement *bins[2];
static GstPad *bin_pads[2];
static GstElement *filesink[2];
static size_t current_bin = 0;
static size_t current_file = 0;
static GstPadProbeReturn
pad_probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data) {
gst_pad_remove_probe (pad, GST_PAD_PROBE_INFO_ID (info));
gst_pad_unlink(queue_src_pad, bin_pads[current_bin]);
gst_pad_send_event(bin_pads[current_bin], gst_event_new_eos());
gst_bin_remove(GST_BIN(pipeline), bins[current_bin]);
gst_element_set_state(bins[current_bin], GST_STATE_NULL);
current_file++;
current_bin = (current_file % 2);
{
char file_location[32];
sprintf(file_location, "recording_%ld.ogg", current_file);
g_object_set(G_OBJECT(
filesink[current_bin]), "location", file_location, NULL);
printf("now writing to %s\n", file_location);
}
gst_bin_add(GST_BIN(pipeline), bins[current_bin]);
gst_pad_link(queue_src_pad, bin_pads[current_bin]);
gst_element_sync_state_with_parent(bins[current_bin]);
return GST_PAD_PROBE_OK;
}
static gboolean timeout_cb(gpointer user_data) {
gst_pad_add_probe (queue_src_pad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
pad_probe_cb, NULL, NULL);
return TRUE;
}
int main(int argc, char *argv[]) {
GstElement *audiosrc, *queue;
GstElement *vorbisenc[2], *oggmux[2];
GstBus *bus;
GMainLoop *loop;
gst_init (&argc, &argv);
//audiosrc = gst_element_factory_make("audiotestsrc", "audiosrc");
//g_object_set (G_OBJECT (audiosrc), "is-live", TRUE, NULL);
audiosrc = gst_element_factory_make("pulsesrc", "audiosrc");
queue = gst_element_factory_make("queue", "queue");
bins[0] = gst_bin_new ("bin0");
bins[1] = gst_bin_new ("bin1");
vorbisenc[0] = gst_element_factory_make("vorbisenc", "vorbisenc0");
vorbisenc[1] = gst_element_factory_make("vorbisenc", "vorbisenc1");
oggmux[0] = gst_element_factory_make("oggmux", "oggmux0");
oggmux[1] = gst_element_factory_make("oggmux", "oggmux1");
filesink[0] = gst_element_factory_make("filesink", "filesink0");
filesink[1] = gst_element_factory_make("filesink", "filesink1");
pipeline = gst_pipeline_new ("test-pipeline");
if (!pipeline || !audiosrc || !queue
|| !vorbisenc[0] || !oggmux[0] || !filesink[0]
|| !vorbisenc[1] || !oggmux[1] || !filesink[1]
) {
g_printerr ("not all elements could be created\n");
return -1;
}
gst_bin_add_many(
GST_BIN(bins[0]), vorbisenc[0], oggmux[0], filesink[0], NULL);
gst_bin_add_many(
GST_BIN(bins[1]), vorbisenc[1], oggmux[1], filesink[1], NULL);
gst_bin_add_many(
GST_BIN(pipeline), audiosrc, queue, bins[0], NULL);
g_assert (gst_element_link(audiosrc, queue));
g_assert (gst_element_link_many(
vorbisenc[0], oggmux[0], filesink[0], NULL));
g_assert (gst_element_link_many(
vorbisenc[1], oggmux[1], filesink[1], NULL));
{
GstPad* pad = gst_element_get_static_pad(vorbisenc[0], "sink");
gst_element_add_pad(bins[0], gst_ghost_pad_new("sink", pad));
gst_object_unref(pad);
}
{
GstPad* pad = gst_element_get_static_pad(vorbisenc[1], "sink");
gst_element_add_pad(bins[1], gst_ghost_pad_new("sink", pad));
gst_object_unref(pad);
}
bin_pads[0] = gst_element_get_static_pad(bins[0], "sink");
bin_pads[1] = gst_element_get_static_pad(bins[1], "sink");
current_bin = 0;
gst_element_link(queue, bins[current_bin]);
g_object_set (filesink[current_bin], "location", "recording_0.ogg", NULL);
queue_src_pad = gst_element_get_static_pad (queue, "src");
bus = gst_element_get_bus (pipeline);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
loop = g_main_loop_new (NULL, FALSE);
g_timeout_add_seconds (3, timeout_cb, NULL);
g_main_loop_run (loop);
gst_object_unref (bus);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
return 0;
}
#包括
#定义GLIB\u禁用\u弃用\u警告
#包括
静态GstElement*管道;
静态GstPad*队列_src _pad;
静态GstElement*存储箱[2];
静态GstPad*bin_焊盘[2];
静态GstElement*文件链接[2];
静态大小\u t当前\u bin=0;
静态大小\u t当前\u文件=0;
静态GSTPADProbe返回
pad_probe_cb(GstPad*pad,GstPadProbeInfo*info,gpointer用户_数据){
gst_焊盘_移除_探头(焊盘,gst_焊盘_探头_信息_ID(信息));
gst_pad_unlink(队列_src_pad,bin_pad[当前_bin]);
gst_pad_send_事件(bin_pad[当前_bin],gst_事件_new_eos());
gst_-bin_移除(gst_-bin(管道)、料仓[当前料仓]);
gst\u元素\u集合\u状态(bins[当前\u bin],gst\u状态\u NULL);
当前_文件++;
当前\u bin=(当前\u文件%2);
{
字符文件_位置[32];
sprintf(文件位置,“录制文件%ld.ogg”,当前文件);
g_对象集(g_对象(
文件链接[当前位置],“位置”,文件位置,空);
printf(“正在写入%s\n”,文件位置);
}
gst_bin_add(gst_bin(管道),bin[当前_bin]);
gst_pad_链接(队列_src_pad,bin_pad[当前_bin]);
gst元素与父项同步状态(bin[当前bin]);
返回GST\u焊盘\u探头\u正常;
}
静态gboolean超时\u cb(gpointer用户\u数据){
gst\U焊盘\U添加\U探头(队列\U src\U焊盘、gst\U焊盘\U探头\U类型\U块\U下游、,
pad_探头_cb,空,空);
返回TRUE;
}
intmain(intargc,char*argv[]){
GstElement*audiosrc,*队列;
GstElement*vorbisenc[2],*oggmux[2];
GstBus*总线;
GMainLoop*循环;
gst_init(&argc,&argv);
//audiosrc=gst元素工厂制造(“audiotestsrc”、“audiosrc”);
//g_object_set(g_object(audiosrc),“是活动的”,TRUE,NULL);
audiosrc=gst、元件、工厂制造(“pulsesrc”、“audiosrc”);
队列=gst元素工厂制造(“队列”、“队列”);
bins[0]=gst_bin_new(“bin0”);
bins[1]=gst_bin_new(“bin1”);
vorbisenc[0]=gst元素工厂制造(“vorbisenc”、“vorbisenc0”);
vorbisenc[1]=gst元素工厂制造(“vorbisenc”、“vorbisenc1”);
oggmux[0]=商品及服务税(gst)要素(gst)工厂(oggmux,oggmux0);
oggmux[1]=商品及服务税(gst)元素工厂制造(“oggmux”、“oggmux1”);
filesink[0]=gst元素工厂制造(“filesink”、“filesink0”);
filesink[1]=gst元素工厂制造(“filesink”、“filesink1”);
管道=gst_管道_新(“测试管道”);
如果(!pipeline | | |!audiosrc | |!队列
||!vorbisenc[0]| |!oggmux[0]| |!filesink[0]
||!vorbisenc[1]| |!oggmux[1]| |!filesink[1]
) {
g_printerr(“不是所有元素都可以创建\n”);
返回-1;
}
商品及服务税(gst)
GST_-BIN(BIN[0]),vorbisenc[0],oggmux[0],filesink[0],NULL);
gst\u bin\u添加\u许多(