]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/utils.c
demux chapters out of matroska
[ffmpeg] / libavformat / utils.c
index caf8df4ebd10e810d8d7067dad5f01d466e44eec..d98db39632eacf84a46c3561da28e6ce682bdc79 100644 (file)
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include "avformat.h"
-#include "opt.h"
-#include "avstring.h"
+#include "libavcodec/opt.h"
+#include "libavutil/avstring.h"
 #include "riff.h"
 #include <sys/time.h>
 #include <time.h>
@@ -282,7 +282,8 @@ static AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int
         if (score > *score_max) {
             *score_max = score;
             fmt = fmt1;
-        }
+        }else if (score == *score_max)
+            fmt = NULL;
     }
     return fmt;
 }
@@ -324,6 +325,7 @@ static const AVOption options[]={
 {"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), FF_OPT_TYPE_INT, 3*AV_TIME_BASE, 0, INT_MAX, D},
 {"cryptokey", "decryption key", OFFSET(key), FF_OPT_TYPE_BINARY, 0, 0, 0, D},
 {"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), FF_OPT_TYPE_INT, 1<<20, 0, INT_MAX, D},
+{"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), FF_OPT_TYPE_INT, 3041280, 0, INT_MAX, D}, /* defaults to 1s of 15fps 352x288 YUYV422 video */
 {NULL},
 };
 
@@ -667,7 +669,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
         if (den && num) {
             pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num);
 
-            if(st->cur_dts == 0)
+            if(st->cur_dts == 0 && pkt->duration != 0)
                 update_initial_durations(s, st, pkt);
         }
     }
@@ -1688,7 +1690,7 @@ static int has_codec_parameters(AVCodecContext *enc)
         val = 1;
         break;
     }
-    return (enc->codec_id != CODEC_ID_NONE && val != 0);
+    return enc->codec_id != CODEC_ID_NONE && val != 0;
 }
 
 static int try_decode_frame(AVStream *st, const uint8_t *data, int size)
@@ -1932,7 +1934,7 @@ int av_find_stream_info(AVFormatContext *ic)
 //                if(st->codec->codec_type == CODEC_TYPE_VIDEO)
 //                    av_log(NULL, AV_LOG_ERROR, "%f\n", dur);
                 if(duration_count[index] < 2)
-                    memset(duration_error, 0, MAX_STREAMS * sizeof(*duration_error));
+                    memset(duration_error[index], 0, sizeof(*duration_error));
                 for(i=1; i<MAX_STD_TIMEBASES; i++){
                     int framerate= get_std_framerate(i);
                     int ticks= lrintf(dur*framerate/(1001*12));
@@ -1989,7 +1991,7 @@ int av_find_stream_info(AVFormatContext *ic)
         count++;
     }
 
-    // close codecs which where opened in try_decode_frame()
+    // close codecs which were opened in try_decode_frame()
     for(i=0;i<ic->nb_streams;i++) {
         st = ic->streams[i];
         if(st->codec->codec)
@@ -2143,8 +2145,14 @@ void av_close_input_stream(AVFormatContext *s)
         av_freep(&s->programs[i]->stream_index);
         av_freep(&s->programs[i]);
     }
+    av_freep(&s->programs);
     flush_packet_queue(s);
     av_freep(&s->priv_data);
+    while(s->num_chapters--) {
+        av_free(s->chapters[s->num_chapters]->title);
+        av_free(s->chapters[s->num_chapters]);
+    }
+    av_freep(&s->chapters);
     av_free(s);
 }
 
@@ -2226,6 +2234,19 @@ void av_set_program_name(AVProgram *program, char *provider_name, char *name)
     }
 }
 
+int ff_new_chapter(AVFormatContext *s, int64_t start, int64_t end, const char *title)
+{
+    AVChapter *chapter = av_mallocz(sizeof(AVChapter));
+    if(!chapter)
+        return AVERROR(ENOMEM);
+    chapter->title = av_strdup(title);
+    chapter->start = start;
+    chapter->end = end;
+
+    dynarray_add(&s->chapters, &s->num_chapters, chapter);
+
+    return 0;
+}
 
 /************************************************************/
 /* output media file */
@@ -2483,7 +2504,7 @@ int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pk
  * @param flush 1 if no further packets are available as input and all
  *              remaining packets should be output
  * @return 1 if a packet was output, 0 if no packet could be output,
- *         < 0 if an error occured
+ *         < 0 if an error occurred
  */
 static int av_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush){
     if(s->oformat->interleave_packet)
@@ -2632,8 +2653,8 @@ void dump_format(AVFormatContext *ic,
             secs %= 60;
             hours = mins / 60;
             mins %= 60;
-            av_log(NULL, AV_LOG_INFO, "%02d:%02d:%02d.%01d", hours, mins, secs,
-                   (10 * us) / AV_TIME_BASE);
+            av_log(NULL, AV_LOG_INFO, "%02d:%02d:%02d.%02d", hours, mins, secs,
+                   (100 * us) / AV_TIME_BASE);
         } else {
             av_log(NULL, AV_LOG_INFO, "N/A");
         }