[FFmpeg-user] Example C code for encoding/muxing/streaming

JULIAN GARDNER joolzg at btinternet.com
Sat Nov 1 11:34:56 CET 2014


>________________________________

> From: JULIAN GARDNER <joolzg at btinternet.com>
>To: FFmpeg user questions <ffmpeg-user at ffmpeg.org> 
>Sent: Wednesday, 29 October 2014, 14:34
>Subject: [FFmpeg-user] Example C code for encoding/muxing/streaming
> 
>
>Ive been
 playing with the code and have a little test project I want to try, a mosaic generator.
>
>Now Ive been looking through the examples code and tried a few but none seem to be able to stream out over multicast.
>
>Has anybody got code/knows of example code which shows how to setup a stream which will output a mpegts to a udp multicast address.
>
>I think i have most of the other code from the examples.
>
>The mosaic will work this way
>
>X streams in, running in threads which will send each I frame to the encoding thread, this thread will
 resize the incoming frame to the correct size and then put it in the correct place on the output frame.
>
>The output frame will then be encoded and streamed out, this is the part that i cannot find any code for.
>
>Ive tried ffmpeg for this but when dealing with 9 streams (3x3) the startup time is way to long and it does not auto restart a broken stream, which Im trying to overcome.
>
>Any help/involvment would be gratefully received
>
>joolz


OK its working!!!!!, but i need some help on a little
 problem with my code. snippet below


....
    /* initialize packet, set data to NULL, let the demuxer fill it */
    av_init_packet(&myframe->pkt);
    inputSource->pkt.data = NULL;
    inputSource->pkt.size = 0;

    /* read frames from the file */
    while (!inputSource->quit && !stop_all_tasks && av_read_frame(inputSource->fmt_ctx, &inputSource->pkt) >= 0) {
        AVPacket orig_pkt = inputSource->pkt;
        do {
            ret = decode_packet(&got_frame, 0, inputSource);
            if (ret < 0)
                break;
            inputSource->pkt.data += ret;
            inputSource->pkt.size -= ret;
        } while (inputSource->pkt.size > 0);
        av_free_packet(&orig_pkt);
    }


I then added a callback but this never seems to be called!!!

static int interrupt_cb(void *ctx)
{
    inputMosaic *inputSource = ctx;

    printf( "."); fflush( stdout);
    if (inputSource->quit || stop_all_tasks)
        return 1;

    return 0;
} 


and in the inputThread

    inputSource->fmt_ctx->interrupt_callback.callback = interrupt_cb;
    inputSource->fmt_ctx->interrupt_callback.opaque = myframe;


Now as this is running in a thread it works well as long as THERE IS data. if no data then this loop just stays here and
 I cannot kill it when I need to switch the input stream or even close down.


Anyone help on this.

joolz


More information about the ffmpeg-user mailing list