PR #26316 opened by luoye-cpu
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26316
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26316.patch

This adds an API-level test that demonstrates frame-exact random access on 
H.264 using only existing public mechanisms:

- `av_seek_frame(..., AVSEEK_FLAG_BACKWARD)` to land on the keyframe preceding 
the target
- `avcodec_flush_buffers()` after seeking
- `AVCodecContext.skip_frame = AVDISCARD_NONREF` over the seek interval, so 
non-reference frames are not decoded at all
- a per-packet target exemption: `skip_frame` is switched back to 
`AVDISCARD_NONE` before the target AU is submitted (per-packet effectiveness of 
context fields, including skip_frame, is documented for `avcodec_send_packet()`)
- pixel-exact comparison of the target frame against a full sequential decode 
baseline (per-plane visible-area MD5), plus per-pass packet/decode counts 
quantifying the reduced decode work

The test is registered as `fate-api-gopseek` under the SAMPLES gate, 
self-asserting exit code (CMP=null), against the fate-suite sample 
`h264/interlaced_crop.mp4` (closed GOP, 24-frame GOPs, I=6/P=29/B=91).

Related upstream work this does not overlap with:

- #25842 (merged, AVSEEK_FLAG_PREROLL) and the open #26313 (MPEG-TS 
keyframe-aware seek) / #24508 (keyframe-aware ff_gen_search) operate at the 
container or generic-search layer; this change stays at the application 
orchestration layer and uses the existing seek semantics as-is.
- #24105 (frame-exact extraction from multi-track MP4) documents the demand 
side; this test is not an implementation or fix for that issue.

Limitations, stated up front:

- Target identification relies on `frame->pts`, so the scope is AU-per-packet 
streams with unique PTS; streams with duplicate or missing PTS are out of scope.
- The stream layer is untouched: no decoder or public API changes. `patcheck` 
is clean.

Verified: `make fate-api-gopseek` passes with the sample present; behavior is 
identical with threads=1 and threads=2.


>From 4e3597f6787f32315553ea0165434a38ce8c56fb Mon Sep 17 00:00:00 2001
From: luoye-cpu <[email protected]>
Date: Tue, 24 Nov 2026 18:06:12 +0800
Subject: [PATCH] tests/api: add GOP-aware seek prototype test

Add an API-level test that demonstrates frame-exact random access on
H.264 by combining avformat seek, decoder flush, AVDISCARD_NONREF
non-reference frame skipping over the seek window, and a target-frame
exemption via runtime skip_frame changes (effective per-packet under
frame threading).

The program performs three passes per automatically selected target
(one B and one P frame in the middle GOP range): a full sequential
baseline build-up with per-frame pixel MD5, a plain seek-then-decode
reference pass, and the GOP-aware pass which skips non-reference
frames before the target. It asserts pixel-exact equality of the
target frame across passes and prints per-pass packet/decode counts
to quantify the reduced decode work.

Target identification relies on frame->pts and thus requires streams
where each AU is one packet with a unique PTS; streams with duplicate
or missing PTS are out of scope for this test.

Registered as fate-api-gopseek (CMP=null, self-asserting exit code)
against the fate-suite sample h264/interlaced_crop.mp4.

No decoder or public API changes.

Signed-off-by: luoye-cpu <[email protected]>
---
 tests/api/Makefile           |   1 +
 tests/api/api-gopseek-test.c | 582 +++++++++++++++++++++++++++++++++++
 tests/fate/api.mak           |   5 +
 3 files changed, 588 insertions(+)
 create mode 100644 tests/api/api-gopseek-test.c

diff --git a/tests/api/Makefile b/tests/api/Makefile
index c411e82e5f1..713ff1e0520 100644
--- a/tests/api/Makefile
+++ b/tests/api/Makefile
@@ -3,6 +3,7 @@ APITESTPROGS-$(call ALLYES, LIBASTCENC_ENCODER 
LIBASTCENC_DECODER) += api-astc-p
 APITESTPROGS-$(call ENCDEC, FLAC, FLAC) += api-flac
 APITESTPROGS-$(call DEMDEC, H264, H264) += api-h264
 APITESTPROGS-$(call DEMDEC, H264, H264) += api-h264-slice
+APITESTPROGS-$(call DEMDEC, H264, H264) += api-gopseek
 APITESTPROGS-$(CONFIG_MOV_MUXER)        += api-movenc
 APITESTPROGS-$(CONFIG_MOVTEXT_ENCODER)  += api-movtext
 APITESTPROGS-$(call ALLYES, HEVC_MP4TOANNEXB_BSF HEVC_DECODER) += 
api-hevc-mp4toannexb
diff --git a/tests/api/api-gopseek-test.c b/tests/api/api-gopseek-test.c
new file mode 100644
index 00000000000..e8dd2b9c962
--- /dev/null
+++ b/tests/api/api-gopseek-test.c
@@ -0,0 +1,582 @@
+/*
+ * Copyright (c) 2026 luoye-cpu
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * GOP-aware seek test.
+ *
+ * Verifies that a GOP-aware seek (seek backward to the keyframe preceding the
+ * target, flush the decoder, skip non-reference frames inside the seek
+ * interval, decode until the target frame shows up) produces the same target
+ * frame pixels as a sequential full decode of the whole stream, while
+ * submitting fewer frames to the decoder than a plain seek followed by
+ * sequential decoding.
+ */
+
+#include <string.h>
+
+#include "libavutil/md5.h"
+#include "libavutil/mem.h"
+#include "libavutil/pixdesc.h"
+#include "libavcodec/avcodec.h"
+#include "libavformat/avformat.h"
+
+#define FRAME_MD5_SIZE 16
+
+typedef struct FrameEntry {
+    int64_t pts;
+    uint8_t md5[FRAME_MD5_SIZE];
+    int pict_type;
+} FrameEntry;
+
+typedef struct FrameTable {
+    FrameEntry *entries;
+    int size;
+    int count;
+} FrameTable;
+
+typedef struct Target {
+    int64_t pts;
+    int pict_type;
+} Target;
+
+static const char *file_basename(const char *path)
+{
+    const char *p = strrchr(path, '/');
+    const char *q = strrchr(path, '\\');
+    if (q > p)
+        p = q;
+    return p ? p + 1 : path;
+}
+
+static char pict_type_char(int pict_type)
+{
+    switch (pict_type) {
+    case AV_PICTURE_TYPE_I: return 'I';
+    case AV_PICTURE_TYPE_P: return 'P';
+    case AV_PICTURE_TYPE_B: return 'B';
+    default:                return '?';
+    }
+}
+
+static int frame_table_add(FrameTable *t, int64_t pts, const uint8_t *md5, int 
pict_type)
+{
+    if (t->count >= t->size) {
+        t->size = t->size ? t->size * 2 : 64;
+        t->entries = av_realloc_f(t->entries, t->size, sizeof(*t->entries));
+        if (!t->entries) {
+            av_log(NULL, AV_LOG_ERROR, "Can't allocate array to store frame 
md5s\n");
+            return AVERROR(ENOMEM);
+        }
+    }
+    t->entries[t->count].pts = pts;
+    memcpy(t->entries[t->count].md5, md5, FRAME_MD5_SIZE);
+    t->entries[t->count].pict_type = pict_type;
+    t->count++;
+    return 0;
+}
+
+static const FrameEntry *frame_table_find(const FrameTable *t, int64_t pts)
+{
+    int i;
+    for (i = 0; i < t->count; i++)
+        if (t->entries[i].pts == pts)
+            return &t->entries[i];
+    return NULL;
+}
+
+/* md5 over the visible pixel area of each plane (linesize * height, chroma
+ * planes subsampled), excluding trailing padding bytes. */
+static void compute_frame_md5(struct AVMD5 *md5ctx, const AVFrame *fr,
+                              uint8_t md5[FRAME_MD5_SIZE])
+{
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fr->format);
+    int planes = av_pix_fmt_count_planes(fr->format);
+    int i;
+
+    av_md5_init(md5ctx);
+    if (planes > 3)
+        planes = 3;
+    for (i = 0; i < planes; i++) {
+        int h = fr->height;
+        if (i > 0 && desc)
+            h = AV_CEIL_RSHIFT(fr->height, desc->log2_chroma_h);
+        if (fr->data[i])
+            av_md5_update(md5ctx, fr->data[i], fr->linesize[i] * (size_t)h);
+    }
+    av_md5_final(md5ctx, md5);
+}
+
+static int open_input_and_decoder(const char *input, int threads,
+                                  AVFormatContext **fmt_ctx_out,
+                                  AVCodecContext **ctx_out, int 
*video_stream_out)
+{
+    const AVCodec *codec;
+    AVCodecContext *ctx = NULL;
+    AVFormatContext *fmt_ctx = NULL;
+    AVStream *st;
+    int video_stream, ret;
+
+    *fmt_ctx_out = NULL;
+    *ctx_out = NULL;
+
+    ret = avformat_open_input(&fmt_ctx, input, NULL, NULL);
+    if (ret < 0) {
+        av_log(NULL, AV_LOG_ERROR, "Can't open file %s\n", input);
+        return ret;
+    }
+
+    ret = avformat_find_stream_info(fmt_ctx, NULL);
+    if (ret < 0) {
+        av_log(NULL, AV_LOG_ERROR, "Can't get stream info\n");
+        goto fail;
+    }
+
+    video_stream = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, 
NULL, 0);
+    if (video_stream < 0) {
+        av_log(NULL, AV_LOG_ERROR, "Can't find video stream in input file\n");
+        ret = video_stream;
+        goto fail;
+    }
+
+    st = fmt_ctx->streams[video_stream];
+
+    codec = avcodec_find_decoder(st->codecpar->codec_id);
+    if (!codec) {
+        av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n");
+        ret = AVERROR_DECODER_NOT_FOUND;
+        goto fail;
+    }
+
+    ctx = avcodec_alloc_context3(codec);
+    if (!ctx) {
+        av_log(NULL, AV_LOG_ERROR, "Can't allocate decoder context\n");
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
+
+    ret = avcodec_parameters_to_context(ctx, st->codecpar);
+    if (ret < 0) {
+        av_log(ctx, AV_LOG_ERROR, "Can't copy decoder context\n");
+        goto fail;
+    }
+
+    ctx->thread_count = threads;
+
+    ret = avcodec_open2(ctx, codec, NULL);
+    if (ret < 0) {
+        av_log(ctx, AV_LOG_ERROR, "Can't open decoder\n");
+        goto fail;
+    }
+
+    *fmt_ctx_out = fmt_ctx;
+    *ctx_out = ctx;
+    *video_stream_out = video_stream;
+    return 0;
+
+fail:
+    avcodec_free_context(&ctx);
+    avformat_close_input(&fmt_ctx);
+    return ret;
+}
+
+static int run_baseline(const char *input, int threads, FrameTable *table,
+                        int64_t *key_start_out, int64_t *duration_out)
+{
+    AVFormatContext *fmt_ctx = NULL;
+    AVCodecContext *ctx = NULL;
+    AVStream *st;
+    AVPacket *pkt = NULL;
+    AVFrame *fr = NULL;
+    struct AVMD5 *md5ctx = NULL;
+    int video_stream, input_done = 0, key_seen = 0, ret;
+    int64_t key_start = AV_NOPTS_VALUE, last_pts = AV_NOPTS_VALUE;
+    uint8_t md5[FRAME_MD5_SIZE];
+
+    ret = open_input_and_decoder(input, threads, &fmt_ctx, &ctx, 
&video_stream);
+    if (ret < 0)
+        return ret;
+
+    ctx->skip_frame = AVDISCARD_NONE;
+
+    pkt = av_packet_alloc();
+    fr = av_frame_alloc();
+    md5ctx = av_md5_alloc();
+    if (!pkt || !fr || !md5ctx) {
+        av_log(NULL, AV_LOG_ERROR, "Can't allocate packet/frame/md5 
context\n");
+        ret = AVERROR(ENOMEM);
+        goto end;
+    }
+
+    while (1) {
+        if (!input_done) {
+            ret = av_read_frame(fmt_ctx, pkt);
+            if (ret < 0) {
+                input_done = 1;
+                ret = avcodec_send_packet(ctx, NULL);
+                if (ret < 0 && ret != AVERROR_EOF) {
+                    av_log(ctx, AV_LOG_ERROR, "Error flushing the decoder\n");
+                    goto end;
+                }
+            } else if (pkt->stream_index != video_stream) {
+                av_packet_unref(pkt);
+                continue;
+            } else {
+                if (!key_seen && (pkt->flags & AV_PKT_FLAG_KEY) &&
+                    pkt->pts != AV_NOPTS_VALUE) {
+                    key_start = pkt->pts;
+                    key_seen = 1;
+                }
+                ret = avcodec_send_packet(ctx, pkt);
+                av_packet_unref(pkt);
+                if (ret < 0) {
+                    av_log(ctx, AV_LOG_ERROR, "Error submitting a packet for 
decoding\n");
+                    goto end;
+                }
+            }
+        }
+
+        ret = avcodec_receive_frame(ctx, fr);
+        if (ret == AVERROR(EAGAIN)) {
+            if (input_done)
+                break;
+            continue;
+        }
+        if (ret == AVERROR_EOF)
+            break;
+        if (ret < 0) {
+            av_log(ctx, AV_LOG_ERROR, "Error decoding frame\n");
+            goto end;
+        }
+
+        if (fr->pts == AV_NOPTS_VALUE) {
+            av_log(NULL, AV_LOG_ERROR, "Decoded frame without pts\n");
+            ret = AVERROR_INVALIDDATA;
+            goto end;
+        }
+        compute_frame_md5(md5ctx, fr, md5);
+        ret = frame_table_add(table, fr->pts, md5, fr->pict_type);
+        if (ret < 0)
+            goto end;
+        last_pts = fr->pts;
+        av_frame_unref(fr);
+    }
+
+    st = fmt_ctx->streams[video_stream];
+    if (st->duration != AV_NOPTS_VALUE)
+        *duration_out = st->duration;
+    else if (fmt_ctx->duration != AV_NOPTS_VALUE)
+        *duration_out = av_rescale_q(fmt_ctx->duration, AV_TIME_BASE_Q, 
st->time_base);
+    else if (key_seen && last_pts != AV_NOPTS_VALUE)
+        *duration_out = last_pts - key_start;
+    else
+        *duration_out = AV_NOPTS_VALUE;
+    *key_start_out = key_start;
+
+    ret = 0;
+end:
+    av_freep(&md5ctx);
+    av_frame_free(&fr);
+    av_packet_free(&pkt);
+    avcodec_free_context(&ctx);
+    avformat_close_input(&fmt_ctx);
+    return ret;
+}
+
+static int select_targets(const FrameTable *table, int64_t key_start, int64_t 
duration,
+                          Target *targets)
+{
+    int64_t lo, hi;
+    int first_b = -1, first_p = -1, second_p = -1;
+    int i, n = 0, pick;
+
+    if (duration < 0) {
+        lo = INT64_MIN;
+        hi = INT64_MAX;
+    } else {
+        lo = key_start + duration / 4;
+        hi = key_start + 3 * duration / 4;
+    }
+
+    for (i = 0; i < table->count; i++) {
+        int64_t pts = table->entries[i].pts;
+        int type = table->entries[i].pict_type;
+        if (pts < lo || pts > hi)
+            continue;
+        if (type == AV_PICTURE_TYPE_B && first_b < 0)
+            first_b = i;
+        if (type == AV_PICTURE_TYPE_P) {
+            if (first_p < 0)
+                first_p = i;
+            else if (second_p < 0)
+                second_p = i;
+        }
+    }
+
+    if (first_b >= 0 && first_p >= 0) {
+        targets[n].pts = table->entries[first_b].pts;
+        targets[n++].pict_type = AV_PICTURE_TYPE_B;
+        targets[n].pts = table->entries[first_p].pts;
+        targets[n++].pict_type = AV_PICTURE_TYPE_P;
+    } else if (first_b >= 0) {
+        targets[n].pts = table->entries[first_b].pts;
+        targets[n++].pict_type = AV_PICTURE_TYPE_B;
+    } else if (first_p >= 0) {
+        /* No B frame in the interval: use two distinct P frames instead. */
+        targets[n].pts = table->entries[first_p].pts;
+        targets[n++].pict_type = AV_PICTURE_TYPE_P;
+        if (second_p >= 0) {
+            targets[n].pts = table->entries[second_p].pts;
+            targets[n++].pict_type = AV_PICTURE_TYPE_P;
+        }
+    } else {
+        /* Neither B nor P frame in the interval: widen the search so that at
+         * least one target is always produced. */
+        pick = -1;
+        for (i = 0; i < table->count && pick < 0; i++)
+            if (table->entries[i].pts >= lo && table->entries[i].pts <= hi)
+                pick = i;
+        for (i = 0; i < table->count && pick < 0; i++)
+            if (table->entries[i].pts >= key_start &&
+                table->entries[i].pict_type != AV_PICTURE_TYPE_I)
+                pick = i;
+        for (i = 0; i < table->count && pick < 0; i++)
+            if (table->entries[i].pts > key_start)
+                pick = i;
+        if (pick < 0)
+            pick = 0;
+        targets[n].pts = table->entries[pick].pts;
+        targets[n++].pict_type = table->entries[pick].pict_type;
+    }
+    return n;
+}
+
+static int run_seek_pass(const char *input, int threads, int64_t target_pts, 
int gop_mode,
+                         const uint8_t *expected_md5, int64_t *landed_pts_out,
+                         int *packets_out, int *decoded_out, int *match_out)
+{
+    AVFormatContext *fmt_ctx = NULL;
+    AVCodecContext *ctx = NULL;
+    AVPacket *pkt = NULL;
+    AVFrame *fr = NULL;
+    struct AVMD5 *md5ctx = NULL;
+    int video_stream, input_done = 0, landed_seen = 0, hit = 0, ret;
+    int64_t landed_pts = AV_NOPTS_VALUE;
+    uint8_t md5[FRAME_MD5_SIZE];
+
+    *landed_pts_out = AV_NOPTS_VALUE;
+    *packets_out = 0;
+    *decoded_out = 0;
+    *match_out = 0;
+
+    ret = open_input_and_decoder(input, threads, &fmt_ctx, &ctx, 
&video_stream);
+    if (ret < 0)
+        return ret;
+
+    pkt = av_packet_alloc();
+    fr = av_frame_alloc();
+    md5ctx = av_md5_alloc();
+    if (!pkt || !fr || !md5ctx) {
+        av_log(NULL, AV_LOG_ERROR, "Can't allocate packet/frame/md5 
context\n");
+        ret = AVERROR(ENOMEM);
+        goto end;
+    }
+
+    ret = av_seek_frame(fmt_ctx, video_stream, target_pts, 
AVSEEK_FLAG_BACKWARD);
+    if (ret < 0) {
+        av_log(NULL, AV_LOG_ERROR, "Seek to %"PRId64" failed\n", target_pts);
+        goto end;
+    }
+
+    avcodec_flush_buffers(ctx);
+    ctx->skip_frame = AVDISCARD_NONE;
+
+    while (1) {
+        if (!input_done) {
+            ret = av_read_frame(fmt_ctx, pkt);
+            if (ret < 0) {
+                input_done = 1;
+                ret = avcodec_send_packet(ctx, NULL);
+                if (ret < 0 && ret != AVERROR_EOF) {
+                    av_log(ctx, AV_LOG_ERROR, "Error flushing the decoder\n");
+                    goto end;
+                }
+            } else if (pkt->stream_index != video_stream) {
+                av_packet_unref(pkt);
+                continue;
+            } else {
+                if (!landed_seen && (pkt->flags & AV_PKT_FLAG_KEY)) {
+                    landed_pts = pkt->pts;
+                    landed_seen = 1;
+                }
+                if (gop_mode && pkt->pts != AV_NOPTS_VALUE && pkt->pts < 
target_pts)
+                    ctx->skip_frame = AVDISCARD_NONREF;
+                else
+                    ctx->skip_frame = AVDISCARD_NONE;
+                ret = avcodec_send_packet(ctx, pkt);
+                av_packet_unref(pkt);
+                if (ret < 0) {
+                    av_log(ctx, AV_LOG_ERROR, "Error submitting a packet for 
decoding\n");
+                    goto end;
+                }
+                (*packets_out)++;
+            }
+        }
+
+        ret = avcodec_receive_frame(ctx, fr);
+        if (ret == AVERROR(EAGAIN)) {
+            if (input_done)
+                break;
+            continue;
+        }
+        if (ret == AVERROR_EOF)
+            break;
+        if (ret < 0) {
+            av_log(ctx, AV_LOG_ERROR, "Error decoding frame\n");
+            goto end;
+        }
+        (*decoded_out)++;
+
+        if (fr->pts == target_pts) {
+            compute_frame_md5(md5ctx, fr, md5);
+            *match_out = !memcmp(md5, expected_md5, FRAME_MD5_SIZE);
+            if (!*match_out)
+                av_log(NULL, AV_LOG_ERROR,
+                       "Target frame pts=%"PRId64" pixel md5 mismatch\n", 
target_pts);
+            hit = 1;
+            av_frame_unref(fr);
+            break;
+        }
+        av_frame_unref(fr);
+    }
+
+    if (!hit)
+        av_log(NULL, AV_LOG_ERROR,
+               "Target frame pts=%"PRId64" was not produced after seeking\n", 
target_pts);
+
+    *landed_pts_out = landed_pts;
+    ret = 0;
+end:
+    av_freep(&md5ctx);
+    av_frame_free(&fr);
+    av_packet_free(&pkt);
+    avcodec_free_context(&ctx);
+    avformat_close_input(&fmt_ctx);
+    return ret;
+}
+
+int main(int argc, char **argv)
+{
+    const char *input = NULL;
+    FrameTable table = { NULL, 0, 0 };
+    Target targets[2];
+    const FrameEntry *entry;
+    char *end;
+    int threads = 1, n_targets, failed = 0, k, ret;
+    int64_t key_start, duration;
+    int exit_code = 1;
+
+    for (k = 1; k < argc; k++) {
+        if (!strcmp(argv[k], "-threads")) {
+            if (++k >= argc) {
+                av_log(NULL, AV_LOG_ERROR, "Missing value for -threads\n");
+                return 1;
+            }
+            threads = strtol(argv[k], &end, 10);
+            if (*end != '\0' || threads < 1) {
+                av_log(NULL, AV_LOG_ERROR, "Invalid thread count '%s'\n", 
argv[k]);
+                return 1;
+            }
+        } else if (!input) {
+            input = argv[k];
+        } else {
+            av_log(NULL, AV_LOG_ERROR, "Unexpected extra argument '%s'\n", 
argv[k]);
+            return 1;
+        }
+    }
+    if (!input) {
+        av_log(NULL, AV_LOG_ERROR, "Usage: %s [-threads N] <input>\n", 
argv[0]);
+        return 1;
+    }
+
+    printf("INPUT %s threads=%d\n", file_basename(input), threads);
+
+    ret = run_baseline(input, threads, &table, &key_start, &duration);
+    if (ret < 0)
+        goto end;
+    printf("BASELINE frames=%d\n", table.count);
+
+    if (table.count < 1) {
+        av_log(NULL, AV_LOG_ERROR, "No frames decoded, nothing to test\n");
+        goto end;
+    }
+    if (key_start == AV_NOPTS_VALUE) {
+        av_log(NULL, AV_LOG_ERROR, "No keyframe packet found in the video 
stream\n");
+        goto end;
+    }
+
+    n_targets = select_targets(&table, key_start, duration, targets);
+    if (n_targets < 1) {
+        av_log(NULL, AV_LOG_ERROR, "Could not select any seek target\n");
+        goto end;
+    }
+
+    for (k = 0; k < n_targets; k++) {
+        int normal_packets, normal_decoded, normal_match;
+        int gop_packets, gop_decoded, gop_match;
+        int64_t landed_pts;
+
+        printf("TARGET pts=%"PRId64" type=%c\n", targets[k].pts,
+               pict_type_char(targets[k].pict_type));
+
+        entry = frame_table_find(&table, targets[k].pts);
+        if (!entry) {
+            av_log(NULL, AV_LOG_ERROR, "Internal error: target pts missing 
from baseline\n");
+            goto end;
+        }
+
+        ret = run_seek_pass(input, threads, targets[k].pts, 0, entry->md5,
+                            &landed_pts, &normal_packets, &normal_decoded,
+                            &normal_match);
+        if (ret < 0)
+            goto end;
+        printf("SEEK landed_pts=%"PRId64"\n", landed_pts);
+        printf("PASS-NORMAL packets=%d decoded=%d match=%d\n",
+               normal_packets, normal_decoded, normal_match);
+
+        ret = run_seek_pass(input, threads, targets[k].pts, 1, entry->md5,
+                            &landed_pts, &gop_packets, &gop_decoded, 
&gop_match);
+        if (ret < 0)
+            goto end;
+        printf("PASS-GOP packets=%d decoded=%d match=%d\n",
+               gop_packets, gop_decoded, gop_match);
+
+        if (!normal_match || !gop_match)
+            failed++;
+    }
+
+    printf("SUMMARY targets=%d failed=%d\n", n_targets, failed);
+    exit_code = failed ? 1 : 0;
+
+end:
+    av_freep(&table.entries);
+    return exit_code;
+}
\ No newline at end of file
diff --git a/tests/fate/api.mak b/tests/fate/api.mak
index 1659c7979c0..e69c9f2e943 100644
--- a/tests/fate/api.mak
+++ b/tests/fate/api.mak
@@ -43,6 +43,11 @@ FATE_API_SAMPLES_LIBAVFORMAT-$(call DEMDEC, H264, H264) += 
fate-api-h264-slice
 fate-api-h264-slice: $(APITESTSDIR)/api-h264-slice-test$(EXESUF)
 fate-api-h264-slice: CMD = run $(APITESTSDIR)/api-h264-slice-test$(EXESUF) 2 
$(TARGET_SAMPLES)/h264/crew_cif.nal
 
+FATE_API_SAMPLES_LIBAVFORMAT-$(call DEMDEC, H264, H264) += fate-api-gopseek
+fate-api-gopseek: $(APITESTSDIR)/api-gopseek-test$(EXESUF)
+fate-api-gopseek: CMD = run $(APITESTSDIR)/api-gopseek-test$(EXESUF) 
$(TARGET_SAMPLES)/h264/interlaced_crop.mp4
+fate-api-gopseek: CMP = null
+
 FATE_API_LIBAVFORMAT-yes += $(if $(findstring 
fate-lavf-flv,$(FATE_LAVF_CONTAINER)),fate-api-seek)
 fate-api-seek: $(APITESTSDIR)/api-seek-test$(EXESUF) fate-lavf-flv
 fate-lavf-flv: KEEP_FILES ?= 1
-- 
2.54.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to