#include "libavutil/colorspace.h"
#include "libavutil/fifo.h"
#include "libavutil/intreadwrite.h"
+#include "libavutil/dict.h"
#include "libavutil/pixdesc.h"
#include "libavutil/avstring.h"
#include "libavutil/libm.h"
# include "libavfilter/avcodec.h"
# include "libavfilter/avfilter.h"
# include "libavfilter/avfiltergraph.h"
+# include "libavfilter/vsink_buffer.h"
# include "libavfilter/vsrc_buffer.h"
#endif
static int nb_input_files_ts_scale[MAX_FILES] = {0};
static AVFormatContext *output_files[MAX_FILES];
-static AVCodec **output_codecs = NULL;
static int nb_output_files = 0;
-static int nb_output_codecs = 0;
static AVStreamMap *stream_maps = NULL;
static int nb_stream_maps;
#endif
static int intra_only = 0;
-static int audio_sample_rate = 44100;
+static int audio_sample_rate = 0;
static int64_t channel_layout = 0;
#define QSCALE_NONE -99999
static float audio_qscale = QSCALE_NONE;
static int audio_disable = 0;
-static int audio_channels = 1;
+static int audio_channels = 0;
static char *audio_codec_name = NULL;
static unsigned int audio_codec_tag = 0;
static char *audio_language = NULL;
static int64_t recording_timestamp = 0;
static int64_t input_ts_offset = 0;
static int file_overwrite = 0;
-static AVMetadata *metadata;
+static AVDictionary *metadata;
static int do_benchmark = 0;
static int do_hex_dump = 0;
static int do_pkt_dump = 0;
struct AVInputStream *sync_ist; /* input stream to sync against */
int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ //FIXME look at frame_number
AVBitStreamFilterContext *bitstream_filters;
+ AVCodec *enc;
+
/* video only */
int video_resample;
AVFrame resample_frame; /* temporary frame for image resampling */
int resample_height;
int resample_width;
int resample_pix_fmt;
+ AVRational frame_rate;
float frame_aspect_ratio;
/** filter graph containing all filters including input & output */
AVCodecContext *codec = ost->st->codec;
AVCodecContext *icodec = ist->st->codec;
- FFSinkContext ffsink_ctx = { .pix_fmt = codec->pix_fmt };
+ enum PixelFormat pix_fmts[] = { codec->pix_fmt, PIX_FMT_NONE };
AVRational sample_aspect_ratio;
char args[255];
int ret;
"src", args, NULL, ost->graph);
if (ret < 0)
return ret;
- ret = avfilter_graph_create_filter(&ost->output_video_filter, &ffsink,
- "out", NULL, &ffsink_ctx, ost->graph);
+ ret = avfilter_graph_create_filter(&ost->output_video_filter, avfilter_get_by_name("buffersink"),
+ "out", NULL, pix_fmts, ost->graph);
if (ret < 0)
return ret;
last_filter = ost->input_video_filter;
ost->graph->scale_sws_opts = av_strdup(args);
if (ost->avfilter) {
- AVFilterInOut *outputs = av_malloc(sizeof(AVFilterInOut));
- AVFilterInOut *inputs = av_malloc(sizeof(AVFilterInOut));
+ AVFilterInOut *outputs = avfilter_inout_alloc();
+ AVFilterInOut *inputs = avfilter_inout_alloc();
outputs->name = av_strdup("in");
outputs->filter_ctx = last_filter;
inputs->pad_idx = 0;
inputs->next = NULL;
- if ((ret = avfilter_graph_parse(ost->graph, ost->avfilter, inputs, outputs, NULL)) < 0)
+ if ((ret = avfilter_graph_parse(ost->graph, ost->avfilter, &inputs, &outputs, NULL)) < 0)
return ret;
av_freep(&ost->avfilter);
} else {
static void term_exit(void)
{
- av_log(NULL, AV_LOG_QUIET, "");
+ av_log(NULL, AV_LOG_QUIET, "%s", "");
#if HAVE_TERMIOS_H
if(!run_as_daemon)
tcsetattr (0, TCSANOW, &oldtty);
av_free(streamid_map);
av_free(input_codecs);
- av_free(output_codecs);
av_free(stream_maps);
av_free(meta_data_maps);
break;
}
if (*p == -1) {
+ if((codec->capabilities & CODEC_CAP_LOSSLESS) && av_get_sample_fmt_name(st->codec->sample_fmt) > av_get_sample_fmt_name(codec->sample_fmts[0]))
+ av_log(NULL, AV_LOG_ERROR, "Convertion will not be lossless'\n");
av_log(NULL, AV_LOG_WARNING,
"Incompatible sample format '%s' for codec '%s', auto-selecting format '%s'\n",
av_get_sample_fmt_name(st->codec->sample_fmt),
int size_out, frame_bytes, ret, resample_changed;
AVCodecContext *enc= ost->st->codec;
AVCodecContext *dec= ist->st->codec;
- int osize= av_get_bits_per_sample_fmt(enc->sample_fmt)/8;
- int isize= av_get_bits_per_sample_fmt(dec->sample_fmt)/8;
+ int osize = av_get_bytes_per_sample(enc->sample_fmt);
+ int isize = av_get_bytes_per_sample(dec->sample_fmt);
const int coded_bps = av_get_bits_per_sample(enc->codec->id);
need_realloc:
av_log(NULL, AV_LOG_INFO,
"Input stream #%d.%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
ist->file_index, ist->st->index,
- ost->resample_width, ost->resample_height, avcodec_get_pix_fmt_name(ost->resample_pix_fmt),
- dec->width , dec->height , avcodec_get_pix_fmt_name(dec->pix_fmt));
+ ost->resample_width, ost->resample_height, av_get_pix_fmt_name(ost->resample_pix_fmt),
+ dec->width , dec->height , av_get_pix_fmt_name(dec->pix_fmt));
ost->resample_width = dec->width;
ost->resample_height = dec->height;
ost->resample_pix_fmt = dec->pix_fmt;
}
}
sws_scale(ost->img_resample_ctx, formatted_picture->data, formatted_picture->linesize,
- 0, ost->resample_height, ost->resample_frame.data, ost->resample_frame.linesize);
+ 0, ost->resample_height, final_picture->data, final_picture->linesize);
}
#endif
int64_t total_size;
AVCodecContext *enc;
int frame_number, vid, i;
- double bitrate, ti1, pts;
+ double bitrate;
+ int64_t pts = INT64_MAX;
static int64_t last_time = -1;
static int qp_histogram[52];
total_size= avio_tell(oc->pb);
buf[0] = '\0';
- ti1 = 1e10;
vid = 0;
for(i=0;i<nb_ostreams;i++) {
float q = -1;
vid = 1;
}
/* compute min output value */
- pts = (double)ost->st->pts.val * av_q2d(ost->st->time_base);
- if ((pts < ti1) && (pts > 0))
- ti1 = pts;
+ pts = FFMIN(pts, av_rescale_q(ost->st->pts.val,
+ ost->st->time_base, AV_TIME_BASE_Q));
}
- if (ti1 < 0.01)
- ti1 = 0.01;
if (verbose > 0 || is_last_report) {
- bitrate = (double)(total_size * 8) / ti1 / 1000.0;
+ int hours, mins, secs, us;
+ secs = pts / AV_TIME_BASE;
+ us = pts % AV_TIME_BASE;
+ mins = secs / 60;
+ secs %= 60;
+ hours = mins / 60;
+ mins %= 60;
+
+ bitrate = pts ? total_size * 8 / (pts / 1000.0) : 0;
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
- "size=%8.0fkB time=%0.2f bitrate=%6.1fkbits/s",
- (double)total_size / 1024, ti1, bitrate);
+ "size=%8.0fkB time=", total_size / 1024.0);
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
+ "%02d:%02d:%02d.%02d ", hours, mins, secs,
+ (100 * us) / AV_TIME_BASE);
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
+ "bitrate=%6.1fkbits/s", bitrate);
if (nb_frames_dup || nb_frames_drop)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d",
#endif
AVPacket avpkt;
- int bps = av_get_bits_per_sample_fmt(ist->st->codec->sample_fmt)>>3;
+ int bps = av_get_bytes_per_sample(ist->st->codec->sample_fmt);
if(ist->next_pts == AV_NOPTS_VALUE)
ist->next_pts= ist->pts;
}
#if CONFIG_AVFILTER
- if(ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+ if(ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
+ if (start_time == 0 || ist->pts >= start_time) {
for(i=0;i<nb_ostreams;i++) {
ost = ost_table[i];
if (ost->input_video_filter && ost->source_index == ist_index) {
picture.sample_aspect_ratio = ist->st->sample_aspect_ratio;
picture.pts = ist->pts;
- av_vsrc_buffer_add_frame(ost->input_video_filter, &picture);
+ av_vsrc_buffer_add_frame(ost->input_video_filter, &picture, AV_VSRC_BUF_FLAG_OVERWRITE);
}
}
}
frame_available = ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO ||
!ost->output_video_filter || avfilter_poll_frame(ost->output_video_filter->inputs[0]);
while (frame_available) {
- AVRational ist_pts_tb;
- if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ost->output_video_filter)
- if (get_filtered_video_frame(ost->output_video_filter, &picture, &ost->picref, &ist_pts_tb) < 0)
+ if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ost->output_video_filter) {
+ AVRational ist_pts_tb = ost->output_video_filter->inputs[0]->time_base;
+ if (av_vsink_buffer_get_video_buffer_ref(ost->output_video_filter, &ost->picref, 0) < 0)
goto cont;
- if (ost->picref)
- ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
+ if (ost->picref) {
+ avfilter_fill_frame_from_video_buffer_ref(&picture, ost->picref);
+ ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
+ }
+ }
#endif
os = output_files[ost->file_index];
}
} else {
AVFrame avframe; //FIXME/XXX remove this
+ AVPicture pict;
AVPacket opkt;
int64_t ost_tb_start_time= av_rescale_q(start_time, AV_TIME_BASE_Q, ost->st->time_base);
opkt.size = data_size;
}
+ if (os->oformat->flags & AVFMT_RAWPICTURE) {
+ /* store AVPicture in AVPacket, as expected by the output format */
+ avpicture_fill(&pict, opkt.data, ost->st->codec->pix_fmt, ost->st->codec->width, ost->st->codec->height);
+ opkt.data = (uint8_t *)&pict;
+ opkt.size = sizeof(AVPicture);
+ opkt.flags |= AV_PKT_FLAG_KEY;
+ }
write_frame(os, &opkt, ost->st->codec, ost->bitstream_filters);
ost->st->codec->frame_number++;
ost->frame_number++;
out_ch->end = FFMIN(rt, in_ch->end - ts_off);
if (metadata_chapters_autocopy)
- av_metadata_copy(&out_ch->metadata, in_ch->metadata, 0);
+ av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
os->nb_chapters++;
os->chapters = av_realloc(os->chapters, sizeof(AVChapter)*os->nb_chapters);
icodec = ist->st->codec;
if (metadata_streams_autocopy)
- av_metadata_copy(&ost->st->metadata, ist->st->metadata,
- AV_METADATA_DONT_OVERWRITE);
+ av_dict_copy(&ost->st->metadata, ist->st->metadata,
+ AV_DICT_DONT_OVERWRITE);
ost->st->disposition = ist->st->disposition;
codec->bits_per_raw_sample= icodec->bits_per_raw_sample;
abort();
}
} else {
+ if (!ost->enc)
+ ost->enc = avcodec_find_encoder(ost->st->codec->codec_id);
switch(codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
ost->fifo= av_fifo_alloc(1024);
if(!ost->fifo)
goto fail;
ost->reformat_pair = MAKE_SFMT_PAIR(AV_SAMPLE_FMT_NONE,AV_SAMPLE_FMT_NONE);
+ if (!codec->sample_rate) {
+ codec->sample_rate = icodec->sample_rate;
+ if (icodec->lowres)
+ codec->sample_rate >>= icodec->lowres;
+ }
+ choose_sample_rate(ost->st, ost->enc);
+ codec->time_base = (AVRational){1, codec->sample_rate};
+ if (!codec->channels) {
+ codec->channels = icodec->channels;
+ codec->channel_layout = icodec->channel_layout;
+ }
+ if (av_get_channel_layout_nb_channels(codec->channel_layout) != codec->channels)
+ codec->channel_layout = 0;
ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1;
icodec->request_channels = codec->channels;
ist->decoding_needed = 1;
ost->resample_channels = icodec->channels;
break;
case AVMEDIA_TYPE_VIDEO:
+ if (codec->pix_fmt == PIX_FMT_NONE)
+ codec->pix_fmt = icodec->pix_fmt;
+ choose_pixel_fmt(ost->st, ost->enc);
+
if (ost->st->codec->pix_fmt == PIX_FMT_NONE) {
fprintf(stderr, "Video pixel format is unknown, stream cannot be encoded\n");
ffmpeg_exit(1);
if (ost->video_resample) {
codec->bits_per_raw_sample= frame_bits_per_raw_sample;
}
+ if (!codec->width || !codec->height) {
+ codec->width = icodec->width;
+ codec->height = icodec->height;
+ }
ost->resample_height = icodec->height;
ost->resample_width = icodec->width;
ost->resample_pix_fmt= icodec->pix_fmt;
ost->encoding_needed = 1;
ist->decoding_needed = 1;
+ if (!ost->frame_rate.num)
+ ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25,1};
+ if (ost->enc && ost->enc->supported_framerates && !force_fps) {
+ int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates);
+ ost->frame_rate = ost->enc->supported_framerates[idx];
+ }
+ codec->time_base = (AVRational){ost->frame_rate.den, ost->frame_rate.num};
+ if( av_q2d(codec->time_base) < 0.001 && video_sync_method
+ && (video_sync_method==1 || (video_sync_method<0 && !(os->oformat->flags & AVFMT_VARIABLE_FPS)))){
+ av_log(os, AV_LOG_WARNING, "Frame rate very high for a muxer not effciciently supporting it.\n"
+ "Please consider specifiying a lower framerate, a different muxer or -vsync 2\n");
+ }
+
#if CONFIG_AVFILTER
if (configure_video_filters(ist, ost)) {
fprintf(stderr, "Error opening filters!\n");
for(i=0;i<nb_ostreams;i++) {
ost = ost_table[i];
if (ost->encoding_needed) {
- AVCodec *codec = i < nb_output_codecs ? output_codecs[i] : NULL;
+ AVCodec *codec = ost->enc;
AVCodecContext *dec = input_streams[ost->source_index].st->codec;
- if (!codec)
- codec = avcodec_find_encoder(ost->st->codec->codec_id);
if (!codec) {
snprintf(error, sizeof(error), "Encoder (codec id %d) not found for output stream #%d.%d",
ost->st->codec->codec_id, ost->file_index, ost->index);
/* set meta data information from input file if required */
for (i=0;i<nb_meta_data_maps;i++) {
AVFormatContext *files[2];
- AVMetadata **meta[2];
+ AVDictionary **meta[2];
int j;
#define METADATA_CHECK_INDEX(index, nb_elems, desc)\
}
}
- av_metadata_copy(meta[0], *meta[1], AV_METADATA_DONT_OVERWRITE);
+ av_dict_copy(meta[0], *meta[1], AV_DICT_DONT_OVERWRITE);
}
/* copy global metadata by default */
if (metadata_global_autocopy) {
for (i = 0; i < nb_output_files; i++)
- av_metadata_copy(&output_files[i]->metadata, input_files[0].ctx->metadata,
- AV_METADATA_DONT_OVERWRITE);
+ av_dict_copy(&output_files[i]->metadata, input_files[0].ctx->metadata,
+ AV_DICT_DONT_OVERWRITE);
}
/* copy chapters according to chapter maps */
/* finish if recording time exhausted */
if (recording_time != INT64_MAX &&
- (pkt.pts != AV_NOPTS_VALUE || pkt.dts != AV_NOPTS_VALUE ?
+ (pkt.pts != AV_NOPTS_VALUE ?
av_compare_ts(pkt.pts, ist->st->time_base, recording_time + start_time, (AVRational){1, 1000000})
:
av_compare_ts(ist->pts, AV_TIME_BASE_Q, recording_time + start_time, (AVRational){1, 1000000})
return AVERROR(EINVAL);
}
} else {
- show_pix_fmts();
+ opt_pix_fmts(NULL, NULL);
ffmpeg_exit(0);
}
return 0;
}
*mid++= 0;
- av_metadata_set2(&metadata, arg, mid, 0);
+ av_dict_set(&metadata, arg, mid, 0);
return 0;
}
return 0;
}
-static int opt_codec(int *pstream_copy, char **pcodec_name,
- int codec_type, const char *arg)
+static int opt_codec(const char *opt, const char *arg)
{
+ int *pstream_copy; char **pcodec_name; enum AVMediaType codec_type;
+
+ if (!strcmp(opt, "acodec")) { pstream_copy = &audio_stream_copy; pcodec_name = &audio_codec_name; codec_type = AVMEDIA_TYPE_AUDIO; }
+ else if (!strcmp(opt, "vcodec")) { pstream_copy = &video_stream_copy; pcodec_name = &video_codec_name; codec_type = AVMEDIA_TYPE_VIDEO; }
+ else if (!strcmp(opt, "scodec")) { pstream_copy = &subtitle_stream_copy; pcodec_name = &subtitle_codec_name; codec_type = AVMEDIA_TYPE_SUBTITLE; }
+ else if (!strcmp(opt, "dcodec")) { pstream_copy = &data_stream_copy; pcodec_name = &data_codec_name; codec_type = AVMEDIA_TYPE_DATA; }
+
av_freep(pcodec_name);
if (!strcmp(arg, "copy")) {
*pstream_copy = 1;
return 0;
}
-static int opt_audio_codec(const char *opt, const char *arg)
-{
- return opt_codec(&audio_stream_copy, &audio_codec_name, AVMEDIA_TYPE_AUDIO, arg);
-}
-
-static int opt_video_codec(const char *opt, const char *arg)
-{
- return opt_codec(&video_stream_copy, &video_codec_name, AVMEDIA_TYPE_VIDEO, arg);
-}
-
-static int opt_subtitle_codec(const char *opt, const char *arg)
-{
- return opt_codec(&subtitle_stream_copy, &subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, arg);
-}
-
-static int opt_data_codec(const char *opt, const char *arg)
-{
- return opt_codec(&data_stream_copy, &data_codec_name, AVMEDIA_TYPE_DATA, arg);
-}
-
static int opt_codec_tag(const char *opt, const char *arg)
{
char *tail;
input_codecs[nb_input_codecs-1] = avcodec_find_decoder(dec->codec_id);
set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM, input_codecs[nb_input_codecs-1]);
channel_layout = dec->channel_layout;
- audio_channels = dec->channels;
- audio_sample_rate = dec->sample_rate;
audio_sample_fmt = dec->sample_fmt;
if(audio_disable)
st->discard= AVDISCARD_ALL;
- /* Note that av_find_stream_info can add more streams, and we
- * currently have no chance of setting up lowres decoding
- * early enough for them. */
- if (dec->lowres)
- audio_sample_rate >>= dec->lowres;
break;
case AVMEDIA_TYPE_VIDEO:
input_codecs[nb_input_codecs-1] = avcodec_find_decoder_by_name(video_codec_name);
if(!input_codecs[nb_input_codecs-1])
input_codecs[nb_input_codecs-1] = avcodec_find_decoder(dec->codec_id);
set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM, input_codecs[nb_input_codecs-1]);
- frame_height = dec->height;
- frame_width = dec->width;
- frame_pix_fmt = dec->pix_fmt;
rfps = ic->streams[i]->r_frame_rate.num;
rfps_base = ic->streams[i]->r_frame_rate.den;
if (dec->lowres) {
dec->flags |= CODEC_FLAG_EMU_EDGE;
- frame_height >>= dec->lowres;
- frame_width >>= dec->lowres;
- dec->height = frame_height;
- dec->width = frame_width;
+ dec->height >>= dec->lowres;
+ dec->width >>= dec->lowres;
}
if(me_threshold)
dec->debug |= FF_DEBUG_MV;
(float)rfps / rfps_base, rfps, rfps_base);
}
- /* update the current frame rate to match the stream frame rate */
- frame_rate.num = rfps;
- frame_rate.den = rfps_base;
if(video_disable)
st->discard= AVDISCARD_ALL;
input_files[nb_input_files - 1].ctx = ic;
input_files[nb_input_files - 1].ist_index = nb_input_streams - ic->nb_streams;
- video_channel = 0;
top_field_first = -1;
+ video_channel = 0;
+ frame_rate = (AVRational){0, 0};
+ frame_pix_fmt = PIX_FMT_NONE;
+ frame_height = 0;
+ frame_width = 0;
+ audio_sample_rate = 0;
+ audio_channels = 0;
av_freep(&video_codec_name);
av_freep(&audio_codec_name);
}
ost = new_output_stream(oc, file_idx);
- output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1);
if(!video_stream_copy){
if (video_codec_name) {
codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO, 1,
avcodec_opts[AVMEDIA_TYPE_VIDEO]->strict_std_compliance);
codec = avcodec_find_encoder_by_name(video_codec_name);
- output_codecs[nb_output_codecs-1] = codec;
+ ost->enc = codec;
} else {
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO);
codec = avcodec_find_encoder(codec_id);
} else {
const char *p;
int i;
- AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1};
+ if (frame_rate.num)
+ ost->frame_rate = frame_rate;
video_enc->codec_id = codec_id;
set_context_opts(video_enc, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);
- if (codec && codec->supported_framerates && !force_fps)
- fps = codec->supported_framerates[av_find_nearest_q_idx(fps, codec->supported_framerates)];
- video_enc->time_base.den = fps.num;
- video_enc->time_base.num = fps.den;
-
video_enc->width = frame_width;
video_enc->height = frame_height;
video_enc->pix_fmt = frame_pix_fmt;
video_enc->bits_per_raw_sample = frame_bits_per_raw_sample;
st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
- choose_pixel_fmt(st, codec);
-
if (intra_only)
video_enc->gop_size = 0;
if (video_qscale || same_quality) {
parse_forced_key_frames(forced_key_frames, ost, video_enc);
}
if (video_language) {
- av_metadata_set2(&st->metadata, "language", video_language, 0);
+ av_dict_set(&st->metadata, "language", video_language, 0);
av_freep(&video_language);
}
}
ost = new_output_stream(oc, file_idx);
- output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1);
if(!audio_stream_copy){
if (audio_codec_name) {
codec_id = find_codec_or_die(audio_codec_name, AVMEDIA_TYPE_AUDIO, 1,
avcodec_opts[AVMEDIA_TYPE_AUDIO]->strict_std_compliance);
codec = avcodec_find_encoder_by_name(audio_codec_name);
- output_codecs[nb_output_codecs-1] = codec;
+ ost->enc = codec;
} else {
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_AUDIO);
codec = avcodec_find_encoder(codec_id);
}
if (audio_stream_copy) {
st->stream_copy = 1;
- audio_enc->channels = audio_channels;
- audio_enc->sample_rate = audio_sample_rate;
} else {
audio_enc->codec_id = codec_id;
set_context_opts(audio_enc, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);
audio_enc->flags |= CODEC_FLAG_QSCALE;
audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale;
}
- audio_enc->channels = audio_channels;
+ if (audio_channels)
+ audio_enc->channels = audio_channels;
audio_enc->sample_fmt = audio_sample_fmt;
- audio_enc->sample_rate = audio_sample_rate;
+ if (audio_sample_rate)
+ audio_enc->sample_rate = audio_sample_rate;
audio_enc->channel_layout = channel_layout;
- if (av_get_channel_layout_nb_channels(channel_layout) != audio_channels)
- audio_enc->channel_layout = 0;
choose_sample_fmt(st, codec);
- choose_sample_rate(st, codec);
}
- audio_enc->time_base= (AVRational){1, audio_sample_rate};
if (audio_language) {
- av_metadata_set2(&st->metadata, "language", audio_language, 0);
+ av_dict_set(&st->metadata, "language", audio_language, 0);
av_freep(&audio_language);
}
static void new_data_stream(AVFormatContext *oc, int file_idx)
{
AVStream *st;
- AVOutputStream *ost av_unused;
AVCodec *codec=NULL;
AVCodecContext *data_enc;
fprintf(stderr, "Could not alloc stream\n");
ffmpeg_exit(1);
}
- ost = new_output_stream(oc, file_idx);
+ new_output_stream(oc, file_idx);
data_enc = st->codec;
- output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1);
if (!data_stream_copy) {
fprintf(stderr, "Data stream encoding not supported yet (only streamcopy)\n");
ffmpeg_exit(1);
}
ost = new_output_stream(oc, file_idx);
subtitle_enc = st->codec;
- output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1);
if(!subtitle_stream_copy){
if (subtitle_codec_name) {
codec_id = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 1,
avcodec_opts[AVMEDIA_TYPE_SUBTITLE]->strict_std_compliance);
- codec= output_codecs[nb_output_codecs-1] = avcodec_find_encoder_by_name(subtitle_codec_name);
+ codec = avcodec_find_encoder_by_name(subtitle_codec_name);
+ ost->enc = codec;
} else {
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_SUBTITLE);
codec = avcodec_find_encoder(codec_id);
}
if (subtitle_language) {
- av_metadata_set2(&st->metadata, "language", subtitle_language, 0);
+ av_dict_set(&st->metadata, "language", subtitle_language, 0);
av_freep(&subtitle_language);
}
return 0;
}
-static void opt_output_file(const char *filename)
+static int opt_output_file(const char *opt, const char *filename)
{
AVFormatContext *oc;
int err, use_video, use_audio, use_subtitle, use_data;
AVFormatParameters params, *ap = ¶ms;
AVOutputFormat *file_oformat;
+ if(nb_output_files >= FF_ARRAY_ELEMS(output_files)){
+ fprintf(stderr, "Too many output files\n");
+ ffmpeg_exit(1);
+ }
+
if (!strcmp(filename, "-"))
filename = "pipe:";
oc->timestamp = recording_timestamp;
- av_metadata_copy(&oc->metadata, metadata, 0);
- av_metadata_free(&metadata);
+ av_dict_copy(&oc->metadata, metadata, 0);
+ av_dict_free(&metadata);
}
output_files[nb_output_files++] = oc;
set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);
+ frame_rate = (AVRational){0, 0};
+ frame_width = 0;
+ frame_height = 0;
+ audio_sample_rate = 0;
+ audio_channels = 0;
+
av_freep(&forced_key_frames);
uninit_opts();
init_opts();
+ return 0;
}
/* same option as mencoder */
}
}
-static void opt_inter_matrix(const char *arg)
+static int opt_inter_matrix(const char *opt, const char *arg)
{
inter_matrix = av_mallocz(sizeof(uint16_t) * 64);
parse_matrix_coeffs(inter_matrix, arg);
+ return 0;
}
-static void opt_intra_matrix(const char *arg)
+static int opt_intra_matrix(const char *opt, const char *arg)
{
intra_matrix = av_mallocz(sizeof(uint16_t) * 64);
parse_matrix_coeffs(intra_matrix, arg);
+ return 0;
}
static void show_usage(void)
printf("\n");
}
-static void show_help(void)
+static int opt_help(const char *opt, const char *arg)
{
AVCodec *c;
AVOutputFormat *oformat = NULL;
}
av_opt_show2(sws_opts, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0);
+ return 0;
}
static int opt_target(const char *opt, const char *arg)
}
if(!strcmp(arg, "vcd")) {
- opt_video_codec("vcodec", "mpeg1video");
- opt_audio_codec("vcodec", "mp2");
+ opt_codec("vcodec", "mpeg1video");
+ opt_codec("acodec", "mp2");
opt_format("f", "vcd");
opt_frame_size("s", norm == PAL ? "352x288" : "352x240");
mux_preload= (36000+3*1200) / 90000.0; //0.44
} else if(!strcmp(arg, "svcd")) {
- opt_video_codec("vcodec", "mpeg2video");
- opt_audio_codec("acodec", "mp2");
+ opt_codec("vcodec", "mpeg2video");
+ opt_codec("acodec", "mp2");
opt_format("f", "svcd");
opt_frame_size("s", norm == PAL ? "480x576" : "480x480");
opt_frame_rate("r", frame_rates[norm]);
+ opt_frame_pix_fmt("pix_fmt", "yuv420p");
opt_default("g", norm == PAL ? "15" : "18");
opt_default("b", "2040000");
} else if(!strcmp(arg, "dvd")) {
- opt_video_codec("vcodec", "mpeg2video");
- opt_audio_codec("vcodec", "ac3");
+ opt_codec("vcodec", "mpeg2video");
+ opt_codec("acodec", "ac3");
opt_format("f", "dvd");
opt_frame_size("vcodec", norm == PAL ? "720x576" : "720x480");
opt_frame_rate("r", frame_rates[norm]);
+ opt_frame_pix_fmt("pix_fmt", "yuv420p");
opt_default("g", norm == PAL ? "15" : "18");
opt_default("b", "6000000");
fprintf(stderr, "%s: Invalid syntax: '%s'\n", filename, line);
ffmpeg_exit(1);
}
- if(!strcmp(tmp, "acodec")){
- opt_audio_codec(tmp, tmp2);
- }else if(!strcmp(tmp, "vcodec")){
- opt_video_codec(tmp, tmp2);
- }else if(!strcmp(tmp, "scodec")){
- opt_subtitle_codec(tmp, tmp2);
- }else if(!strcmp(tmp, "dcodec")){
- opt_data_codec(tmp, tmp2);
+ if (!strcmp(tmp, "acodec") ||
+ !strcmp(tmp, "vcodec") ||
+ !strcmp(tmp, "scodec") ||
+ !strcmp(tmp, "dcodec")) {
+ opt_codec(tmp, tmp2);
}else if(opt_default(tmp, tmp2) < 0){
fprintf(stderr, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2);
ffmpeg_exit(1);
{
}
-static void opt_passlogfile(const char *arg)
+static int opt_passlogfile(const char *opt, const char *arg)
{
pass_logfilename_prefix = arg;
opt_default("passlogfile", arg);
+ return 0;
}
static const OptionDef options[] = {
{ "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" },
{ "qscale", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qscale}, "use fixed video quantizer scale (VBR)", "q" },
{ "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" },
- { "vcodec", HAS_ARG | OPT_VIDEO, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" },
+ { "vcodec", HAS_ARG | OPT_VIDEO, {(void*)opt_codec}, "force video codec ('copy' to copy stream)", "codec" },
{ "me_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimaton threshold", "threshold" },
{ "sameq", OPT_BOOL | OPT_VIDEO, {(void*)&same_quality},
"use same quantizer as source (implies VBR)" },
{ "ar", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" },
{ "ac", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_channels}, "set number of audio channels", "channels" },
{ "an", OPT_BOOL | OPT_AUDIO, {(void*)&audio_disable}, "disable audio" },
- { "acodec", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" },
+ { "acodec", HAS_ARG | OPT_AUDIO, {(void*)opt_codec}, "force audio codec ('copy' to copy stream)", "codec" },
{ "atag", HAS_ARG | OPT_EXPERT | OPT_AUDIO, {(void*)opt_codec_tag}, "force audio tag/fourcc", "fourcc/tag" },
{ "vol", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&audio_volume}, "change audio volume (256=normal)" , "volume" }, //
{ "newaudio", OPT_AUDIO, {(void*)opt_new_stream}, "add a new audio stream to the current output stream" },
/* subtitle options */
{ "sn", OPT_BOOL | OPT_SUBTITLE, {(void*)&subtitle_disable}, "disable subtitle" },
- { "scodec", HAS_ARG | OPT_SUBTITLE, {(void*)opt_subtitle_codec}, "force subtitle codec ('copy' to copy stream)", "codec" },
+ { "scodec", HAS_ARG | OPT_SUBTITLE, {(void*)opt_codec}, "force subtitle codec ('copy' to copy stream)", "codec" },
{ "newsubtitle", OPT_SUBTITLE, {(void*)opt_new_stream}, "add a new subtitle stream to the current output stream" },
{ "slang", HAS_ARG | OPT_STRING | OPT_SUBTITLE, {(void *)&subtitle_language}, "set the ISO 639 language code (3 letters) of the current subtitle stream" , "code" },
{ "stag", HAS_ARG | OPT_EXPERT | OPT_SUBTITLE, {(void*)opt_codec_tag}, "force subtitle tag/fourcc", "fourcc/tag" },
{ "spre", HAS_ARG | OPT_SUBTITLE | OPT_EXPERT, {(void*)opt_preset}, "set the subtitle options to the indicated preset", "preset" },
{ "fpre", HAS_ARG | OPT_EXPERT, {(void*)opt_preset}, "set options from indicated preset file", "filename" },
/* data codec support */
- { "dcodec", HAS_ARG | OPT_DATA, {(void*)opt_data_codec}, "force data codec ('copy' to copy stream)", "codec" },
+ { "dcodec", HAS_ARG | OPT_DATA, {(void*)opt_codec}, "force data codec ('copy' to copy stream)", "codec" },
{ "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" },
{ NULL, },