]> git.sesse.net Git - ffmpeg/blobdiff - ffmpeg.c
MAINTAINERS: update versions
[ffmpeg] / ffmpeg.c
index 0ca5b054c1eb6801065d5b010f9410d0c54a626c..51cd58719826e9a157e69896fb65bc69d26bc8ed 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -438,6 +438,8 @@ typedef struct OptionsContext {
     int        nb_filters;
 } OptionsContext;
 
+static void do_video_stats(AVFormatContext *os, OutputStream *ost, int frame_size);
+
 #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
 {\
     int i, ret;\
@@ -711,7 +713,7 @@ static char *choose_pix_fmts(OutputStream *ost)
     }
     if (ost->st->codec->pix_fmt != PIX_FMT_NONE) {
         return av_strdup(av_get_pix_fmt_name(choose_pixel_fmt(ost->st, ost->enc, ost->st->codec->pix_fmt)));
-    } else if (ost->enc->pix_fmts) {
+    } else if (ost->enc && ost->enc->pix_fmts) {
         const enum PixelFormat *p;
         AVIOContext *s = NULL;
         uint8_t *ret;
@@ -1678,13 +1680,6 @@ static void choose_sample_fmt(AVStream *st, AVCodec *codec)
     }
 }
 
-static double
-get_sync_ipts(const OutputStream *ost, int64_t pts)
-{
-    OutputFile *of = output_files[ost->file_index];
-    return (double)(pts - of->start_time) / AV_TIME_BASE;
-}
-
 static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
 {
     AVBitStreamFilterContext *bsfc = ost->bitstream_filters;
@@ -1912,55 +1907,15 @@ static void do_subtitle_out(AVFormatContext *s,
     }
 }
 
-static double psnr(double d)
+static void do_video_out(AVFormatContext *s,
+                         OutputStream *ost,
+                         AVFrame *in_picture,
+                         float quality)
 {
-    return -10.0 * log(d) / log(10.0);
-}
-
-static void do_video_stats(AVFormatContext *os, OutputStream *ost,
-                           int frame_size)
-{
-    AVCodecContext *enc;
-    int frame_number;
-    double ti1, bitrate, avg_bitrate;
-
-    /* this is executed just the first time do_video_stats is called */
-    if (!vstats_file) {
-        vstats_file = fopen(vstats_filename, "w");
-        if (!vstats_file) {
-            perror("fopen");
-            exit_program(1);
-        }
-    }
-
-    enc = ost->st->codec;
-    if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
-        frame_number = ost->frame_number;
-        fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality / (float)FF_QP2LAMBDA);
-        if (enc->flags&CODEC_FLAG_PSNR)
-            fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0] / (enc->width * enc->height * 255.0 * 255.0)));
-
-        fprintf(vstats_file,"f_size= %6d ", frame_size);
-        /* compute pts value */
-        ti1 = ost->sync_opts * av_q2d(enc->time_base);
-        if (ti1 < 0.01)
-            ti1 = 0.01;
-
-        bitrate     = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;
-        avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0;
-        fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
-               (double)video_size / 1024, ti1, bitrate, avg_bitrate);
-        fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(enc->coded_frame->pict_type));
-    }
-}
-
-
-static void do_video_out(AVFormatContext *s, OutputStream *ost,
-                         AVFrame *in_picture, float quality)
-{
-    int nb_frames, i, ret, format_video_sync;
+    int ret, format_video_sync;
     AVPacket pkt;
-    AVCodecContext *enc;
+    AVCodecContext *enc = ost->st->codec;
+    int nb_frames, i;
     double sync_ipts, delta;
     double duration = 0;
     int frame_size = 0;
@@ -1969,12 +1924,10 @@ static void do_video_out(AVFormatContext *s, OutputStream *ost,
     if (ost->source_index >= 0)
         ist = input_streams[ost->source_index];
 
-    enc = ost->st->codec;
-
     if(ist && ist->st->start_time != AV_NOPTS_VALUE && ist->st->first_dts != AV_NOPTS_VALUE && ost->frame_rate.num)
         duration = 1/(av_q2d(ost->frame_rate) * av_q2d(enc->time_base));
 
-    sync_ipts = get_sync_ipts(ost, in_picture->pts) / av_q2d(enc->time_base);
+    sync_ipts = in_picture->pts;
     delta = sync_ipts - ost->sync_opts + duration;
 
     /* by default, we output a single frame */
@@ -2022,6 +1975,8 @@ duplicate_frame:
     pkt.data = NULL;
     pkt.size = 0;
 
+    in_picture->pts = ost->sync_opts;
+
     if (s->oformat->flags & AVFMT_RAWPICTURE &&
         enc->codec->id == CODEC_ID_RAWVIDEO) {
         /* raw pictures are written as AVPicture structure to
@@ -2031,7 +1986,7 @@ duplicate_frame:
         enc->coded_frame->top_field_first  = in_picture->top_field_first;
         pkt.data   = (uint8_t *)in_picture;
         pkt.size   =  sizeof(AVPicture);
-        pkt.pts    = av_rescale_q(ost->sync_opts, enc->time_base, ost->st->time_base);
+        pkt.pts    = av_rescale_q(in_picture->pts, enc->time_base, ost->st->time_base);
         pkt.flags |= AV_PKT_FLAG_KEY;
 
         write_frame(s, &pkt, ost);
@@ -2055,7 +2010,6 @@ duplicate_frame:
         big_picture.quality = quality;
         if (!enc->me_threshold)
             big_picture.pict_type = 0;
-        big_picture.pts = ost->sync_opts;
         if (ost->forced_kf_index < ost->forced_kf_count &&
             big_picture.pts >= ost->forced_kf_pts[ost->forced_kf_index]) {
             big_picture.pict_type = AV_PICTURE_TYPE_I;
@@ -2111,6 +2065,48 @@ duplicate_frame:
         do_video_stats(output_files[ost->file_index]->ctx, ost, frame_size);
 }
 
+static double psnr(double d)
+{
+    return -10.0 * log(d) / log(10.0);
+}
+
+static void do_video_stats(AVFormatContext *os, OutputStream *ost,
+                           int frame_size)
+{
+    AVCodecContext *enc;
+    int frame_number;
+    double ti1, bitrate, avg_bitrate;
+
+    /* this is executed just the first time do_video_stats is called */
+    if (!vstats_file) {
+        vstats_file = fopen(vstats_filename, "w");
+        if (!vstats_file) {
+            perror("fopen");
+            exit_program(1);
+        }
+    }
+
+    enc = ost->st->codec;
+    if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+        frame_number = ost->frame_number;
+        fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality / (float)FF_QP2LAMBDA);
+        if (enc->flags&CODEC_FLAG_PSNR)
+            fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0] / (enc->width * enc->height * 255.0 * 255.0)));
+
+        fprintf(vstats_file,"f_size= %6d ", frame_size);
+        /* compute pts value */
+        ti1 = ost->sync_opts * av_q2d(enc->time_base);
+        if (ti1 < 0.01)
+            ti1 = 0.01;
+
+        bitrate     = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;
+        avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0;
+        fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
+               (double)video_size / 1024, ti1, bitrate, avg_bitrate);
+        fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(enc->coded_frame->pict_type));
+    }
+}
+
 /* check for new output on any of the filtergraphs */
 static int poll_filters(void)
 {
@@ -2159,22 +2155,22 @@ static int poll_filters(void)
                     break;
                 }
                 frame_pts = AV_NOPTS_VALUE;
-                if (ost->enc->type == AVMEDIA_TYPE_VIDEO)
-                    filtered_frame->pts = frame_pts = av_rescale_q(picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
-                else if (picref->pts != AV_NOPTS_VALUE)
+                if (picref->pts != AV_NOPTS_VALUE) {
                     filtered_frame->pts = frame_pts = av_rescale_q(picref->pts,
                                                     ost->filter->filter->inputs[0]->time_base,
                                                     ost->st->codec->time_base) -
                                         av_rescale_q(of->start_time,
                                                     AV_TIME_BASE_Q,
                                                     ost->st->codec->time_base);
+
+                    if (of->start_time && filtered_frame->pts < 0) {
+                        avfilter_unref_buffer(picref);
+                        continue;
+                    }
+                }
                 //if (ost->source_index >= 0)
                 //    *filtered_frame= *input_streams[ost->source_index]->decoded_frame; //for me_threshold
 
-                if (of->start_time && filtered_frame->pts < of->start_time) {
-                    avfilter_unref_buffer(picref);
-                    continue;
-                }
 
                 switch (ost->filter->filter->inputs[0]->type) {
                 case AVMEDIA_TYPE_VIDEO:
@@ -2542,7 +2538,7 @@ static int guess_input_channel_layout(InputStream *ist)
     return 1;
 }
 
-static int transcode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
+static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
 {
     AVFrame *decoded_frame;
     AVCodecContext *avctx = ist->st->codec;
@@ -2643,7 +2639,7 @@ static int transcode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
     return ret;
 }
 
-static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output)
+static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output)
 {
     AVFrame *decoded_frame;
     void *buffer_to_free = NULL;
@@ -2828,10 +2824,10 @@ static int output_packet(InputStream *ist, const AVPacket *pkt)
 
         switch (ist->st->codec->codec_type) {
         case AVMEDIA_TYPE_AUDIO:
-            ret = transcode_audio    (ist, &avpkt, &got_output);
+            ret = decode_audio    (ist, &avpkt, &got_output);
             break;
         case AVMEDIA_TYPE_VIDEO:
-            ret = transcode_video    (ist, &avpkt, &got_output);
+            ret = decode_video    (ist, &avpkt, &got_output);
             if (avpkt.duration) {
                 duration = av_rescale_q(avpkt.duration, ist->st->time_base, AV_TIME_BASE_Q);
             } else if(ist->st->codec->time_base.num != 0 && ist->st->codec->time_base.den != 0) {