[FFmpeg-cvslog] libavformat/http.c: Make http-listen work as an input stream.

Stephan Holljes git at videolan.org
Sat Apr 11 23:12:39 CEST 2015


ffmpeg | branch: master | Stephan Holljes <klaxa1337 at googlemail.com> | Sat Apr 11 22:26:57 2015 +0200| [b51027fd18f63d91ea6413a5b73becdaeae7493a] | committer: Michael Niedermayer

libavformat/http.c: Make http-listen work as an input stream.

With this patch http can be used to listen for POST data to be used as an input stream.

Signed-off-by: Stephan Holljes <klaxa1337 at googlemail.com>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b51027fd18f63d91ea6413a5b73becdaeae7493a
---

 doc/protocols.texi |   24 +++++++++++++++++++++++-
 libavformat/http.c |    7 +++++--
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index 5b7b6cf..f822d81 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -279,7 +279,29 @@ Set initial byte offset.
 Try to limit the request to bytes preceding this offset.
 
 @item listen
-If set to 1 enables experimental HTTP server.
+If set to 1 enables experimental HTTP server. This can be used to send data when
+used as an output option, or read data from a client with HTTP POST when used as
+an input option.
+ at example
+# Server side (sending):
+ffmpeg -i somefile.ogg -c copy -listen 1 -f ogg http://@var{server}:@var{port}
+
+# Client side (receiving):
+ffmpeg -i http://@var{server}:@var{port} -c copy somefile.ogg
+
+# Client can also be done with wget:
+wget http://@var{server}:@var{port} -O somefile.ogg
+
+# Server side (receiving):
+ffmpeg -listen 1 -i http://@var{server}:@var{port} -c copy somefile.ogg
+
+# Client side (sending):
+ffmpeg -i somefile.ogg -chunked_post 0 -c copy -f ogg http://@var{server}:@var{port}
+
+# Client can also be done with wget:
+wget --post-file=somefile.ogg http://@var{server}:@var{port}
+ at end example
+
 @end table
 
 @subsection HTTP Cookies
diff --git a/libavformat/http.c b/libavformat/http.c
index 8115272..b2293da 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -128,13 +128,14 @@ static const AVOption options[] = {
     { "end_offset", "try to limit the request to bytes preceding this offset", OFFSET(end_off), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX, D },
     { "method", "Override the HTTP method", OFFSET(method), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
     { "reconnect", "auto reconnect after disconnect before EOF", OFFSET(reconnect), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D },
-    { "listen", "listen on HTTP", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, E },
+    { "listen", "listen on HTTP", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D | E },
     { NULL }
 };
 
 static int http_connect(URLContext *h, const char *path, const char *local_path,
                         const char *hoststr, const char *auth,
                         const char *proxyauth, int *new_location);
+static int http_read_header(URLContext *h, int *new_location);
 
 void ff_http_init_auth_state(URLContext *dest, const URLContext *src)
 {
@@ -305,7 +306,7 @@ static int http_listen(URLContext *h, const char *uri, int flags,
     static const char header[] = "HTTP/1.1 200 OK\r\nContent-Type: application/octet-stream\r\nTransfer-Encoding: chunked\r\n\r\n";
     char hostname[1024];
     char lower_url[100];
-    int port;
+    int port, new_location;
     av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port,
                  NULL, 0, uri);
     ff_url_join(lower_url, sizeof(lower_url), "tcp", NULL, hostname, port,
@@ -316,6 +317,8 @@ static int http_listen(URLContext *h, const char *uri, int flags,
         goto fail;
     if ((ret = ffurl_write(s->hd, header, strlen(header))) < 0)
         goto fail;
+    if ((ret = http_read_header(h, &new_location)) < 0)
+         goto fail;
     return 0;
 
 fail:



More information about the ffmpeg-cvslog mailing list