Newest 'ffmpeg' Questions - Stack Overflow

http://stackoverflow.com/questions/tagged/ffmpeg

Les articles publiés sur le site

  • Inserting User Data in Mpeg stream

    28 novembre 2016, par hzrari

    Is there any way to insert User Data (Start code = 0X1B2) in a MPEG stream? What I am looking for is a simple tool, script or some tips using and Hex Editor...

    Or you may have a patch for ffmpeg (libavcodec and libavformat) that allows to do that?

  • Remuxing RTMP stream into mpegts using ffmpeg

    28 novembre 2016, par maziar esfandiarpoor

    So I'm trying to remux a live rtmp stream which is in flv format into mpegts. My code is working; however it stops after like an hour without any errors, it just stucks at av_read_frame! And I know for sure that there is nothing wrong with the rtmp stream beacause I can play it with ffplay for hours and it keeps running without any problems.

    AVOutputFormat *ofmt = NULL;
    AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
    AVPacket pkt;
    int ret, i;
    
    //custom avio
    AVIOContext *avio_ctx = NULL;
    uint8_t *avio_ctx_buffer = NULL;
    
    
    av_register_all();
    avformat_network_init();
    
    ifmt_ctx = avformat_alloc_context();
    
    av_dump_format(ifmt_ctx, 0, input_pipe_name.c_str(), 0);
    if ((ret = avformat_open_input(&ifmt_ctx,"rtmp_url",  0, NULL)) < 0) {
        printf( "Could not open rtmp url.");
        return 1;
    }
    if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) < 0) {
        printf( "Failed to retrieve input stream information");
        return 1;
    }
    av_dump_format(ifmt_ctx, 0, "rtmp_url", 0);
    avformat_alloc_output_context2(&ofmt_ctx, NULL, "mpegts", NULL);
    if (!ofmt_ctx) {
        printf( "Could not create output context\n");
        ret = AVERROR_UNKNOWN;
        return 1;
    }
    ofmt = ofmt_ctx->oformat;
    for (i = 0; i < ifmt_ctx->nb_streams; i++) {
        //Create output AVStream according to input AVStream
        AVStream *in_stream = ifmt_ctx->streams[i];
        AVStream *out_stream = avformat_new_stream(ofmt_ctx, in_stream->codec->codec);
        if (!out_stream) {
            printf( "Failed allocating output stream\n");
            ret = AVERROR_UNKNOWN;
            return 1;
        }
        //Copy the settings of AVCodecContext
        if (avcodec_copy_context(out_stream->codec, in_stream->codec) < 0) {
            printf( "Failed to copy context from input to output stream codec context\n");
            return 1;
        }
        out_stream->codec->codec_tag = 0;
        if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
            out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
    }
    AVStream *in_stream, *out_stream;
    if (avformat_write_header(ofmt_ctx, NULL) < 0) {
        printf( "Error occurred when opening output file\n");
        return 1;
    }
    while (!force_stop) {
    
        ret = av_read_frame(ifmt_ctx, &pkt);
        in_stream  = ifmt_ctx->streams[pkt.stream_index];
        out_stream = ofmt_ctx->streams[pkt.stream_index];
        pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base,    out_stream->time_base, (AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
        pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, out_stream->time_base, (AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
        pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base,    out_stream->time_base);
        pkt.pos = -1;
        av_interleaved_write_frame(ofmt_ctx, &pkt)
        av_free_packet(&pkt);
        }
    
  • Finding library during compliation in mingw64 environment (libgcrypt and libgpg-error)

    28 novembre 2016, par Alastair

    I'm a real beginner at this, so apologies in advance for obvious questions. I'm trying to compile a custom build of ffmpeg that has some extra dependencies the normal build does not. Among those is libgcrypt and libgpg-error - I know this, because when I run configure, it fails, and the log contains:

    C:/workspace/windows/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgcrypt
    C:/workspace/windows/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgpg-error
    

    With this in mind, I cloned the repo for libgpg-error, ran make and make install, which created libgpg-error.dll.a and libgpg-error.la in /home/myuser/w64root/lib. I've tried adding this path to my $LIB environment variable, but the configure run still says it can't find the library.

    How can I make it visible? I also have pkg-config available on the machine - would manually creating a .pc file help me any?

    Thanks!

  • Stream audio (only) from ffmpeg to Android application

    28 novembre 2016, par Othman Mohammad

    I'm trying to implement a simple system to stream voice from microphone to an Android app. To stream, I used the ffmpeg program. I tried the following command:

    ffmpeg -ar 48000 -f alsa -i hw:0 -acodec mp2 -b:a 384k -f rtp rtp://127.0.0.1:1234
    

    and I was able to start the server.

    Then, I used the command:

    ffplay rtp://127.0.0.1:1234
    

    and everything worked properly.

    Now I need to play this stream in an Android mobile app.

    I saw this code somewhere in stackoverflow:

    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("rtsp://192.168.0.100"));
    startActivity(i);
    

    but the app crashed, stating that:

    android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=rtp://192.168.0.100:1234
    

    Can anyone help me with the Android code to play the stream? Plus, am I using the right protocol (RTP) or should I use RTSP?

    Thank you.

  • Extracting programs from dvb mux which begin later in stream

    28 novembre 2016, par John Allsup

    On DVB-T, some channels do not run 24h/day. If I save the entire mux using e.g. vlc (I do this on Windows due to Linux not liking my TV stick), I can play back the resulting .ts file with vlc, and select programs, and if I skip, say, 1hr in, and switch to the program (once started), I can watch it ok. If, however, I run ffmpeg on the file, it reports the program as having only one stream, of type 'Unknown: none', and cannot extract the stream.

    The reasoning is that if I wish to capture the first program from a channel which comes on at, say, 7pm, I want the dump of the mux to begin before 7pm.

    Any thoughts on how to extract the program stream?