size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...)
{
    int len = strlen(dst);
    va_list vl;
    va_start(vl, fmt);
    len += vsnprintf(dst + len, size > len ? size - len : 0, fmt, vl);
    va_end(vl);
    return len;
}
['static int av_encode(AVFormatContext **output_files,\n                     int nb_output_files,\n                     AVFormatContext **input_files,\n                     int nb_input_files,\n                     AVStreamMap *stream_maps, int nb_stream_maps)\n{\n    int ret, i, j, k, n, nb_istreams = 0, nb_ostreams = 0;\n    AVFormatContext *is, *os;\n    AVCodecContext *codec, *icodec;\n    AVOutputStream *ost, **ost_table = NULL;\n    AVInputStream *ist, **ist_table = NULL;\n    AVInputFile *file_table;\n    int key;\n    int want_sdp = 1;\n    file_table= av_mallocz(nb_input_files * sizeof(AVInputFile));\n    if (!file_table)\n        goto fail;\n    j = 0;\n    for(i=0;i<nb_input_files;i++) {\n        is = input_files[i];\n        file_table[i].ist_index = j;\n        file_table[i].nb_streams = is->nb_streams;\n        j += is->nb_streams;\n    }\n    nb_istreams = j;\n    ist_table = av_mallocz(nb_istreams * sizeof(AVInputStream *));\n    if (!ist_table)\n        goto fail;\n    for(i=0;i<nb_istreams;i++) {\n        ist = av_mallocz(sizeof(AVInputStream));\n        if (!ist)\n            goto fail;\n        ist_table[i] = ist;\n    }\n    j = 0;\n    for(i=0;i<nb_input_files;i++) {\n        is = input_files[i];\n        for(k=0;k<is->nb_streams;k++) {\n            ist = ist_table[j++];\n            ist->st = is->streams[k];\n            ist->file_index = i;\n            ist->index = k;\n            ist->discard = 1;\n            if (ist->st->codec->rate_emu) {\n                ist->start = av_gettime();\n                ist->frame = 0;\n            }\n        }\n    }\n    nb_ostreams = 0;\n    for(i=0;i<nb_output_files;i++) {\n        os = output_files[i];\n        if (!os->nb_streams) {\n            fprintf(stderr, "Output file does not contain any stream\\n");\n            exit(1);\n        }\n        nb_ostreams += os->nb_streams;\n    }\n    if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) {\n        fprintf(stderr, "Number of stream maps must match number of output streams\\n");\n        exit(1);\n    }\n    for(i=0;i<nb_stream_maps;i++) {\n        int fi = stream_maps[i].file_index;\n        int si = stream_maps[i].stream_index;\n        if (fi < 0 || fi > nb_input_files - 1 ||\n            si < 0 || si > file_table[fi].nb_streams - 1) {\n            fprintf(stderr,"Could not find input stream #%d.%d\\n", fi, si);\n            exit(1);\n        }\n        fi = stream_maps[i].sync_file_index;\n        si = stream_maps[i].sync_stream_index;\n        if (fi < 0 || fi > nb_input_files - 1 ||\n            si < 0 || si > file_table[fi].nb_streams - 1) {\n            fprintf(stderr,"Could not find sync stream #%d.%d\\n", fi, si);\n            exit(1);\n        }\n    }\n    ost_table = av_mallocz(sizeof(AVOutputStream *) * nb_ostreams);\n    if (!ost_table)\n        goto fail;\n    for(i=0;i<nb_ostreams;i++) {\n        ost = av_mallocz(sizeof(AVOutputStream));\n        if (!ost)\n            goto fail;\n        ost_table[i] = ost;\n    }\n    n = 0;\n    for(k=0;k<nb_output_files;k++) {\n        os = output_files[k];\n        for(i=0;i<os->nb_streams;i++) {\n            int found;\n            ost = ost_table[n++];\n            ost->file_index = k;\n            ost->index = i;\n            ost->st = os->streams[i];\n            if (nb_stream_maps > 0) {\n                ost->source_index = file_table[stream_maps[n-1].file_index].ist_index +\n                    stream_maps[n-1].stream_index;\n                if (ist_table[ost->source_index]->st->codec->codec_type != ost->st->codec->codec_type) {\n                    fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\\n",\n                        stream_maps[n-1].file_index, stream_maps[n-1].stream_index,\n                        ost->file_index, ost->index);\n                    exit(1);\n                }\n            } else {\n                if(opt_programid) {\n                    found = 0;\n                    j = stream_index_from_inputs(input_files, nb_input_files, file_table, ist_table, ost->st->codec->codec_type, opt_programid);\n                    if(j != -1) {\n                        ost->source_index = j;\n                        found = 1;\n                    }\n                } else {\n                    found = 0;\n                    for(j=0;j<nb_istreams;j++) {\n                        ist = ist_table[j];\n                        if (ist->discard &&\n                            ist->st->codec->codec_type == ost->st->codec->codec_type) {\n                            ost->source_index = j;\n                            found = 1;\n                            break;\n                        }\n                    }\n                }\n                if (!found) {\n                    if(! opt_programid) {\n                        for(j=0;j<nb_istreams;j++) {\n                            ist = ist_table[j];\n                            if (ist->st->codec->codec_type == ost->st->codec->codec_type) {\n                                ost->source_index = j;\n                                found = 1;\n                            }\n                        }\n                    }\n                    if (!found) {\n                        fprintf(stderr, "Could not find input stream matching output stream #%d.%d\\n",\n                                ost->file_index, ost->index);\n                        exit(1);\n                    }\n                }\n            }\n            ist = ist_table[ost->source_index];\n            ist->discard = 0;\n            ost->sync_ist = (nb_stream_maps > 0) ?\n                ist_table[file_table[stream_maps[n-1].sync_file_index].ist_index +\n                         stream_maps[n-1].sync_stream_index] : ist;\n        }\n    }\n    for(i=0;i<nb_ostreams;i++) {\n        ost = ost_table[i];\n        os = output_files[ost->file_index];\n        ist = ist_table[ost->source_index];\n        codec = ost->st->codec;\n        icodec = ist->st->codec;\n        if (!ost->st->language[0])\n            av_strlcpy(ost->st->language, ist->st->language,\n                       sizeof(ost->st->language));\n        ost->st->disposition = ist->st->disposition;\n        if (ost->st->stream_copy) {\n            codec->codec_id = icodec->codec_id;\n            codec->codec_type = icodec->codec_type;\n            if(!codec->codec_tag){\n                if(   !os->oformat->codec_tag\n                   || av_codec_get_id (os->oformat->codec_tag, icodec->codec_tag) > 0\n                   || av_codec_get_tag(os->oformat->codec_tag, icodec->codec_id) <= 0)\n                    codec->codec_tag = icodec->codec_tag;\n            }\n            codec->bit_rate = icodec->bit_rate;\n            codec->extradata= icodec->extradata;\n            codec->extradata_size= icodec->extradata_size;\n            if(av_q2d(icodec->time_base) > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/1000)\n                codec->time_base = icodec->time_base;\n            else\n                codec->time_base = ist->st->time_base;\n            switch(codec->codec_type) {\n            case CODEC_TYPE_AUDIO:\n                codec->sample_rate = icodec->sample_rate;\n                codec->channels = icodec->channels;\n                codec->frame_size = icodec->frame_size;\n                codec->block_align= icodec->block_align;\n                if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3)\n                    codec->block_align= 0;\n                break;\n            case CODEC_TYPE_VIDEO:\n                if(using_vhook) {\n                    fprintf(stderr,"-vcodec copy and -vhook are incompatible (frames are not decoded)\\n");\n                    exit(1);\n                }\n                codec->pix_fmt = icodec->pix_fmt;\n                codec->width = icodec->width;\n                codec->height = icodec->height;\n                codec->has_b_frames = icodec->has_b_frames;\n                break;\n            case CODEC_TYPE_SUBTITLE:\n                break;\n            default:\n                abort();\n            }\n        } else {\n            switch(codec->codec_type) {\n            case CODEC_TYPE_AUDIO:\n                if (av_fifo_init(&ost->fifo, 1024))\n                    goto fail;\n                ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1;\n                icodec->request_channels = codec->channels;\n                ist->decoding_needed = 1;\n                ost->encoding_needed = 1;\n                break;\n            case CODEC_TYPE_VIDEO:\n                ost->video_crop = ((frame_leftBand + frame_rightBand + frame_topBand + frame_bottomBand) != 0);\n                ost->video_pad = ((frame_padleft + frame_padright + frame_padtop + frame_padbottom) != 0);\n                ost->video_resample = ((codec->width != icodec->width -\n                                (frame_leftBand + frame_rightBand) +\n                                (frame_padleft + frame_padright)) ||\n                        (codec->height != icodec->height -\n                                (frame_topBand  + frame_bottomBand) +\n                                (frame_padtop + frame_padbottom)) ||\n                        (codec->pix_fmt != icodec->pix_fmt));\n                if (ost->video_crop) {\n                    ost->topBand = frame_topBand;\n                    ost->leftBand = frame_leftBand;\n                }\n                if (ost->video_pad) {\n                    ost->padtop = frame_padtop;\n                    ost->padleft = frame_padleft;\n                    ost->padbottom = frame_padbottom;\n                    ost->padright = frame_padright;\n                    if (!ost->video_resample) {\n                        avcodec_get_frame_defaults(&ost->pict_tmp);\n                        if( avpicture_alloc( (AVPicture*)&ost->pict_tmp, codec->pix_fmt,\n                                         codec->width, codec->height ) )\n                            goto fail;\n                    }\n                }\n                if (ost->video_resample) {\n                    avcodec_get_frame_defaults(&ost->pict_tmp);\n                    if( avpicture_alloc( (AVPicture*)&ost->pict_tmp, codec->pix_fmt,\n                                         codec->width, codec->height ) ) {\n                        fprintf(stderr, "Cannot allocate temp picture, check pix fmt\\n");\n                        exit(1);\n                    }\n                    sws_flags = av_get_int(sws_opts, "sws_flags", NULL);\n                    ost->img_resample_ctx = sws_getContext(\n                            icodec->width - (frame_leftBand + frame_rightBand),\n                            icodec->height - (frame_topBand + frame_bottomBand),\n                            icodec->pix_fmt,\n                            codec->width - (frame_padleft + frame_padright),\n                            codec->height - (frame_padtop + frame_padbottom),\n                            codec->pix_fmt,\n                            sws_flags, NULL, NULL, NULL);\n                    if (ost->img_resample_ctx == NULL) {\n                        fprintf(stderr, "Cannot get resampling context\\n");\n                        exit(1);\n                    }\n                    ost->resample_height = icodec->height - (frame_topBand + frame_bottomBand);\n                }\n                ost->encoding_needed = 1;\n                ist->decoding_needed = 1;\n                break;\n            case CODEC_TYPE_SUBTITLE:\n                ost->encoding_needed = 1;\n                ist->decoding_needed = 1;\n                break;\n            default:\n                abort();\n                break;\n            }\n            if (ost->encoding_needed &&\n                (codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) {\n                char logfilename[1024];\n                FILE *f;\n                int size;\n                char *logbuffer;\n                snprintf(logfilename, sizeof(logfilename), "%s-%d.log",\n                         pass_logfilename ?\n                         pass_logfilename : DEFAULT_PASS_LOGFILENAME, i);\n                if (codec->flags & CODEC_FLAG_PASS1) {\n                    f = fopen(logfilename, "w");\n                    if (!f) {\n                        perror(logfilename);\n                        exit(1);\n                    }\n                    ost->logfile = f;\n                } else {\n                    f = fopen(logfilename, "r");\n                    if (!f) {\n                        perror(logfilename);\n                        exit(1);\n                    }\n                    fseek(f, 0, SEEK_END);\n                    size = ftell(f);\n                    fseek(f, 0, SEEK_SET);\n                    logbuffer = av_malloc(size + 1);\n                    if (!logbuffer) {\n                        fprintf(stderr, "Could not allocate log buffer\\n");\n                        exit(1);\n                    }\n                    size = fread(logbuffer, 1, size, f);\n                    fclose(f);\n                    logbuffer[size] = \'\\0\';\n                    codec->stats_in = logbuffer;\n                }\n            }\n        }\n        if(codec->codec_type == CODEC_TYPE_VIDEO){\n            int size= codec->width * codec->height;\n            bit_buffer_size= FFMAX(bit_buffer_size, 4*size);\n        }\n    }\n    if (!bit_buffer)\n        bit_buffer = av_malloc(bit_buffer_size);\n    if (!bit_buffer)\n        goto fail;\n    for(i=0;i<nb_output_files;i++) {\n        dump_format(output_files[i], i, output_files[i]->filename, 1);\n    }\n    if (verbose >= 0) {\n        fprintf(stderr, "Stream mapping:\\n");\n        for(i=0;i<nb_ostreams;i++) {\n            ost = ost_table[i];\n            fprintf(stderr, "  Stream #%d.%d -> #%d.%d",\n                    ist_table[ost->source_index]->file_index,\n                    ist_table[ost->source_index]->index,\n                    ost->file_index,\n                    ost->index);\n            if (ost->sync_ist != ist_table[ost->source_index])\n                fprintf(stderr, " [sync #%d.%d]",\n                        ost->sync_ist->file_index,\n                        ost->sync_ist->index);\n            fprintf(stderr, "\\n");\n        }\n    }\n    for(i=0;i<nb_ostreams;i++) {\n        ost = ost_table[i];\n        if (ost->encoding_needed) {\n            AVCodec *codec;\n            codec = avcodec_find_encoder(ost->st->codec->codec_id);\n            if (!codec) {\n                fprintf(stderr, "Unsupported codec for output stream #%d.%d\\n",\n                        ost->file_index, ost->index);\n                exit(1);\n            }\n            if (avcodec_open(ost->st->codec, codec) < 0) {\n                fprintf(stderr, "Error while opening codec for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height\\n",\n                        ost->file_index, ost->index);\n                exit(1);\n            }\n            extra_size += ost->st->codec->extradata_size;\n        }\n    }\n    for(i=0;i<nb_istreams;i++) {\n        ist = ist_table[i];\n        if (ist->decoding_needed) {\n            AVCodec *codec;\n            codec = avcodec_find_decoder(ist->st->codec->codec_id);\n            if (!codec) {\n                fprintf(stderr, "Unsupported codec (id=%d) for input stream #%d.%d\\n",\n                        ist->st->codec->codec_id, ist->file_index, ist->index);\n                exit(1);\n            }\n            if (avcodec_open(ist->st->codec, codec) < 0) {\n                fprintf(stderr, "Error while opening codec for input stream #%d.%d\\n",\n                        ist->file_index, ist->index);\n                exit(1);\n            }\n        }\n    }\n    for(i=0;i<nb_istreams;i++) {\n        ist = ist_table[i];\n        is = input_files[ist->file_index];\n        ist->pts = 0;\n        ist->next_pts = AV_NOPTS_VALUE;\n        ist->is_start = 1;\n    }\n    for (i=0;i<nb_meta_data_maps;i++) {\n        AVFormatContext *out_file;\n        AVFormatContext *in_file;\n        int out_file_index = meta_data_maps[i].out_file;\n        int in_file_index = meta_data_maps[i].in_file;\n        if ( out_file_index < 0 || out_file_index >= nb_output_files ) {\n            fprintf(stderr, "Invalid output file index %d map_meta_data(%d,%d)\\n", out_file_index, out_file_index, in_file_index);\n            ret = AVERROR(EINVAL);\n            goto fail;\n        }\n        if ( in_file_index < 0 || in_file_index >= nb_input_files ) {\n            fprintf(stderr, "Invalid input file index %d map_meta_data(%d,%d)\\n", in_file_index, out_file_index, in_file_index);\n            ret = AVERROR(EINVAL);\n            goto fail;\n        }\n        out_file = output_files[out_file_index];\n        in_file = input_files[in_file_index];\n        strcpy(out_file->title, in_file->title);\n        strcpy(out_file->author, in_file->author);\n        strcpy(out_file->copyright, in_file->copyright);\n        strcpy(out_file->comment, in_file->comment);\n        strcpy(out_file->album, in_file->album);\n        out_file->year = in_file->year;\n        out_file->track = in_file->track;\n        strcpy(out_file->genre, in_file->genre);\n    }\n    for(i=0;i<nb_output_files;i++) {\n        os = output_files[i];\n        if (av_write_header(os) < 0) {\n            fprintf(stderr, "Could not write header for output file #%d (incorrect codec parameters ?)\\n", i);\n            ret = AVERROR(EINVAL);\n            goto fail;\n        }\n        if (strcmp(output_files[i]->oformat->name, "rtp")) {\n            want_sdp = 0;\n        }\n    }\n    if (want_sdp) {\n        print_sdp(output_files, nb_output_files);\n    }\n    if ( !using_stdin && verbose >= 0) {\n        fprintf(stderr, "Press [q] to stop encoding\\n");\n        url_set_interrupt_cb(decode_interrupt_cb);\n    }\n    term_init();\n    key = -1;\n    timer_start = av_gettime();\n    for(; received_sigterm == 0;) {\n        int file_index, ist_index;\n        AVPacket pkt;\n        double ipts_min;\n        double opts_min;\n    redo:\n        ipts_min= 1e100;\n        opts_min= 1e100;\n        if (!using_stdin) {\n            if (q_pressed)\n                break;\n            key = read_key();\n            if (key == \'q\')\n                break;\n        }\n        file_index = -1;\n        for(i=0;i<nb_ostreams;i++) {\n            double ipts, opts;\n            ost = ost_table[i];\n            os = output_files[ost->file_index];\n            ist = ist_table[ost->source_index];\n            if(ost->st->codec->codec_type == CODEC_TYPE_VIDEO)\n                opts = ost->sync_opts * av_q2d(ost->st->codec->time_base);\n            else\n                opts = ost->st->pts.val * av_q2d(ost->st->time_base);\n            ipts = (double)ist->pts;\n            if (!file_table[ist->file_index].eof_reached){\n                if(ipts < ipts_min) {\n                    ipts_min = ipts;\n                    if(input_sync ) file_index = ist->file_index;\n                }\n                if(opts < opts_min) {\n                    opts_min = opts;\n                    if(!input_sync) file_index = ist->file_index;\n                }\n            }\n            if(ost->frame_number >= max_frames[ost->st->codec->codec_type]){\n                file_index= -1;\n                break;\n            }\n        }\n        if (file_index < 0) {\n            break;\n        }\n        if (recording_time > 0 && opts_min >= (recording_time / 1000000.0))\n            break;\n        if (limit_filesize != 0 && limit_filesize < url_ftell(output_files[0]->pb))\n            break;\n        is = input_files[file_index];\n        if (av_read_frame(is, &pkt) < 0) {\n            file_table[file_index].eof_reached = 1;\n            if (opt_shortest)\n                break;\n            else\n                continue;\n        }\n        if (do_pkt_dump) {\n            av_pkt_dump_log(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump);\n        }\n        if (pkt.stream_index >= file_table[file_index].nb_streams)\n            goto discard_packet;\n        ist_index = file_table[file_index].ist_index + pkt.stream_index;\n        ist = ist_table[ist_index];\n        if (ist->discard)\n            goto discard_packet;\n        if (pkt.dts != AV_NOPTS_VALUE)\n            pkt.dts += av_rescale_q(input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ist->st->time_base);\n        if (pkt.pts != AV_NOPTS_VALUE)\n            pkt.pts += av_rescale_q(input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ist->st->time_base);\n        if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE) {\n            int64_t pkt_dts= av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q);\n            int64_t delta= pkt_dts - ist->next_pts;\n            if((FFABS(delta) > 1LL*dts_delta_threshold*AV_TIME_BASE || pkt_dts+1<ist->pts)&& !copy_ts){\n                input_files_ts_offset[ist->file_index]-= delta;\n                if (verbose > 2)\n                    fprintf(stderr, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\\n", delta, input_files_ts_offset[ist->file_index]);\n                pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);\n                if(pkt.pts != AV_NOPTS_VALUE)\n                    pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);\n            }\n        }\n        if (output_packet(ist, ist_index, ost_table, nb_ostreams, &pkt) < 0) {\n            if (verbose >= 0)\n                fprintf(stderr, "Error while decoding stream #%d.%d\\n",\n                        ist->file_index, ist->index);\n            av_free_packet(&pkt);\n            goto redo;\n        }\n    discard_packet:\n        av_free_packet(&pkt);\n        print_report(output_files, ost_table, nb_ostreams, 0);\n    }\n    for(i=0;i<nb_istreams;i++) {\n        ist = ist_table[i];\n        if (ist->decoding_needed) {\n            output_packet(ist, i, ost_table, nb_ostreams, NULL);\n        }\n    }\n    term_exit();\n    for(i=0;i<nb_output_files;i++) {\n        os = output_files[i];\n        av_write_trailer(os);\n    }\n    print_report(output_files, ost_table, nb_ostreams, 1);\n    for(i=0;i<nb_ostreams;i++) {\n        ost = ost_table[i];\n        if (ost->encoding_needed) {\n            av_freep(&ost->st->codec->stats_in);\n            avcodec_close(ost->st->codec);\n        }\n    }\n    for(i=0;i<nb_istreams;i++) {\n        ist = ist_table[i];\n        if (ist->decoding_needed) {\n            avcodec_close(ist->st->codec);\n        }\n    }\n    ret = 0;\n fail1:\n    av_freep(&bit_buffer);\n    av_free(file_table);\n    if (ist_table) {\n        for(i=0;i<nb_istreams;i++) {\n            ist = ist_table[i];\n            av_free(ist);\n        }\n        av_free(ist_table);\n    }\n    if (ost_table) {\n        for(i=0;i<nb_ostreams;i++) {\n            ost = ost_table[i];\n            if (ost) {\n                if (ost->logfile) {\n                    fclose(ost->logfile);\n                    ost->logfile = NULL;\n                }\n                av_fifo_free(&ost->fifo);\n                av_free(ost->pict_tmp.data[0]);\n                if (ost->video_resample)\n                    sws_freeContext(ost->img_resample_ctx);\n                if (ost->resample)\n                    audio_resample_close(ost->resample);\n                av_free(ost);\n            }\n        }\n        av_free(ost_table);\n    }\n    return ret;\n fail:\n    ret = AVERROR(ENOMEM);\n    goto fail1;\n}', 'static void print_sdp(AVFormatContext **avc, int n)\n{\n    char sdp[2048];\n    avf_sdp_create(avc, n, sdp, sizeof(sdp));\n    printf("SDP:\\n%s\\n", sdp);\n}', 'int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size)\n{\n    struct sdp_session_level s;\n    int i, j, port, ttl;\n    char dst[32];\n    memset(buff, 0, size);\n    memset(&s, 0, sizeof(struct sdp_session_level));\n    s.user = "-";\n    s.src_addr = "127.0.0.1";\n    s.name = ac[0]->title;\n    port = 0;\n    ttl = 0;\n    if (n_files == 1) {\n        port = get_address(dst, sizeof(dst), &ttl, ac[0]->filename);\n        if (port > 0) {\n            s.dst_addr = dst;\n            s.ttl = ttl;\n        }\n    }\n    sdp_write_header(buff, size, &s);\n    dst[0] = 0;\n    for (i = 0; i < n_files; i++) {\n        if (n_files != 1) {\n            port = get_address(dst, sizeof(dst), &ttl, ac[i]->filename);\n        }\n        for (j = 0; j < ac[i]->nb_streams; j++) {\n            sdp_write_media(buff, size,\n                                  ac[i]->streams[j]->codec, dst[0] ? dst : NULL,\n                                  (port > 0) ? port + j * 2 : 0, ttl);\n            if (port <= 0) {\n                av_strlcatf(buff, size,\n                                   "a=control:streamid=%d\\r\\n", i + j);\n            }\n        }\n    }\n    return 0;\n}', 'static void sdp_write_header(char *buff, int size, struct sdp_session_level *s)\n{\n    av_strlcatf(buff, size, "v=%d\\r\\n"\n                            "o=- %d %d IN IPV4 %s\\r\\n"\n                            "t=%d %d\\r\\n"\n                            "s=%s\\r\\n"\n                            "a=tool:libavformat\\r\\n",\n                            s->sdp_version,\n                            s->id, s->version, s->src_addr,\n                            s->start_time, s->end_time,\n                            s->name[0] ? s->name : "No Name");\n    dest_write(buff, size, s->dst_addr, s->ttl);\n}', 'static void dest_write(char *buff, int size, const char *dest_addr, int ttl)\n{\n    if (dest_addr) {\n        if (ttl > 0) {\n            av_strlcatf(buff, size, "c=IN IP4 %s/%d\\r\\n", dest_addr, ttl);\n        } else {\n            av_strlcatf(buff, size, "c=IN IP4 %s\\r\\n", dest_addr);\n        }\n    }\n}', 'size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...)\n{\n    int len = strlen(dst);\n    va_list vl;\n    va_start(vl, fmt);\n    len += vsnprintf(dst + len, size > len ? size - len : 0, fmt, vl);\n    va_end(vl);\n    return len;\n}']