[Libav-user] How to redirect FFMPEG output to a socket

Wagner Patriota wagner.patriota at gmail.com
Fri May 4 19:10:51 CEST 2012


yes... sure...
this is still a skeleton, but it's already working...

In MY CASE, I have a socket already open... sending and receiving some
information already... I need to use the same socket to send the output of
ffmpeg... everything I do is "equivalent" to type, for example: "ffmpeg -i
inputfile *socket://8989*"

so my application send the output to the socket with handle 8989... the
code below is enough... maybe I will do some optmization later, but it
works pretty fine.

If you want to write do some buffer, you should pass the buffer address
with socket_open, save the address in priv_data, as I did, and then
use socket_write to write to this buffer... of couse, use appropriate names
for it... and I am not completely sure about what you want so I am not sure
if this is the best solution for you... but the idea is to make your own
URLProtocol... :-)

static int socket_write(URLContext *h, const unsigned char *buf, int size)
{
    int *socketHandleInt32 = (int*)h->priv_data;
    int r = send(*socketHandleInt32, buf, size, 0);
    return (-1 == r) ? AVERROR(errno) : r;
}

static int socket_get_handle(URLContext *h)
{
    return *(int*)h->priv_data;
}

static int socket_check(URLContext *h, int mask)
{
    return 0;
}

static int socket_open(URLContext *h, const char *socketHandle, int flags)
{
    int * socketHandleInt32 = av_malloc( sizeof(int) );

    socketHandle += 9; // skip "socket://"
    h->priv_data = socketHandleInt32;

    *socketHandleInt32 = atoi( socketHandle );

    return 0;
}

static int socket_close(URLContext *h)
{
    int *socketHandleInt32 = (int*)h->priv_data;
    return !close(*socketHandleInt32);
}

URLProtocol ff_socket_protocol = {
    .name                = "socket",
    .url_open            = socket_open,
    .url_write           = socket_write,
    .url_close           = socket_close,
    .url_get_file_handle = socket_get_handle,
    .url_check           = socket_check,
};


On Thu, May 3, 2012 at 4:54 PM, Denis <info at denisgottardello.it> wrote:

> In data giovedì 03 maggio 2012 21:39:36, Wagner Patriota ha scritto:
> > Hey guys, sorry... but it's VERY VERY simple... I did it in about 10 or
> 15
> > minutes after I figured out how URLProtocol works...
> >
> > I just rewrote the URLProtocol... that's it... I created a new one, based
> > on file.c and then I rewrote all the functions to write in my socket...
> it
> > worked right in the first time.
>
> Can you post an example?
> Can this method be used for send not to a socket but to a memory buffer?
>
> --
> www.denisgottardello.it
> Skype: mrdebug
> Videosurveillance and home automation!
> http://www.denisgottardello.it/DomusBoss/DomusBossIndice.php
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20120504/3e6695f5/attachment.html>


More information about the Libav-user mailing list