#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"
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);
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);
}
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;
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';
/* 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;
}
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);
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;
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);