OLD | NEW |
1 /* | 1 /* |
2 * various utility functions for use within FFmpeg | 2 * various utility functions for use within FFmpeg |
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard | 3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard |
4 * | 4 * |
5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
6 * | 6 * |
7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
11 * | 11 * |
12 * FFmpeg is distributed in the hope that it will be useful, | 12 * FFmpeg is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Lesser General Public License for more details. | 15 * Lesser General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Lesser General Public | 17 * You should have received a copy of the GNU Lesser General Public |
18 * License along with FFmpeg; if not, write to the Free Software | 18 * License along with FFmpeg; if not, write to the Free Software |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 */ | 20 */ |
21 #include "avformat.h" | 21 #include "avformat.h" |
22 #include "internal.h" | 22 #include "internal.h" |
23 #include "libavcodec/opt.h" | 23 #include "libavcodec/opt.h" |
24 #include "metadata.h" | 24 #include "metadata.h" |
25 #include "libavutil/avstring.h" | 25 #include "libavutil/avstring.h" |
26 #include "riff.h" | 26 #include "riff.h" |
| 27 #include "audiointerleave.h" |
27 #include <sys/time.h> | 28 #include <sys/time.h> |
28 #include <time.h> | 29 #include <time.h> |
29 #include <strings.h> | 30 #include <strings.h> |
| 31 #include <stdarg.h> |
| 32 #if CONFIG_NETWORK |
| 33 #include "network.h" |
| 34 #endif |
30 | 35 |
31 #undef NDEBUG | 36 #undef NDEBUG |
32 #include <assert.h> | 37 #include <assert.h> |
33 | 38 |
34 /** | 39 /** |
35 * @file libavformat/utils.c | 40 * @file libavformat/utils.c |
36 * various utility functions for use within FFmpeg | 41 * various utility functions for use within FFmpeg |
37 */ | 42 */ |
38 | 43 |
39 unsigned avformat_version(void) | 44 unsigned avformat_version(void) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 135 |
131 void av_register_output_format(AVOutputFormat *format) | 136 void av_register_output_format(AVOutputFormat *format) |
132 { | 137 { |
133 AVOutputFormat **p; | 138 AVOutputFormat **p; |
134 p = &first_oformat; | 139 p = &first_oformat; |
135 while (*p != NULL) p = &(*p)->next; | 140 while (*p != NULL) p = &(*p)->next; |
136 *p = format; | 141 *p = format; |
137 format->next = NULL; | 142 format->next = NULL; |
138 } | 143 } |
139 | 144 |
140 #if LIBAVFORMAT_VERSION_MAJOR < 53 | |
141 int match_ext(const char *filename, const char *extensions) | |
142 { | |
143 return av_match_ext(filename, extensions); | |
144 } | |
145 #endif | |
146 | |
147 int av_match_ext(const char *filename, const char *extensions) | 145 int av_match_ext(const char *filename, const char *extensions) |
148 { | 146 { |
149 const char *ext, *p; | 147 const char *ext, *p; |
150 char ext1[32], *q; | 148 char ext1[32], *q; |
151 | 149 |
152 if(!filename) | 150 if(!filename) |
153 return 0; | 151 return 0; |
154 | 152 |
155 ext = strrchr(filename, '.'); | 153 ext = strrchr(filename, '.'); |
156 if (ext) { | 154 if (ext) { |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 if((s->flags & AVFMT_FLAG_IGNDTS) && pkt->pts != AV_NOPTS_VALUE) | 809 if((s->flags & AVFMT_FLAG_IGNDTS) && pkt->pts != AV_NOPTS_VALUE) |
812 pkt->dts= AV_NOPTS_VALUE; | 810 pkt->dts= AV_NOPTS_VALUE; |
813 | 811 |
814 if (st->codec->codec_id != CODEC_ID_H264 && pc && pc->pict_type == FF_B_TYPE
) | 812 if (st->codec->codec_id != CODEC_ID_H264 && pc && pc->pict_type == FF_B_TYPE
) |
815 //FIXME Set low_delay = 0 when has_b_frames = 1 | 813 //FIXME Set low_delay = 0 when has_b_frames = 1 |
816 st->codec->has_b_frames = 1; | 814 st->codec->has_b_frames = 1; |
817 | 815 |
818 /* do we have a video B-frame ? */ | 816 /* do we have a video B-frame ? */ |
819 delay= st->codec->has_b_frames; | 817 delay= st->codec->has_b_frames; |
820 presentation_delayed = 0; | 818 presentation_delayed = 0; |
| 819 |
| 820 // this delay should not count for undecoded frames |
| 821 if (delay && st->codec->active_thread_type&FF_THREAD_FRAME) |
| 822 delay -= st->codec->thread_count-1; |
| 823 |
821 /* XXX: need has_b_frame, but cannot get it if the codec is | 824 /* XXX: need has_b_frame, but cannot get it if the codec is |
822 not initialized */ | 825 not initialized */ |
823 if (delay && | 826 if (delay && |
824 pc && pc->pict_type != FF_B_TYPE) | 827 pc && pc->pict_type != FF_B_TYPE) |
825 presentation_delayed = 1; | 828 presentation_delayed = 1; |
826 | 829 |
827 if(pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && pkt->dts > pk
t->pts && st->pts_wrap_bits<63 | 830 if(pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && pkt->dts > pk
t->pts && st->pts_wrap_bits<63 |
828 /*&& pkt->dts-(1LL<<st->pts_wrap_bits) < pkt->pts*/){ | 831 /*&& pkt->dts-(1LL<<st->pts_wrap_bits) < pkt->pts*/){ |
829 pkt->dts -= 1LL<<st->pts_wrap_bits; | 832 pkt->dts -= 1LL<<st->pts_wrap_bits; |
830 } | 833 } |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 { | 1544 { |
1542 int index; | 1545 int index; |
1543 int64_t ret; | 1546 int64_t ret; |
1544 AVStream *st; | 1547 AVStream *st; |
1545 AVIndexEntry *ie; | 1548 AVIndexEntry *ie; |
1546 | 1549 |
1547 st = s->streams[stream_index]; | 1550 st = s->streams[stream_index]; |
1548 | 1551 |
1549 index = av_index_search_timestamp(st, timestamp, flags); | 1552 index = av_index_search_timestamp(st, timestamp, flags); |
1550 | 1553 |
| 1554 if(index < 0 && st->nb_index_entries && timestamp < st->index_entries[0].tim
estamp) |
| 1555 return -1; |
| 1556 |
1551 if(index < 0 || index==st->nb_index_entries-1){ | 1557 if(index < 0 || index==st->nb_index_entries-1){ |
1552 int i; | 1558 int i; |
1553 AVPacket pkt; | 1559 AVPacket pkt; |
1554 | 1560 |
1555 if(st->nb_index_entries){ | 1561 if(st->nb_index_entries){ |
1556 assert(st->index_entries); | 1562 assert(st->index_entries); |
1557 ie= &st->index_entries[st->nb_index_entries-1]; | 1563 ie= &st->index_entries[st->nb_index_entries-1]; |
1558 if ((ret = url_fseek(s->pb, ie->pos, SEEK_SET)) < 0) | 1564 if ((ret = url_fseek(s->pb, ie->pos, SEEK_SET)) < 0) |
1559 return ret; | 1565 return ret; |
1560 av_update_cur_dts(s, st, ie->timestamp); | 1566 av_update_cur_dts(s, st, ie->timestamp); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1904 | 1910 |
1905 static int has_codec_parameters(AVCodecContext *enc) | 1911 static int has_codec_parameters(AVCodecContext *enc) |
1906 { | 1912 { |
1907 int val; | 1913 int val; |
1908 switch(enc->codec_type) { | 1914 switch(enc->codec_type) { |
1909 case CODEC_TYPE_AUDIO: | 1915 case CODEC_TYPE_AUDIO: |
1910 val = enc->sample_rate && enc->channels && enc->sample_fmt != SAMPLE_FMT
_NONE; | 1916 val = enc->sample_rate && enc->channels && enc->sample_fmt != SAMPLE_FMT
_NONE; |
1911 if(!enc->frame_size && | 1917 if(!enc->frame_size && |
1912 (enc->codec_id == CODEC_ID_VORBIS || | 1918 (enc->codec_id == CODEC_ID_VORBIS || |
1913 enc->codec_id == CODEC_ID_AAC || | 1919 enc->codec_id == CODEC_ID_AAC || |
| 1920 enc->codec_id == CODEC_ID_MP1 || |
| 1921 enc->codec_id == CODEC_ID_MP2 || |
1914 enc->codec_id == CODEC_ID_MP3 || | 1922 enc->codec_id == CODEC_ID_MP3 || |
1915 enc->codec_id == CODEC_ID_SPEEX)) | 1923 enc->codec_id == CODEC_ID_SPEEX)) |
1916 return 0; | 1924 return 0; |
1917 break; | 1925 break; |
1918 case CODEC_TYPE_VIDEO: | 1926 case CODEC_TYPE_VIDEO: |
1919 val = enc->width && enc->pix_fmt != PIX_FMT_NONE; | 1927 val = enc->width && enc->pix_fmt != PIX_FMT_NONE; |
1920 break; | 1928 break; |
1921 default: | 1929 default: |
1922 val = 1; | 1930 val = 1; |
1923 break; | 1931 break; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2062 { | 2070 { |
2063 int i, count, ret, read_size, j; | 2071 int i, count, ret, read_size, j; |
2064 AVStream *st; | 2072 AVStream *st; |
2065 AVPacket pkt1, *pkt; | 2073 AVPacket pkt1, *pkt; |
2066 int64_t last_dts[MAX_STREAMS]; | 2074 int64_t last_dts[MAX_STREAMS]; |
2067 int64_t duration_gcd[MAX_STREAMS]={0}; | 2075 int64_t duration_gcd[MAX_STREAMS]={0}; |
2068 int duration_count[MAX_STREAMS]={0}; | 2076 int duration_count[MAX_STREAMS]={0}; |
2069 double (*duration_error)[MAX_STD_TIMEBASES]; | 2077 double (*duration_error)[MAX_STD_TIMEBASES]; |
2070 int64_t old_offset = url_ftell(ic->pb); | 2078 int64_t old_offset = url_ftell(ic->pb); |
2071 int64_t codec_info_duration[MAX_STREAMS]={0}; | 2079 int64_t codec_info_duration[MAX_STREAMS]={0}; |
2072 int codec_info_nb_frames[MAX_STREAMS]={0}; | |
2073 | 2080 |
2074 duration_error = av_mallocz(MAX_STREAMS * sizeof(*duration_error)); | 2081 duration_error = av_mallocz(MAX_STREAMS * sizeof(*duration_error)); |
2075 if (!duration_error) return AVERROR(ENOMEM); | 2082 if (!duration_error) return AVERROR(ENOMEM); |
2076 | 2083 |
2077 for(i=0;i<ic->nb_streams;i++) { | 2084 for(i=0;i<ic->nb_streams;i++) { |
2078 st = ic->streams[i]; | 2085 st = ic->streams[i]; |
| 2086 if (st->codec->codec_id == CODEC_ID_AAC) { |
| 2087 st->codec->sample_rate = 0; |
| 2088 st->codec->frame_size = 0; |
| 2089 st->codec->channels = 0; |
| 2090 } |
2079 if(st->codec->codec_type == CODEC_TYPE_VIDEO){ | 2091 if(st->codec->codec_type == CODEC_TYPE_VIDEO){ |
2080 /* if(!st->time_base.num) | 2092 /* if(!st->time_base.num) |
2081 st->time_base= */ | 2093 st->time_base= */ |
2082 if(!st->codec->time_base.num) | 2094 if(!st->codec->time_base.num) |
2083 st->codec->time_base= st->time_base; | 2095 st->codec->time_base= st->time_base; |
2084 } | 2096 } |
2085 //only for the split stuff | 2097 //only for the split stuff |
2086 if (!st->parser) { | 2098 if (!st->parser) { |
2087 st->parser = av_parser_init(st->codec->codec_id); | 2099 st->parser = av_parser_init(st->codec->codec_id); |
2088 if(st->need_parsing == AVSTREAM_PARSE_HEADERS && st->parser){ | 2100 if(st->need_parsing == AVSTREAM_PARSE_HEADERS && st->parser){ |
2089 st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; | 2101 st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; |
2090 } | 2102 } |
2091 } | 2103 } |
| 2104 assert(!st->codec->codec); |
| 2105 //try to just open decoders, in case this is enough to get parameters |
| 2106 if(!has_codec_parameters(st->codec)){ |
| 2107 AVCodec *codec = avcodec_find_decoder(st->codec->codec_id); |
| 2108 if (codec) |
| 2109 avcodec_open(st->codec, codec); |
| 2110 } |
2092 } | 2111 } |
2093 | 2112 |
2094 for(i=0;i<MAX_STREAMS;i++){ | 2113 for(i=0;i<MAX_STREAMS;i++){ |
2095 last_dts[i]= AV_NOPTS_VALUE; | 2114 last_dts[i]= AV_NOPTS_VALUE; |
2096 } | 2115 } |
2097 | 2116 |
2098 count = 0; | 2117 count = 0; |
2099 read_size = 0; | 2118 read_size = 0; |
2100 for(;;) { | 2119 for(;;) { |
2101 if(url_interrupt_cb()){ | 2120 if(url_interrupt_cb()){ |
2102 ret= AVERROR(EINTR); | 2121 ret= AVERROR(EINTR); |
2103 av_log(ic, AV_LOG_DEBUG, "interrupted\n"); | 2122 av_log(ic, AV_LOG_DEBUG, "interrupted\n"); |
2104 break; | 2123 break; |
2105 } | 2124 } |
2106 | 2125 |
2107 /* check if one codec still needs to be handled */ | 2126 /* check if one codec still needs to be handled */ |
2108 for(i=0;i<ic->nb_streams;i++) { | 2127 for(i=0;i<ic->nb_streams;i++) { |
2109 st = ic->streams[i]; | 2128 st = ic->streams[i]; |
2110 if (!has_codec_parameters(st->codec)) | 2129 if (!has_codec_parameters(st->codec)) |
2111 break; | 2130 break; |
2112 /* variable fps and no guess at the real fps */ | 2131 /* variable fps and no guess at the real fps */ |
2113 if( tb_unreliable(st->codec) | 2132 if( tb_unreliable(st->codec) && !(st->r_frame_rate.num && st->avg_
frame_rate.num) |
2114 && duration_count[i]<20 && st->codec->codec_type == CODEC_TYPE_VI
DEO) | 2133 && duration_count[i]<20 && st->codec->codec_type == CODEC_TYPE_VI
DEO) |
2115 break; | 2134 break; |
2116 if(st->parser && st->parser->parser->split && !st->codec->extradata) | 2135 if(st->parser && st->parser->parser->split && !st->codec->extradata) |
2117 break; | 2136 break; |
2118 if(st->first_dts == AV_NOPTS_VALUE) | 2137 if(st->first_dts == AV_NOPTS_VALUE) |
2119 break; | 2138 break; |
2120 } | 2139 } |
2121 if (i == ic->nb_streams) { | 2140 if (i == ic->nb_streams) { |
2122 /* NOTE: if the format has no header, then we need to read | 2141 /* NOTE: if the format has no header, then we need to read |
2123 some packets to get most of the streams, so we cannot | 2142 some packets to get most of the streams, so we cannot |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2159 | 2178 |
2160 pkt= add_to_pktbuf(&ic->packet_buffer, &pkt1, &ic->packet_buffer_end); | 2179 pkt= add_to_pktbuf(&ic->packet_buffer, &pkt1, &ic->packet_buffer_end); |
2161 if(av_dup_packet(pkt) < 0) { | 2180 if(av_dup_packet(pkt) < 0) { |
2162 av_free(duration_error); | 2181 av_free(duration_error); |
2163 return AVERROR(ENOMEM); | 2182 return AVERROR(ENOMEM); |
2164 } | 2183 } |
2165 | 2184 |
2166 read_size += pkt->size; | 2185 read_size += pkt->size; |
2167 | 2186 |
2168 st = ic->streams[pkt->stream_index]; | 2187 st = ic->streams[pkt->stream_index]; |
2169 if(codec_info_nb_frames[st->index]>1) { | 2188 if(st->codec_info_nb_frames>1) { |
2170 if (st->time_base.den > 0 && av_rescale_q(codec_info_duration[st->in
dex], st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration){ | 2189 if (st->time_base.den > 0 && av_rescale_q(codec_info_duration[st->in
dex], st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration){ |
2171 av_log(ic, AV_LOG_WARNING, "max_analyze_duration reached\n"); | 2190 av_log(ic, AV_LOG_WARNING, "max_analyze_duration reached\n"); |
2172 break; | 2191 break; |
2173 } | 2192 } |
2174 codec_info_duration[st->index] += pkt->duration; | 2193 codec_info_duration[st->index] += pkt->duration; |
2175 } | 2194 } |
2176 if (pkt->duration != 0) | 2195 st->codec_info_nb_frames++; |
2177 codec_info_nb_frames[st->index]++; | |
2178 | 2196 |
2179 { | 2197 { |
2180 int index= pkt->stream_index; | 2198 int index= pkt->stream_index; |
2181 int64_t last= last_dts[index]; | 2199 int64_t last= last_dts[index]; |
2182 int64_t duration= pkt->dts - last; | 2200 int64_t duration= pkt->dts - last; |
2183 | 2201 |
2184 if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && duration>
0){ | 2202 if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && duration>
0){ |
2185 double dur= duration * av_q2d(st->time_base); | 2203 double dur= duration * av_q2d(st->time_base); |
2186 | 2204 |
2187 // if(st->codec->codec_type == CODEC_TYPE_VIDEO) | 2205 // if(st->codec->codec_type == CODEC_TYPE_VIDEO) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2223 } | 2241 } |
2224 | 2242 |
2225 // close codecs which were opened in try_decode_frame() | 2243 // close codecs which were opened in try_decode_frame() |
2226 for(i=0;i<ic->nb_streams;i++) { | 2244 for(i=0;i<ic->nb_streams;i++) { |
2227 st = ic->streams[i]; | 2245 st = ic->streams[i]; |
2228 if(st->codec->codec) | 2246 if(st->codec->codec) |
2229 avcodec_close(st->codec); | 2247 avcodec_close(st->codec); |
2230 } | 2248 } |
2231 for(i=0;i<ic->nb_streams;i++) { | 2249 for(i=0;i<ic->nb_streams;i++) { |
2232 st = ic->streams[i]; | 2250 st = ic->streams[i]; |
2233 if(codec_info_nb_frames[i]>2 && !st->avg_frame_rate.num) | 2251 if(st->codec_info_nb_frames>2 && !st->avg_frame_rate.num && codec_info_d
uration[i]) |
2234 av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, | 2252 av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, |
2235 (codec_info_nb_frames[i]-2)*(int64_t)st->time_base.den, | 2253 (st->codec_info_nb_frames-2)*(int64_t)st->time_base.den, |
2236 codec_info_duration[i] *(int64_t)st->time_base.num, 600
00); | 2254 codec_info_duration[i] *(int64_t)st->time_base.num, 600
00); |
2237 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { | 2255 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { |
2238 if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag
&& !st->codec->bits_per_coded_sample) | 2256 if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag
&& !st->codec->bits_per_coded_sample) |
2239 st->codec->codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec->pi
x_fmt); | 2257 st->codec->codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec->pi
x_fmt); |
2240 | 2258 |
2241 // the check for tb_unreliable() is not completely correct, since th
is is not about handling | 2259 // the check for tb_unreliable() is not completely correct, since th
is is not about handling |
2242 // a unreliable/inexact time base, but a time base that is finer tha
n necessary, as e.g. | 2260 // a unreliable/inexact time base, but a time base that is finer tha
n necessary, as e.g. |
2243 // ipmovie.c produces. | 2261 // ipmovie.c produces. |
2244 if (tb_unreliable(st->codec) && duration_count[i] > 15 && duration_g
cd[i] > 1) | 2262 if (tb_unreliable(st->codec) && duration_count[i] > 15 && duration_g
cd[i] > 1 && !st->r_frame_rate.num) |
2245 av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time
_base.den, st->time_base.num * duration_gcd[i], INT_MAX); | 2263 av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time
_base.den, st->time_base.num * duration_gcd[i], INT_MAX); |
2246 if(duration_count[i] | 2264 if(duration_count[i] && !st->r_frame_rate.num |
2247 && tb_unreliable(st->codec) /*&& | 2265 && tb_unreliable(st->codec) /*&& |
2248 //FIXME we should not special-case MPEG-2, but this needs testing
with non-MPEG-2 ... | 2266 //FIXME we should not special-case MPEG-2, but this needs testing
with non-MPEG-2 ... |
2249 st->time_base.num*duration_sum[i]/duration_count[i]*101LL > st->t
ime_base.den*/){ | 2267 st->time_base.num*duration_sum[i]/duration_count[i]*101LL > st->t
ime_base.den*/){ |
2250 int num = 0; | 2268 int num = 0; |
2251 double best_error= 2*av_q2d(st->time_base); | 2269 double best_error= 2*av_q2d(st->time_base); |
2252 best_error= best_error*best_error*duration_count[i]*1000*12*30; | 2270 best_error= best_error*best_error*duration_count[i]*1000*12*30; |
2253 | 2271 |
2254 for(j=1; j<MAX_STD_TIMEBASES; j++){ | 2272 for(j=1; j<MAX_STD_TIMEBASES; j++){ |
2255 double error= duration_error[i][j] * get_std_framerate(j); | 2273 double error= duration_error[i][j] * get_std_framerate(j); |
2256 // if(st->codec->codec_type == CODEC_TYPE_VIDEO) | 2274 // if(st->codec->codec_type == CODEC_TYPE_VIDEO) |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2529 } | 2547 } |
2530 if(!st->codec->block_align) | 2548 if(!st->codec->block_align) |
2531 st->codec->block_align = st->codec->channels * | 2549 st->codec->block_align = st->codec->channels * |
2532 av_get_bits_per_sample(st->codec->codec_id) >> 3; | 2550 av_get_bits_per_sample(st->codec->codec_id) >> 3; |
2533 break; | 2551 break; |
2534 case CODEC_TYPE_VIDEO: | 2552 case CODEC_TYPE_VIDEO: |
2535 if(st->codec->time_base.num<=0 || st->codec->time_base.den<=0){ //FI
XME audio too? | 2553 if(st->codec->time_base.num<=0 || st->codec->time_base.den<=0){ //FI
XME audio too? |
2536 av_log(s, AV_LOG_ERROR, "time base not set\n"); | 2554 av_log(s, AV_LOG_ERROR, "time base not set\n"); |
2537 return -1; | 2555 return -1; |
2538 } | 2556 } |
2539 if(st->codec->width<=0 || st->codec->height<=0){ | 2557 if((st->codec->width<=0 || st->codec->height<=0) && !(s->oformat->fl
ags & AVFMT_NODIMENSIONS)){ |
2540 av_log(s, AV_LOG_ERROR, "dimensions not set\n"); | 2558 av_log(s, AV_LOG_ERROR, "dimensions not set\n"); |
2541 return -1; | 2559 return -1; |
2542 } | 2560 } |
2543 if(av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)
){ | 2561 if(av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)
){ |
2544 av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between encoder a
nd muxer layer\n"); | 2562 av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between encoder a
nd muxer layer\n"); |
2545 return -1; | 2563 return -1; |
2546 } | 2564 } |
2547 break; | 2565 break; |
2548 } | 2566 } |
2549 | 2567 |
(...skipping 16 matching lines...) Expand all Loading... |
2566 if (!s->priv_data && s->oformat->priv_data_size > 0) { | 2584 if (!s->priv_data && s->oformat->priv_data_size > 0) { |
2567 s->priv_data = av_mallocz(s->oformat->priv_data_size); | 2585 s->priv_data = av_mallocz(s->oformat->priv_data_size); |
2568 if (!s->priv_data) | 2586 if (!s->priv_data) |
2569 return AVERROR(ENOMEM); | 2587 return AVERROR(ENOMEM); |
2570 } | 2588 } |
2571 | 2589 |
2572 #if LIBAVFORMAT_VERSION_MAJOR < 53 | 2590 #if LIBAVFORMAT_VERSION_MAJOR < 53 |
2573 ff_metadata_mux_compat(s); | 2591 ff_metadata_mux_compat(s); |
2574 #endif | 2592 #endif |
2575 | 2593 |
| 2594 /* set muxer identification string */ |
| 2595 if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) { |
| 2596 AVMetadata *m; |
| 2597 AVMetadataTag *t; |
| 2598 |
| 2599 if (!(m = av_mallocz(sizeof(AVMetadata)))) |
| 2600 return AVERROR(ENOMEM); |
| 2601 av_metadata_set2(&m, "encoder", LIBAVFORMAT_IDENT, 0); |
| 2602 metadata_conv(&m, s->oformat->metadata_conv, NULL); |
| 2603 if ((t = av_metadata_get(m, "", NULL, AV_METADATA_IGNORE_SUFFIX))) |
| 2604 av_metadata_set2(&s->metadata, t->key, t->value, 0); |
| 2605 av_metadata_free(&m); |
| 2606 } |
| 2607 |
2576 if(s->oformat->write_header){ | 2608 if(s->oformat->write_header){ |
2577 ret = s->oformat->write_header(s); | 2609 ret = s->oformat->write_header(s); |
2578 if (ret < 0) | 2610 if (ret < 0) |
2579 return ret; | 2611 return ret; |
2580 } | 2612 } |
2581 | 2613 |
2582 /* init PTS generation */ | 2614 /* init PTS generation */ |
2583 for(i=0;i<s->nb_streams;i++) { | 2615 for(i=0;i<s->nb_streams;i++) { |
2584 int64_t den = AV_NOPTS_VALUE; | 2616 int64_t den = AV_NOPTS_VALUE; |
2585 st = s->streams[i]; | 2617 st = s->streams[i]; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2628 if((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VAL
UE && !delay){ | 2660 if((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VAL
UE && !delay){ |
2629 pkt->dts= | 2661 pkt->dts= |
2630 // pkt->pts= st->cur_dts; | 2662 // pkt->pts= st->cur_dts; |
2631 pkt->pts= st->pts.val; | 2663 pkt->pts= st->pts.val; |
2632 } | 2664 } |
2633 | 2665 |
2634 //calculate dts from pts | 2666 //calculate dts from pts |
2635 if(pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_
REORDER_DELAY){ | 2667 if(pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_
REORDER_DELAY){ |
2636 st->pts_buffer[0]= pkt->pts; | 2668 st->pts_buffer[0]= pkt->pts; |
2637 for(i=1; i<delay+1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++) | 2669 for(i=1; i<delay+1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++) |
2638 st->pts_buffer[i]= (i-delay-1) * pkt->duration; | 2670 st->pts_buffer[i]= pkt->pts + (i-delay-1) * pkt->duration; |
2639 for(i=0; i<delay && st->pts_buffer[i] > st->pts_buffer[i+1]; i++) | 2671 for(i=0; i<delay && st->pts_buffer[i] > st->pts_buffer[i+1]; i++) |
2640 FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i+1]); | 2672 FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i+1]); |
2641 | 2673 |
2642 pkt->dts= st->pts_buffer[0]; | 2674 pkt->dts= st->pts_buffer[0]; |
2643 } | 2675 } |
2644 | 2676 |
2645 if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && st->cur_dts >= pkt->dts){ | 2677 if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && st->cur_dts >= pkt->dts){ |
2646 av_log(s, AV_LOG_ERROR, | 2678 av_log(s, AV_LOG_ERROR, |
2647 "st:%d error, non monotone timestamps %"PRId64" >= %"PRId64"\n", | 2679 "st:%d error, non monotone timestamps %"PRId64" >= %"PRId64"\n", |
2648 st->index, st->cur_dts, pkt->dts); | 2680 st->index, st->cur_dts, pkt->dts); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2724 this_pktl->next= *next_point; | 2756 this_pktl->next= *next_point; |
2725 | 2757 |
2726 s->streams[pkt->stream_index]->last_in_packet_buffer= | 2758 s->streams[pkt->stream_index]->last_in_packet_buffer= |
2727 *next_point= this_pktl; | 2759 *next_point= this_pktl; |
2728 } | 2760 } |
2729 | 2761 |
2730 int ff_interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVPacket *pkt) | 2762 int ff_interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVPacket *pkt) |
2731 { | 2763 { |
2732 AVStream *st = s->streams[ pkt ->stream_index]; | 2764 AVStream *st = s->streams[ pkt ->stream_index]; |
2733 AVStream *st2= s->streams[ next->stream_index]; | 2765 AVStream *st2= s->streams[ next->stream_index]; |
2734 int64_t left = st2->time_base.num * (int64_t)st ->time_base.den; | 2766 int64_t a= st2->time_base.num * (int64_t)st ->time_base.den; |
2735 int64_t right= st ->time_base.num * (int64_t)st2->time_base.den; | 2767 int64_t b= st ->time_base.num * (int64_t)st2->time_base.den; |
2736 | 2768 return av_rescale_rnd(pkt->dts, b, a, AV_ROUND_DOWN) < next->dts; |
2737 if (pkt->dts == AV_NOPTS_VALUE) | |
2738 return 0; | |
2739 | |
2740 return next->dts * left > pkt->dts * right; //FIXME this can overflow | |
2741 } | 2769 } |
2742 | 2770 |
2743 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pk
t, int flush){ | 2771 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pk
t, int flush){ |
2744 AVPacketList *pktl; | 2772 AVPacketList *pktl; |
2745 int stream_count=0; | 2773 int stream_count=0; |
2746 int i; | 2774 int i; |
2747 | 2775 |
2748 if(pkt){ | 2776 if(pkt){ |
2749 ff_interleave_add_packet(s, pkt, ff_interleave_compare_dts); | 2777 ff_interleave_add_packet(s, pkt, ff_interleave_compare_dts); |
2750 } | 2778 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2838 goto fail; | 2866 goto fail; |
2839 if(url_ferror(s->pb)) | 2867 if(url_ferror(s->pb)) |
2840 goto fail; | 2868 goto fail; |
2841 } | 2869 } |
2842 | 2870 |
2843 if(s->oformat->write_trailer) | 2871 if(s->oformat->write_trailer) |
2844 ret = s->oformat->write_trailer(s); | 2872 ret = s->oformat->write_trailer(s); |
2845 fail: | 2873 fail: |
2846 if(ret == 0) | 2874 if(ret == 0) |
2847 ret=url_ferror(s->pb); | 2875 ret=url_ferror(s->pb); |
2848 for(i=0;i<s->nb_streams;i++) | 2876 for(i=0;i<s->nb_streams;i++) { |
2849 av_freep(&s->streams[i]->priv_data); | 2877 av_freep(&s->streams[i]->priv_data); |
| 2878 av_freep(&s->streams[i]->index_entries); |
| 2879 } |
2850 av_freep(&s->priv_data); | 2880 av_freep(&s->priv_data); |
2851 return ret; | 2881 return ret; |
2852 } | 2882 } |
2853 | 2883 |
2854 void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int i
dx) | 2884 void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int i
dx) |
2855 { | 2885 { |
2856 int i, j; | 2886 int i, j; |
2857 AVProgram *program=NULL; | 2887 AVProgram *program=NULL; |
2858 void *tmp; | 2888 void *tmp; |
2859 | 2889 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2908 int g = av_gcd(st->time_base.num, st->time_base.den); | 2938 int g = av_gcd(st->time_base.num, st->time_base.den); |
2909 AVMetadataTag *lang = av_metadata_get(st->metadata, "language", NULL, 0); | 2939 AVMetadataTag *lang = av_metadata_get(st->metadata, "language", NULL, 0); |
2910 avcodec_string(buf, sizeof(buf), st->codec, is_output); | 2940 avcodec_string(buf, sizeof(buf), st->codec, is_output); |
2911 av_log(NULL, AV_LOG_INFO, " Stream #%d.%d", index, i); | 2941 av_log(NULL, AV_LOG_INFO, " Stream #%d.%d", index, i); |
2912 /* the pid is an important information, so we display it */ | 2942 /* the pid is an important information, so we display it */ |
2913 /* XXX: add a generic system */ | 2943 /* XXX: add a generic system */ |
2914 if (flags & AVFMT_SHOW_IDS) | 2944 if (flags & AVFMT_SHOW_IDS) |
2915 av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id); | 2945 av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id); |
2916 if (lang) | 2946 if (lang) |
2917 av_log(NULL, AV_LOG_INFO, "(%s)", lang->value); | 2947 av_log(NULL, AV_LOG_INFO, "(%s)", lang->value); |
2918 av_log(NULL, AV_LOG_DEBUG, ", %d/%d", st->time_base.num/g, st->time_base.den
/g); | 2948 av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames, st->time
_base.num/g, st->time_base.den/g); |
2919 av_log(NULL, AV_LOG_INFO, ": %s", buf); | 2949 av_log(NULL, AV_LOG_INFO, ": %s", buf); |
2920 if (st->sample_aspect_ratio.num && // default | 2950 if (st->sample_aspect_ratio.num && // default |
2921 av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)) { | 2951 av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)) { |
2922 AVRational display_aspect_ratio; | 2952 AVRational display_aspect_ratio; |
2923 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, | 2953 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, |
2924 st->codec->width*st->sample_aspect_ratio.num, | 2954 st->codec->width*st->sample_aspect_ratio.num, |
2925 st->codec->height*st->sample_aspect_ratio.den, | 2955 st->codec->height*st->sample_aspect_ratio.den, |
2926 1024*1024); | 2956 1024*1024); |
2927 av_log(NULL, AV_LOG_INFO, ", PAR %d:%d DAR %d:%d", | 2957 av_log(NULL, AV_LOG_INFO, ", PAR %d:%d DAR %d:%d", |
2928 st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, | 2958 st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2982 secs, (int)av_rescale(us, 1000000, AV_TIME_BASE)); | 3012 secs, (int)av_rescale(us, 1000000, AV_TIME_BASE)); |
2983 } | 3013 } |
2984 av_log(NULL, AV_LOG_INFO, ", bitrate: "); | 3014 av_log(NULL, AV_LOG_INFO, ", bitrate: "); |
2985 if (ic->bit_rate) { | 3015 if (ic->bit_rate) { |
2986 av_log(NULL, AV_LOG_INFO,"%d kb/s", ic->bit_rate / 1000); | 3016 av_log(NULL, AV_LOG_INFO,"%d kb/s", ic->bit_rate / 1000); |
2987 } else { | 3017 } else { |
2988 av_log(NULL, AV_LOG_INFO, "N/A"); | 3018 av_log(NULL, AV_LOG_INFO, "N/A"); |
2989 } | 3019 } |
2990 av_log(NULL, AV_LOG_INFO, "\n"); | 3020 av_log(NULL, AV_LOG_INFO, "\n"); |
2991 } | 3021 } |
| 3022 for (i = 0; i < ic->nb_chapters; i++) { |
| 3023 AVChapter *ch = ic->chapters[i]; |
| 3024 av_log(NULL, AV_LOG_INFO, " Chapter #%d.%d: ", index, i); |
| 3025 av_log(NULL, AV_LOG_INFO, "start %f, ", ch->start * av_q2d(ch->time_base
)); |
| 3026 av_log(NULL, AV_LOG_INFO, "end %f\n", ch->end * av_q2d(ch->time_base
)); |
| 3027 |
| 3028 dump_metadata(NULL, ch->metadata, " "); |
| 3029 } |
2992 if(ic->nb_programs) { | 3030 if(ic->nb_programs) { |
2993 int j, k, total = 0; | 3031 int j, k, total = 0; |
2994 for(j=0; j<ic->nb_programs; j++) { | 3032 for(j=0; j<ic->nb_programs; j++) { |
2995 AVMetadataTag *name = av_metadata_get(ic->programs[j]->metadata, | 3033 AVMetadataTag *name = av_metadata_get(ic->programs[j]->metadata, |
2996 "name", NULL, 0); | 3034 "name", NULL, 0); |
2997 av_log(NULL, AV_LOG_INFO, " Program %d %s\n", ic->programs[j]->id, | 3035 av_log(NULL, AV_LOG_INFO, " Program %d %s\n", ic->programs[j]->id, |
2998 name ? name->value : ""); | 3036 name ? name->value : ""); |
2999 dump_metadata(NULL, ic->programs[j]->metadata, " "); | 3037 dump_metadata(NULL, ic->programs[j]->metadata, " "); |
3000 for(k=0; k<ic->programs[j]->nb_stream_indexes; k++) { | 3038 for(k=0; k<ic->programs[j]->nb_stream_indexes; k++) { |
3001 dump_stream_format(ic, ic->programs[j]->stream_index[k], index,
is_output); | 3039 dump_stream_format(ic, ic->programs[j]->stream_index[k], index,
is_output); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3318 void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload) | 3356 void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload) |
3319 { | 3357 { |
3320 pkt_dump_internal(NULL, f, 0, pkt, dump_payload); | 3358 pkt_dump_internal(NULL, f, 0, pkt, dump_payload); |
3321 } | 3359 } |
3322 | 3360 |
3323 void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload) | 3361 void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload) |
3324 { | 3362 { |
3325 pkt_dump_internal(avcl, NULL, level, pkt, dump_payload); | 3363 pkt_dump_internal(avcl, NULL, level, pkt, dump_payload); |
3326 } | 3364 } |
3327 | 3365 |
3328 void url_split(char *proto, int proto_size, | 3366 void ff_url_split(char *proto, int proto_size, |
3329 char *authorization, int authorization_size, | 3367 char *authorization, int authorization_size, |
3330 char *hostname, int hostname_size, | 3368 char *hostname, int hostname_size, |
3331 int *port_ptr, | 3369 int *port_ptr, |
3332 char *path, int path_size, | 3370 char *path, int path_size, |
3333 const char *url) | 3371 const char *url) |
3334 { | 3372 { |
3335 const char *p, *ls, *at, *col, *brk; | 3373 const char *p, *ls, *at, *col, *brk; |
3336 | 3374 |
3337 if (port_ptr) *port_ptr = -1; | 3375 if (port_ptr) *port_ptr = -1; |
3338 if (proto_size > 0) proto[0] = 0; | 3376 if (proto_size > 0) proto[0] = 0; |
3339 if (authorization_size > 0) authorization[0] = 0; | 3377 if (authorization_size > 0) authorization[0] = 0; |
3340 if (hostname_size > 0) hostname[0] = 0; | 3378 if (hostname_size > 0) hostname[0] = 0; |
3341 if (path_size > 0) path[0] = 0; | 3379 if (path_size > 0) path[0] = 0; |
3342 | 3380 |
3343 /* parse protocol */ | 3381 /* parse protocol */ |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3409 | 3447 |
3410 if(av_reduce(&s->time_base.num, &s->time_base.den, pts_num, pts_den, INT_MAX
)){ | 3448 if(av_reduce(&s->time_base.num, &s->time_base.den, pts_num, pts_den, INT_MAX
)){ |
3411 if(s->time_base.num != pts_num) | 3449 if(s->time_base.num != pts_num) |
3412 av_log(NULL, AV_LOG_DEBUG, "st:%d removing common factor %d from tim
ebase\n", s->index, pts_num/s->time_base.num); | 3450 av_log(NULL, AV_LOG_DEBUG, "st:%d removing common factor %d from tim
ebase\n", s->index, pts_num/s->time_base.num); |
3413 }else | 3451 }else |
3414 av_log(NULL, AV_LOG_WARNING, "st:%d has too large timebase, reducing\n",
s->index); | 3452 av_log(NULL, AV_LOG_WARNING, "st:%d has too large timebase, reducing\n",
s->index); |
3415 | 3453 |
3416 if(!s->time_base.num || !s->time_base.den) | 3454 if(!s->time_base.num || !s->time_base.den) |
3417 s->time_base.num= s->time_base.den= 0; | 3455 s->time_base.num= s->time_base.den= 0; |
3418 } | 3456 } |
| 3457 |
| 3458 int ff_url_join(char *str, int size, const char *proto, |
| 3459 const char *authorization, const char *hostname, |
| 3460 int port, const char *fmt, ...) |
| 3461 { |
| 3462 #if CONFIG_NETWORK |
| 3463 struct addrinfo hints, *ai; |
| 3464 #endif |
| 3465 |
| 3466 str[0] = '\0'; |
| 3467 if (proto) |
| 3468 av_strlcatf(str, size, "%s://", proto); |
| 3469 if (authorization) |
| 3470 av_strlcatf(str, size, "%s@", authorization); |
| 3471 #if CONFIG_NETWORK && defined(AF_INET6) |
| 3472 /* Determine if hostname is a numerical IPv6 address, |
| 3473 * properly escape it within [] in that case. */ |
| 3474 memset(&hints, 0, sizeof(hints)); |
| 3475 hints.ai_flags = AI_NUMERICHOST; |
| 3476 if (!getaddrinfo(hostname, NULL, &hints, &ai)) { |
| 3477 if (ai->ai_family == AF_INET6) { |
| 3478 av_strlcat(str, "[", size); |
| 3479 av_strlcat(str, hostname, size); |
| 3480 av_strlcat(str, "]", size); |
| 3481 } else { |
| 3482 av_strlcat(str, hostname, size); |
| 3483 } |
| 3484 freeaddrinfo(ai); |
| 3485 } else |
| 3486 #endif |
| 3487 /* Not an IPv6 address, just output the plain string. */ |
| 3488 av_strlcat(str, hostname, size); |
| 3489 |
| 3490 if (port >= 0) |
| 3491 av_strlcatf(str, size, ":%d", port); |
| 3492 if (fmt) { |
| 3493 va_list vl; |
| 3494 int len = strlen(str); |
| 3495 |
| 3496 va_start(vl, fmt); |
| 3497 vsnprintf(str + len, size > len ? size - len : 0, fmt, vl); |
| 3498 va_end(vl); |
| 3499 } |
| 3500 return strlen(str); |
| 3501 } |
OLD | NEW |