[FFmpeg-devel] [PATCH 1/2] Sent fixed amount frames.

Rick van der Zwet info at rickvanderzwet.nl
Sun Mar 4 14:09:02 CET 2012


For an JPEG picture only an single frame should be sent and next the connection
should be terminated. This more generic appoch allows to specify frames you you
would with MaxTime.

Signed-off-by: Rick van der Zwet <info at rickvanderzwet.nl>
---
 ffserver.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/ffserver.c b/ffserver.c
index bddcb7d..b02d0b4 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -140,6 +140,7 @@ typedef struct HTTPContext {
     int feed_fd;
     /* input format handling */
     AVFormatContext *fmt_in;
+    int64_t sent_frame_count;
     int64_t start_time;            /* In milliseconds - this wraps fairly often */
     int64_t first_pts;            /* initial pts value */
     int64_t cur_pts;             /* current pts value from the stream in us */
@@ -220,6 +221,7 @@ typedef struct FFStream {
     int nb_streams;
     int prebuffer;      /* Number of millseconds early to start */
     int64_t max_time;      /* Number of milliseconds to run */
+    int64_t max_frames;    /* Number of frames to run */
     int send_on_key;
     AVStream *streams[MAX_STREAMS];
     int feed_streams[MAX_STREAMS]; /* index of streams in the feed */
@@ -2181,6 +2183,7 @@ static int open_input_stream(HTTPContext *c, const char *info)
         av_seek_frame(c->fmt_in, -1, stream_pos, 0);
     /* set the start time (needed for maxtime and RTP packet timing) */
     c->start_time = cur_time;
+    c->sent_frame_count = 0;
     c->first_pts = AV_NOPTS_VALUE;
     return 0;
 }
@@ -2408,6 +2411,12 @@ static int http_prepare_data(HTTPContext *c)
                         av_free_packet(&pkt);
                         goto redo;
                     }
+
+                    c->sent_frame_count++;
+                    if (c->stream->max_frames &&
+                        c->sent_frame_count >= c->stream->max_frames)
+                        /* We have served enough frames */
+                        c->state = HTTPSTATE_SEND_DATA_TRAILER;
                 }
                 av_free_packet(&pkt);
             }
@@ -4320,6 +4329,10 @@ static int parse_ffconfig(const char *filename)
             get_arg(arg, sizeof(arg), &p);
             if (stream)
                 stream->max_time = atof(arg) * 1000;
+        } else if (!av_strcasecmp(cmd, "MaxFrames")) {
+            get_arg(arg, sizeof(arg), &p);
+            if (stream)
+                stream->max_frames = atof(arg);
         } else if (!av_strcasecmp(cmd, "AudioBitRate")) {
             get_arg(arg, sizeof(arg), &p);
             if (stream)
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list