参考:https://blog.youkuaiyun.com/sakulafly/article/list/2
https://gstreamer.freedesktop.org/documentation/tutorials/playback/subtitle-management.html
如何获取字幕、音轨、视频流个数,及其具体信息
如何切换字幕,切换音轨,切换视频流
如何外挂一个字幕
如何设置字幕的字体
下面结合播放教程一,实现了以上功能。
#include "pch.h"
//如何选择字幕
//如何添加字幕
//如何定制字幕的字体
#include<string.h>
#include<stdio.h>
#include <gst/gst.h>
typedef struct _CustomData{
GstElement *playbin;
gint n_video;
gint n_audio;
gint n_text;
gint current_video;
gint current_audio;
gint current_text;
GMainLoop *main_loop;
}CustomData;
typedef enum {
GST_PLAY_FLAG_VIDEO = (1 << 0), //we want video output
GST_PALY_FLAG_AUDIO = (1 << 1),
GST_PALY_FLAG_TEXT = (1 << 2)
}GstPlayFlags;
static gboolean handle_message(GstBus *bus, GstMessage *msg, CustomData *data);
static gboolean handle_keyboard(GIOChannel *source, GIOCondition cond, CustomData *data);
int main(int argc, char *argv[]) {
CustomData data;
GstBus *bus;
GstStateChangeReturn ret;
gint flags;
GIOChannel *io_stdin;
gst_init(&argc, &argv);
data.playbin = gst_element_factory_make("playbin", "playbin");
if (!data.playbin) {
g_printerr("could not create playbin\n");
return -1;
}
g_object_set(data.playbin, "uri", "file:///C:/Users/lenovo/Desktop/testVideo/[PGS][Tintin-004][DTS-AC3][5PGS].mkv", NULL);
//外挂字幕地址
g_object_set(data.playbin, "suburi", "file:///C:/Users/lenovo/Desktop/testVideo/shenhua_waigua.srt", NULL);
//设置字幕的字体
g_object_set(data.playbin, "subtitle-font-desc", "Sans,18"