static OutputStream *choose_output(void)

{

    int i;

    int64_t opts_min = INT64_MAX;

    OutputStream *ost_min = NULL;



    for (i = 0; i < nb_output_streams; i++) {

        OutputStream *ost = output_streams[i];

        int64_t opts = av_rescale_q(ost->st->cur_dts, ost->st->time_base,

                                    AV_TIME_BASE_Q);

        if (!ost->finished && opts < opts_min) {

            opts_min = opts;

            ost_min  = ost->unavailable ? NULL : ost;

        }

    }

    return ost_min;

}
