]> git.sesse.net Git - ffmpeg/blobdiff - avconv.c
mpegvideoenc: make a table const
[ffmpeg] / avconv.c
index 0b75cbe21498f5601db28ed955b7315fca05a11a..fe606250feb8a0caa98e2b7628f6822ae9891945 100644 (file)
--- a/avconv.c
+++ b/avconv.c
@@ -38,6 +38,7 @@
 #include "libavutil/parseutils.h"
 #include "libavutil/samplefmt.h"
 #include "libavutil/fifo.h"
+#include "libavutil/hwcontext.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/dict.h"
@@ -190,7 +191,6 @@ static void avconv_cleanup(int ret)
         for (j = 0; j < ost->nb_bitstream_filters; j++)
             av_bsf_free(&ost->bsf_ctx[j]);
         av_freep(&ost->bsf_ctx);
-        av_freep(&ost->bitstream_filters);
 
         av_frame_free(&ost->filtered_frame);
 
@@ -206,7 +206,6 @@ static void avconv_cleanup(int ret)
         if (ost->muxing_queue) {
             while (av_fifo_size(ost->muxing_queue)) {
                 AVPacket pkt;
-                av_log(NULL, AV_LOG_INFO, "after av_fifo_size()\n");
                 av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL);
                 av_packet_unref(&pkt);
             }
@@ -910,7 +909,7 @@ static void print_report(int is_last_report, int64_t timer_start)
     char buf[1024];
     OutputStream *ost;
     AVFormatContext *oc;
-    int64_t total_size;
+    int64_t total_size = 0;
     AVCodecContext *enc;
     int frame_number, vid, i;
     double bitrate, ti1, pts;
@@ -935,16 +934,17 @@ static void print_report(int is_last_report, int64_t timer_start)
 
 
     oc = output_files[0]->ctx;
-
-    total_size = avio_size(oc->pb);
-    if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too
-        total_size = avio_tell(oc->pb);
-    if (total_size < 0) {
-        char errbuf[128];
-        av_strerror(total_size, errbuf, sizeof(errbuf));
-        av_log(NULL, AV_LOG_VERBOSE, "Bitrate not available, "
-               "avio_tell() failed: %s\n", errbuf);
-        total_size = 0;
+    if (oc->pb) {
+        total_size = avio_size(oc->pb);
+        if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too
+            total_size = avio_tell(oc->pb);
+        if (total_size < 0) {
+            char errbuf[128];
+            av_strerror(total_size, errbuf, sizeof(errbuf));
+            av_log(NULL, AV_LOG_VERBOSE, "Bitrate not available, "
+                   "avio_tell() failed: %s\n", errbuf);
+            total_size = 0;
+        }
     }
 
     buf[0] = '\0';
@@ -1351,7 +1351,7 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output,
     /* if the decoder provides a pts, use it instead of the last packet pts.
        the decoder could be delaying output by a packet or more. */
     if (decoded_frame->pts != AV_NOPTS_VALUE)
-        ist->next_dts = decoded_frame->pts;
+        ist->next_dts = av_rescale_q(decoded_frame->pts, ist->st->time_base, AV_TIME_BASE_Q);
     else if (pkt && pkt->pts != AV_NOPTS_VALUE) {
         decoded_frame->pts = pkt->pts;
     }
@@ -1798,17 +1798,8 @@ static int init_output_bsfs(OutputStream *ost)
     if (!ost->nb_bitstream_filters)
         return 0;
 
-    ost->bsf_ctx = av_mallocz_array(ost->nb_bitstream_filters, sizeof(*ost->bsf_ctx));
-    if (!ost->bsf_ctx)
-        return AVERROR(ENOMEM);
-
     for (i = 0; i < ost->nb_bitstream_filters; i++) {
-        ret = av_bsf_alloc(ost->bitstream_filters[i], &ctx);
-        if (ret < 0) {
-            av_log(NULL, AV_LOG_ERROR, "Error allocating a bitstream filter context\n");
-            return ret;
-        }
-        ost->bsf_ctx[i] = ctx;
+        ctx = ost->bsf_ctx[i];
 
         ret = avcodec_parameters_copy(ctx->par_in,
                                       i ? ost->bsf_ctx[i - 1]->par_out : ost->st->codecpar);
@@ -1820,12 +1811,11 @@ static int init_output_bsfs(OutputStream *ost)
         ret = av_bsf_init(ctx);
         if (ret < 0) {
             av_log(NULL, AV_LOG_ERROR, "Error initializing bitstream filter: %s\n",
-                   ost->bitstream_filters[i]->name);
+                   ctx->filter->name);
             return ret;
         }
     }
 
-    ctx = ost->bsf_ctx[ost->nb_bitstream_filters - 1];
     ret = avcodec_parameters_copy(ost->st->codecpar, ctx->par_out);
     if (ret < 0)
         return ret;
@@ -2046,7 +2036,9 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len)
         if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0))
             av_dict_set(&ost->encoder_opts, "threads", "auto", 0);
 
-        if (ost->filter && ost->filter->filter->inputs[0]->hw_frames_ctx) {
+        if (ost->filter && ost->filter->filter->inputs[0]->hw_frames_ctx &&
+            ((AVHWFramesContext*)ost->filter->filter->inputs[0]->hw_frames_ctx->data)->format ==
+            ost->filter->filter->inputs[0]->format) {
             ost->enc_ctx->hw_frames_ctx = av_buffer_ref(ost->filter->filter->inputs[0]->hw_frames_ctx);
             if (!ost->enc_ctx->hw_frames_ctx)
                 return AVERROR(ENOMEM);