On Wed, Feb 17, 2016 at 10:58 PM, wm4 <nfx...@googlemail.com> wrote:
> On Wed, 17 Feb 2016 22:55:47 +0700
> Muhammad Faiz <mfc...@gmail.com> wrote:
>
>> On Wed, Feb 17, 2016 at 10:20 PM, wm4 <nfx...@googlemail.com> wrote:
>> > On Wed, 17 Feb 2016 21:30:20 +0700
>> > Muhammad Faiz <mfc...@gmail.com> wrote:
>> >
>> >> From 6291c06dacbe2aa48a97bf36835ec8a3bce8a40a Mon Sep 17 00:00:00 2001
>> >> From: Muhammad Faiz <mfc...@gmail.com>
>> >> Date: Wed, 17 Feb 2016 21:21:12 +0700
>> >> Subject: [PATCH] avfilter/src_movie: add various commands
>> >>
>> >> add seek command
>> >> add get_duration command
>> >> ---
>> >>  doc/filters.texi        | 24 ++++++++++++++++++++++++
>> >>  libavfilter/src_movie.c | 37 +++++++++++++++++++++++++++++++++++++
>> >>  2 files changed, 61 insertions(+)
>> >>
>> >
>> >> +static int process_command(AVFilterContext *ctx, const char *cmd, const 
>> >> char *args,
>> >> +                           char *res, int res_len, int flags)
>> >> +{
>> >> +    MovieContext *movie = ctx->priv;
>> >> +    int ret = AVERROR(ENOSYS);
>> >> +
>> >> +    if (!strcmp(cmd, "seek")) {
>> >> +        int idx, flags;
>> >> +        int64_t ts;
>> >> +        char tail[2];
>> >> +
>> >> +        if (sscanf(args, "%i|%"SCNi64"|%i %1s", &idx, &ts, &flags, tail) 
>> >> != 3)
>> >> +            return AVERROR(EINVAL);
>> >> +
>> >> +        return av_seek_frame(movie->format_ctx, idx, ts, flags);
>> >
>> > This can't work correctly. You have to flush the decoder (which you
>> > could easily do, but fail to do here), and the filters (which you can't
>> > do unless you add seeking and/or flushing support to libavfilter).
>> I don't see avformat_flush or avio_flush call on ffplay
>
> No, the decoders.
>

OK, I fix it in new patch
patch attached

Thank's
From ad978fe2627961db167a33c7f30b5501872bb904 Mon Sep 17 00:00:00 2001
From: Muhammad Faiz <mfc...@gmail.com>
Date: Wed, 17 Feb 2016 23:20:08 +0700
Subject: [PATCH] avfilter/src_movie: add various commands

add seek command
add get_duration command
---
 doc/filters.texi        | 24 ++++++++++++++++++++++++
 libavfilter/src_movie.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index 68f54f1..a9eecf1 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -15897,4 +15897,28 @@ movie=dvd.vob:s=v:0+#0x81 [video] [audio]
 @end example
 @end itemize
 
+@subsection Commands
+
+Both movie and amovie support the following commands:
+@table @option
+@item seek
+Perform seek using "av_seek_frame".
+The syntax is: seek @var{stream_index}|@var{timestamp}|@var{flags}
+@itemize
+@item
+@var{stream_index}: If stream_index is -1, a default
+stream is selected, and @var{timestamp} is automatically converted
+from AV_TIME_BASE units to the stream specific time_base.
+@item
+@var{timestamp}: Timestamp in AVStream.time_base units
+or, if no stream is specified, in AV_TIME_BASE units.
+@item
+@var{flags}: Flags which select direction and seeking mode.
+@end itemize
+
+@item get_duration
+Get movie duration in AV_TIME_BASE units.
+
+@end table
+
 @c man end MULTIMEDIA SOURCES
diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
index 82d2bcd..f7b35f4 100644
--- a/libavfilter/src_movie.c
+++ b/libavfilter/src_movie.c
@@ -573,6 +573,49 @@ static int movie_request_frame(AVFilterLink *outlink)
     }
 }
 
+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
+                           char *res, int res_len, int flags)
+{
+    MovieContext *movie = ctx->priv;
+    int ret = AVERROR(ENOSYS);
+
+    if (!strcmp(cmd, "seek")) {
+        int idx, flags, i;
+        int64_t ts;
+        char tail[2];
+
+        if (sscanf(args, "%i|%"SCNi64"|%i %1s", &idx, &ts, &flags, tail) != 3)
+            return AVERROR(EINVAL);
+
+        ret = av_seek_frame(movie->format_ctx, idx, ts, flags);
+        if (ret < 0)
+            return ret;
+
+        for (i = 0; i < ctx->nb_outputs; i++) {
+            avcodec_flush_buffers(movie->st[i].st->codec);
+            movie->st[i].done = 0;
+        }
+        return ret;
+    } else if (!strcmp(cmd, "get_duration")) {
+        int print_len;
+        char tail[2];
+
+        if (!res || res_len <= 0)
+            return AVERROR(EINVAL);
+
+        if (args && sscanf(args, "%1s", tail) == 1)
+            return AVERROR(EINVAL);
+
+        print_len = snprintf(res, res_len, "%"PRId64, movie->format_ctx->duration);
+        if (print_len < 0 || print_len >= res_len)
+            return AVERROR(EINVAL);
+
+        return 0;
+    }
+
+    return ret;
+}
+
 #if CONFIG_MOVIE_FILTER
 
 AVFILTER_DEFINE_CLASS(movie);
@@ -589,6 +632,7 @@ AVFilter ff_avsrc_movie = {
     .inputs    = NULL,
     .outputs   = NULL,
     .flags     = AVFILTER_FLAG_DYNAMIC_OUTPUTS,
+    .process_command = process_command
 };
 
 #endif  /* CONFIG_MOVIE_FILTER */
@@ -610,6 +654,7 @@ AVFilter ff_avsrc_amovie = {
     .outputs    = NULL,
     .priv_class = &amovie_class,
     .flags      = AVFILTER_FLAG_DYNAMIC_OUTPUTS,
+    .process_command = process_command,
 };
 
 #endif /* CONFIG_AMOVIE_FILTER */
-- 
2.5.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to