#include <stdio.h>
#include <libavformat/avformat.h>

#define src_filename argv[1]

int main (int argc, char **argv)
{
    int r;
    AVFormatContext *fmt_ctx = NULL;

    /* register all formats and codecs */
    av_register_all();

    /* open input file, and allocate format context */
    if (avformat_open_input(&fmt_ctx, src_filename, NULL, NULL) < 0) {
        fprintf(stderr, "Could not open source file %s\n", src_filename);
        exit(1);
    }

    /* retrieve stream information */
    if (avformat_find_stream_info(fmt_ctx, NULL) < 0) {
        fprintf(stderr, "Could not find stream information\n");
        exit(1);
    }

    r = av_seek_frame(fmt_ctx, -1, fmt_ctx->start_time, AVSEEK_FLAG_BACKWARD/* | AVSEEK_FLAG_ANY*/);
    printf("av_seek_frame=%d\n", r);

    avformat_close_input(&fmt_ctx);

    return 0;
};
