0

I have three very similar videos, but seek does not work with one of them. I'm trying to understand why so I can fix it. The problem can be demonstrated using the following short piece of code.

#include <gst/gst.h>
#include <stdio.h>
#include <Windows.h>

const char* PLAYBIN_URI = "URI HERE";

int main(int argc, char* argv[])
{
    gst_init(&argc, &argv);

    GstElement *playbin_v = gst_element_factory_make("playbin", "bin_v");
    g_object_set(playbin_v, "flags", 1, "uri", PLAYBIN_URI, NULL);
    gst_element_set_state(playbin_v, GST_STATE_PLAYING);

    Sleep(5000);
    gboolean result = gst_element_seek_simple(playbin_v, GST_FORMAT_TIME, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT), 240000000000);
    fprintf(stderr, "Result of gst_element_seek_simple is %u", result);

    Sleep(1000000);
    return 0;
}

Example 1: Good URI

You need to run the following command with a recent version of yt-dlp. The resulting link expires after a few hours, so I cannot provide one:

yt-dlp -f 22 --get-url https://www.youtube.com/watch?v=t7XDdXdap4w

The resulting link is a very long URL from the googlevideo.com domain. Set PLAYBIN_URI to this.

gst_element_seek_simple will return 1, and the video will seek. What you will see is 5 seconds of a man talking, then the video jumps to a shot of food cooking in a red pot on a stove.

Example 2: Bad URI

Use the link from this command:

yt-dlp -f 136 --get-url https://www.youtube.com/watch?v=t7XDdXdap4w

gst_element_seek_simple will return 0 and the video will NOT seek.

Example 3: Good URI (same video as example 2)

Take the url from example 2, and download it. So open it up in chrome, right click and select "save as". The result is a "videoplayback.mp4" file that is 62mb in size.

Set the PLAYBIN_URI to this file (e.g. PLAYBIN_URI = "file:///c:/videos/videoplayback.mp4";)

gst_element_seek_simple will now return 1, and the video will seek.

Other Notes

My bad video is not an isolated example. Some (but not all) of the URLs that yt-dlp return for videos with VCODEC=avc1 have this odd behaviour where playbin cannot seek if it's playing the url, but it can seek if it's playing the downloaded mp4 file.

Things that I've tried, which don't make a difference:

  • Setting the pipeline to PAUSE before doing the seek. This seems to make no difference. (The pause succeeds, the video does indeed pause)
  • Using gst_element_seek instead of gst_element_seek_simple.
  • Setting playbin's buffer properties to very high values
  • Changing playbin's flags from 1 (VIDEO) to 3 (VIDEO+AUDIO)

Anyone got any guesses as to what the problem is? I notice there are lots of possible values for seek flags but I don't quite understand what all of them mean. Should I try a different seek method?

0 Answers0