Last active
November 11, 2022 16:59
-
-
Save chichunchen/187cf34156388ddb1d0e023e247e00ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <gst/gst.h> | |
| #define BUF_LEN 1000 | |
| char buf[BUF_LEN]; | |
| char *path; | |
| char *name; | |
| int video_segment_cnt = 1; | |
| char *get_uri_from_id(int n); | |
| /* Structure to contain all our information, so we can pass it around */ | |
| typedef struct _CustomData { | |
| GstElement *playbin; /* Our one and only element */ | |
| GMainLoop *main_loop; /* GLib's Main Loop */ | |
| } CustomData; | |
| void prepare_next_stream(GstElement *obj, gpointer userdata) { | |
| g_print("prepare next stream\n"); | |
| CustomData *data = (CustomData*) userdata; | |
| video_segment_cnt++; | |
| if (video_segment_cnt < 196) | |
| g_object_set(G_OBJECT(data->playbin), "uri", | |
| get_uri_from_id(video_segment_cnt), NULL); | |
| } | |
| /* playbin flags */ | |
| typedef enum { | |
| GST_PLAY_FLAG_VIDEO = (1 << 0), /* We want video output */ | |
| GST_PLAY_FLAG_AUDIO = (1 << 1), /* We want audio output */ | |
| GST_PLAY_FLAG_TEXT = (1 << 2) /* We want subtitle output */ | |
| } GstPlayFlags; | |
| char *get_uri_from_id(int n) { | |
| sprintf(buf, "file://%s/%s_%d.mp4", path, name, n); | |
| g_print("log: %s\n", buf); | |
| return buf; | |
| } | |
| /** | |
| * Usage: ./gapless <path of video segments> <name of video segment> | |
| */ | |
| int main(int argc, char *argv[]) { | |
| CustomData data; | |
| GstStateChangeReturn ret; | |
| gint flags; | |
| GIOChannel *io_stdin; | |
| path = argv[1]; | |
| name = argv[2]; | |
| /* Initialize GStreamer */ | |
| gst_init (&argc, &argv); | |
| /* Create the elements */ | |
| data.playbin = gst_element_factory_make ("playbin", "playbin"); | |
| if (!data.playbin) { | |
| g_printerr ("Not all elements could be created.\n"); | |
| return -1; | |
| } | |
| /* Set the URI to play */ | |
| g_object_set (data.playbin, "uri", get_uri_from_id(video_segment_cnt), NULL); | |
| g_signal_connect(data.playbin, "about-to-finish", G_CALLBACK(prepare_next_stream), &data); | |
| /* Start playing */ | |
| ret = gst_element_set_state (data.playbin, GST_STATE_PLAYING); | |
| if (ret == GST_STATE_CHANGE_FAILURE) { | |
| g_printerr ("Unable to set the pipeline to the playing state.\n"); | |
| gst_object_unref (data.playbin); | |
| return -1; | |
| } | |
| /* Create a GLib Main Loop and set it to run */ | |
| data.main_loop = g_main_loop_new (NULL, FALSE); | |
| g_main_loop_run (data.main_loop); | |
| /* Free resources */ | |
| g_main_loop_unref (data.main_loop); | |
| g_io_channel_unref (io_stdin); | |
| gst_element_set_state (data.playbin, GST_STATE_NULL); | |
| gst_object_unref (data.playbin); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment