popy ·¢±íÓÚ 2008-8-22 03:12 PM
ÈçºÎ»ñÈ¡µÄnb_streamsÊýÄ¿?
·ÖÎöFFmpegµÄ´úÂ룬·¢ÏÖ»ñÈ¡nb_streamsÖµµÄ¹ý³ÌÓÐЩÒþ»Þ£¬×·×ÙÁËһϣ¬»¹ÊÇûÓз¢ÏÖÔõô»ñÈ¡µÄ¸ÃÖµ¡£
¿¼ÂÇÒ»¸ö×î¼òµ¥µÄÁ÷³Ì£º
[list=1][*][b]av_register_all() Õâ¾Í²»ÓÃ˵ʲôÁË[/b][*][b]av_open_input_file() Ö÷ÒªÊǵ÷ÓÃdemuxerµÄxxx_probeÒÔ̽²âÎļþµÄ¸ñʽ
[/b][*][b]av_find_stream_info() ˵µÄÊÇ´ÓÎļþÖлñÈ¡Á÷µÄÏà¹ØÐÅÏ¢£¬µ«Ã»ÓÐÕÒµ½ÔõôÑù»ñÈ¡nb_streamsµÄ¹ý³Ì£¬¾´ÇëÖ¸½Ì
[/b][/list]
Fastreaming ·¢±íÓÚ 2008-8-22 03:19 PM
>># av_open_input_file() Ö÷ÒªÊǵ÷ÓÃdemuxerµÄxxx_probeÒÔ̽²âÎļþµÄ¸ñʽ
No,
av_open_input_file() will calculte nb_streams by calling the demuxer's read_header
popy ·¢±íÓÚ 2008-8-22 03:27 PM
»Ø¸´ #2 Fastreaming µÄÌû×Ó
Ŷ£¬ÄѵÀÎÒ¿´Â©µØ·½ÁË£¬ÔÙ¿´¿´
popy ·¢±íÓÚ 2008-8-22 03:49 PM
»Ø¸´ #2 Fastreaming µÄÌû×Ó
¸ø³öÒ»¸ö¼òµ¥µÄÁ÷³Ì£¬¹ØÓÚav_open_input_file() µÄÖ´Ðйý³Ì£º
/** size of probe buffer, for guessing file type from file contents */
#define PROBE_BUF_MIN 2048
#define PROBE_BUF_MAX (1<<20)
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
AVInputFormat *fmt,
int buf_size,
AVFormatParameters *ap)
{}
/* Do not open file if the format does not need it. XXX: specific
hack needed to handle RTSP/TCP */
if (!fmt || !(fmt->flags & AVFMT_NOFILE)) {}
if (buf_size > 0) {}
for(probe_size= PROBE_BUF_MIN; probe_size<=PROBE_BUF_MAX && !fmt; probe_size<<=1){}
}
/* guess file format */
fmt = av_probe_input_format2(pd, 1, &score);
}
av_freep(&pd->buf);
}
/* if still no format found, error */
if (!fmt) {}
/* check filename in case an image number is expected */
if (fmt->flags & AVFMT_NEEDNUMBER) {}
}
#########################################
»ñÈ¡Á÷µÄÐÅÏ¢ ???????
#########################################
err = av_open_input_stream(ic_ptr, pb, filename, fmt, ap);
if (err)
goto fail;
return 0;
fail:
av_freep(&pd->buf);
if (pb)
url_fclose(pb);
*ic_ptr = NULL;
return err;
}
¼ÙÉèÏÖÔÚµÄdemuxerÊÇmpegts_demuxer:
int av_open_input_stream(AVFormatContext **ic_ptr,
ByteIOContext *pb, const char *filename,
AVInputFormat *fmt, AVFormatParameters *ap)
{}
if(!ap->prealloced_context)
ic = av_alloc_format_context();
else
ic = *ic_ptr;
if (!ic) {}
ic->iformat = fmt;
ic->pb = pb;
ic->duration = AV_NOPTS_VALUE;
ic->start_time = AV_NOPTS_VALUE;
av_strlcpy(ic->filename, filename, sizeof(ic->filename));
/* allocate private data */
if (fmt->priv_data_size > 0) {}
} else {}
if (ic->iformat->read_header) {}
if (pb && !ic->data_offset)
ic->data_offset = url_ftell(ic->pb);
*ic_ptr = ic;
return 0;
fail:
if (ic) {}
av_free(st);
}
}
av_free(ic);
*ic_ptr = NULL;
return err;
}
½ÓÏÂÀ´£¬¿ÉÒÔ¿´¿´mpegts_read_header()[libavformat/mpegts.c]
static int mpegts_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{}
}
/* read the first 1024 bytes to get packet size */
pos = url_ftell(pb);
len = get_buffer(pb, buf, sizeof(buf));
if (len != sizeof(buf))
goto fail;
ts->raw_packet_size = get_packet_size(buf, sizeof(buf));
if (ts->raw_packet_size <= 0)
goto fail;
ts->stream = s;
ts->auto_guess = 0;
if (s->iformat == &mpegts_demuxer) {} else {}
nb_packets++;
}
/* NOTE1: the bitrate is computed without the FEC */
/* NOTE2: it is only the bitrate of the start of the stream */
ts->pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]);
ts->cur_pcr = pcrs[0] - ts->pcr_incr * packet_count[0];
s->bit_rate = (TS_PACKET_SIZE * 8) * 27e6 / ts->pcr_incr;
st->codec->bit_rate = s->bit_rate;
st->start_time = ts->cur_pcr;
#if 0
av_log(ts->stream, AV_LOG_DEBUG, "start=%0.3f pcr=%0.3f incr=%d\n",
st->start_time / 1000000.0, pcrs[0] / 27e6, ts->pcr_incr);
#endif
}
url_fseek(pb, pos, SEEK_SET);
return 0;
fail:
return -1;
}
¿¼ÂÇÒ»¸ö¼òµ¥Ò»µãµÄÇé¿ö£¬¼ÙÉèÔÚprobe½×¶ÎÒѾÕÒµ½ÊäÈëµÄ¸ñʽΪmpegts_demuxer£¬Òò´ËÉÏÃæ¾ÍÖ»ÓùØÐÄ£º
/* normal demux */
/* first do a scaning to get all the services */
url_fseek(pb, pos, SEEK_SET);
mpegts_scan_sdt(ts);
mpegts_set_service(ts);
handle_packets(ts, s->probesize);
/* if could not find service, enable auto_guess */
ts->auto_guess = 1;
Õ⼸ÐдúÂë¶øÒÑ£¬Õ⼸¸öº¯ÊýÎÒ¶¼¼òµ¥¿´¹ý£¬²¢Ã»·¢ÏÖÔõôÉèÖõÄnb_streams
popy ·¢±íÓÚ 2008-8-22 04:38 PM
»Ø¸´ #2 Fastreaming µÄÌû×Ó
ÕÒµ½µØ·½ÁË£¬¶àлָµã£º
ÆäʵËùÓÐËùÓÐstreamµÄ²éÕÒ¹ý³Ì£¬×îÖÕ¶¼»áµ÷Óõ½AVStream *av_new_stream(AVFormatContext *s, int id)£»Õâ¸öº¯Êý£¬Ö»ÊÇMPEGTS±È½ÏÌØÊâһЩ£¬ËüÓпÉÄܲ»Ö¹ÓÐstream£¬»¹¿ÉÄÜÓÐprogram£¬¶ø´Ëʱµ÷ÓõľÍÊÇAVProgram *av_new_program(AVFormatContext *ac, int id)£»ÎÒ·ÖÎöµÄʱºò·ÖÎöµ½ÁËÕâ¸öº¯Êý£¬µ«ÆäËüµÄ·ÖÖ§ÊÇÓпÉÄܵ½AVStream *av_new_stream(AVFormatContext *s, int id)£»º¯ÊýµÄ¡£
Æäʵ֮ǰ¾Í¿´µ½¹ýAVStream *av_new_stream(AVFormatContext *s, int id)ÀïµÄs->streams[s->nb_streams++] = st;
ÍÆ²â×î¿ÉÄÜ×îÖÕµ÷ÓõÄÊÇËü£¬µ«·ÖÎö·ÖÖ§Çé¿öµÄʱºòÒÅ©ÁË
Ò³:
[1]