[Libav-user] av_interleaved_write_frame error in muxing packets

Lalit Patil lalit.patil005 at gmail.com
Tue Dec 29 05:56:13 CET 2015


Dear All,
please help me on this topic.
i m  trying to stream a local mp4 file to wowza server usi ng remuxing.c


AVOutputFormat *ofmt = NULL;
    AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
    AVPacket pkt;
    const char *out_filename;
    int ret, i;
    CString inputFile;
    m_editFileName.GetWindowTextW(inputFile);

    //Convert CString to std:: String and then const char*
    CT2CA pszConvertedAnsiString(inputFile);
    std::string strStd(pszConvertedAnsiString);
    const char* in_filename(strStd.c_str());
    //Convert CString to std:: String and then const char* End

    out_filename = "rtsp://192.168.200.96:1935/live/MFCVODTest";
    av_register_all();
    avformat_network_init();
    if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, 0)) < 0) {
        AfxMessageBox(L"Could not open input file", MB_OKCANCEL, 0);
        goto end;
    }

    if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) < 0) {

        AfxMessageBox(L"Failed to retrieve input stream information",
MB_OKCANCEL, 0);
        goto end;
    }

    av_dump_format(ifmt_ctx, 0, in_filename, 0);

    avformat_alloc_output_context2(&ofmt_ctx, NULL, "rtsp", out_filename);
    if (!ofmt_ctx) {
        AfxMessageBox(L"Could not create output context\n", MB_OKCANCEL, 0);
        ret = AVERROR_UNKNOWN;
        goto end;
    }

    ofmt = ofmt_ctx->oformat;

    for (i = 0; i < ifmt_ctx->nb_streams; i++) {
        AVStream *in_stream = ifmt_ctx->streams[i];
        AVStream *out_stream = avformat_new_stream(ofmt_ctx,
in_stream->codec->codec);
        if (!out_stream) {
            AfxMessageBox(L"Failed allocating output stream\n",
MB_OKCANCEL, 0);
            ret = AVERROR_UNKNOWN;
            goto end;
        }

        ret = avcodec_copy_context(out_stream->codec, in_stream->codec);
        if (ret < 0) {
            AfxMessageBox(L"Failed to copy context from input to output
stream codec context\n", MB_OKCANCEL, 0);
            goto end;
        }
        out_stream->codec->codec_tag = 0;
        if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
            out_stream->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
    }
    av_dump_format(ofmt_ctx, 0, out_filename, 1);

    if (!(ofmt->flags & AVFMT_NOFILE)) {
        ret = avio_open(&ofmt_ctx->pb, out_filename, AVIO_FLAG_WRITE);
        if (ret < 0) {
            AfxMessageBox(L"Could not open output file", MB_OKCANCEL, 0);
            goto end;
        }
    }

    ret = avformat_write_header(ofmt_ctx, NULL);
    if (ret < 0) {
        AfxMessageBox(L"Error occurred when opening output file\n",
MB_OKCANCEL, 0);
        goto end;
    }

    while (1) {
        AVStream *in_stream, *out_stream;

        ret = av_read_frame(ifmt_ctx, &pkt);
        if (ret < 0)
            break;

        in_stream = ifmt_ctx->streams[pkt.stream_index];
        out_stream = ofmt_ctx->streams[pkt.stream_index];

        //log_packet(ifmt_ctx, &pkt, "in");

        /* copy packet */
        pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base,
out_stream->time_base, AV_ROUND_NEAR_INF);
        pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base,
out_stream->time_base, AV_ROUND_NEAR_INF);
        pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base,
out_stream->time_base);
        pkt.pos = -1;
        //log_packet(ofmt_ctx, &pkt, "out");

         ret = av_interleaved_write_frame(ofmt_ctx, &pkt);

        //ret = av_write_frame(ofmt_ctx, &pkt);
        if (ret < 0) {
            AfxMessageBox(L"Error muxing packet\n", MB_OKCANCEL, 0);
            break;
        }
        av_packet_unref(&pkt);
    }

    av_write_trailer(ofmt_ctx);

  end:

    avformat_close_input(&ifmt_ctx);
    avformat_network_deinit();
    /* close output */
    if (ofmt_ctx && !(ofmt->flags & AVFMT_NOFILE))
        avio_closep(&ofmt_ctx->pb);
    avformat_free_context(ofmt_ctx);

    if (ret < 0 && ret != AVERROR_EOF) {
        //fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));
        //return 1;
    }
    else
    {
        AfxMessageBox(L"File Uploaded Successfully", MB_OKCANCEL, 0);
    }


 but getting error in muxing apckets


*Thanks and Regards,**Lalit Patil*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20151229/f59184ce/attachment.html>


More information about the Libav-user mailing list