extern const OptionDef options[];
-static void show_help(void);
-static void opt_show_license(void);
-static int opt_default(const char *opt, const char *arg);
-
#define MAX_FILES 20
static AVFormatContext *input_files[MAX_FILES];
static int video_global_header = 0;
static char *vstats_filename;
static FILE *vstats_file;
+static int opt_programid = 0;
static int rate_emu = 0;
}
static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx, AVBitStreamFilterContext *bsfc){
+ int ret;
+
while(bsfc){
AVPacket new_pkt= *pkt;
int a= av_bitstream_filter_filter(bsfc, avctx, NULL,
bsfc= bsfc->next;
}
- av_interleaved_write_frame(s, pkt);
+ ret= av_interleaved_write_frame(s, pkt);
+ if(ret < 0){
+ print_error("av_interleaved_write_frame()", ret);
+ exit(1);
+ }
}
#define MAX_AUDIO_PACKET_SIZE (128 * 1024)
printf("SDP:\n%s\n", sdp);
}
+static int stream_index_from_inputs(AVFormatContext **input_files,
+ int nb_input_files,
+ AVInputFile *file_table,
+ AVInputStream **ist_table,
+ enum CodecType type,
+ int programid)
+{
+ int p, q, z;
+ for(z=0; z<nb_input_files; z++) {
+ AVFormatContext *ic = input_files[z];
+ for(p=0; p<ic->nb_programs; p++) {
+ AVProgram *program = ic->programs[p];
+ if(program->id != programid)
+ continue;
+ for(q=0; q<program->nb_stream_indexes; q++) {
+ int sidx = program->stream_index[q];
+ int ris = file_table[z].ist_index + sidx;
+ if(ist_table[ris]->discard && ic->streams[sidx]->codec->codec_type == type)
+ return ris;
+ }
+ }
+ }
+
+ return -1;
+}
+
/*
* The following code is the main loop of the file converter
*/
}
} else {
- /* get corresponding input stream index : we select the first one with the right type */
- found = 0;
- for(j=0;j<nb_istreams;j++) {
- ist = ist_table[j];
- if (ist->discard &&
- ist->st->codec->codec_type == ost->st->codec->codec_type) {
+ if(opt_programid) {
+ found = 0;
+ j = stream_index_from_inputs(input_files, nb_input_files, file_table, ist_table, ost->st->codec->codec_type, opt_programid);
+ if(j != -1) {
ost->source_index = j;
found = 1;
- break;
}
- }
-
- if (!found) {
- /* try again and reuse existing stream */
+ } else {
+ /* get corresponding input stream index : we select the first one with the right type */
+ found = 0;
for(j=0;j<nb_istreams;j++) {
ist = ist_table[j];
- if (ist->st->codec->codec_type == ost->st->codec->codec_type) {
+ if (ist->discard &&
+ ist->st->codec->codec_type == ost->st->codec->codec_type) {
ost->source_index = j;
found = 1;
+ break;
+ }
+ }
+ }
+
+ if (!found) {
+ if(! opt_programid) {
+ /* try again and reuse existing stream */
+ for(j=0;j<nb_istreams;j++) {
+ ist = ist_table[j];
+ if (ist->st->codec->codec_type == ost->st->codec->codec_type) {
+ ost->source_index = j;
+ found = 1;
+ }
}
}
if (!found) {
}
}
+#if defined(CONFIG_FFM_DEMUXER) || defined(CONFIG_FFM_MUXER)
+extern int ffm_nopts;
+#endif
+
+static int opt_default(const char *opt, const char *arg){
+ int type;
+ const AVOption *o= NULL;
+ int opt_types[]={AV_OPT_FLAG_VIDEO_PARAM, AV_OPT_FLAG_AUDIO_PARAM, 0, AV_OPT_FLAG_SUBTITLE_PARAM, 0};
+
+ for(type=0; type<CODEC_TYPE_NB; type++){
+ const AVOption *o2 = av_find_opt(avctx_opts[0], opt, NULL, opt_types[type], opt_types[type]);
+ if(o2)
+ o = av_set_string(avctx_opts[type], opt, arg);
+ }
+ if(!o)
+ o = av_set_string(avformat_opts, opt, arg);
+ if(!o)
+ o = av_set_string(sws_opts, opt, arg);
+ if(!o){
+ if(opt[0] == 'a')
+ o = av_set_string(avctx_opts[CODEC_TYPE_AUDIO], opt+1, arg);
+ else if(opt[0] == 'v')
+ o = av_set_string(avctx_opts[CODEC_TYPE_VIDEO], opt+1, arg);
+ else if(opt[0] == 's')
+ o = av_set_string(avctx_opts[CODEC_TYPE_SUBTITLE], opt+1, arg);
+ }
+ if(!o)
+ return -1;
+
+// av_log(NULL, AV_LOG_ERROR, "%s:%s: %f 0x%0X\n", opt, arg, av_get_double(avctx_opts, opt, NULL), (int)av_get_int(avctx_opts, opt, NULL));
+
+ //FIXME we should always use avctx_opts, ... for storing options so there wont be any need to keep track of whats set over this
+ opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1));
+ opt_names[opt_name_count++]= o->name;
+
+#if defined(CONFIG_FFM_DEMUXER) || defined(CONFIG_FFM_MUXER)
+ /* disable generate of real time pts in ffm (need to be supressed anyway) */
+ if(avctx_opts[0]->flags & CODEC_FLAG_BITEXACT)
+ ffm_nopts = 1;
+#endif
+
+ if(avctx_opts[0]->debug)
+ av_log_level = AV_LOG_DEBUG;
+ return 0;
+}
+
static void opt_video_rc_eq(char *arg)
{
video_rc_eq = arg;
}
}
+static void opt_bitrate(const char *opt, const char *arg)
+{
+ int codec_type = opt[0]=='a' ? CODEC_TYPE_AUDIO : CODEC_TYPE_VIDEO;
+
+ opt_default(opt, arg);
+
+ if (av_get_int(avctx_opts[codec_type], "b", NULL) < 1000)
+ fprintf(stderr, "WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s\n");
+}
+
static void opt_frame_crop_top(const char *arg)
{
frame_topBand = atoi(arg);
print_error(filename, err);
exit(1);
}
+ if(opt_programid) {
+ int i;
+ for(i=0; i<ic->nb_programs; i++)
+ if(ic->programs[i]->id != opt_programid)
+ ic->programs[i]->discard = AVDISCARD_ALL;
+ }
ic->loop_input = loop_input;
#endif
}
-#if defined(CONFIG_FFM_DEMUXER) || defined(CONFIG_FFM_MUXER)
-extern int ffm_nopts;
-#endif
-
static void opt_show_formats(void)
{
AVInputFormat *ifmt;
parse_matrix_coeffs(intra_matrix, arg);
}
+/**
+ * Trivial log callback.
+ * Only suitable for show_help and similar since it lacks prefix handling.
+ */
+static void log_callback_help(void* ptr, int level, const char* fmt, va_list vl)
+{
+ vfprintf(stdout, fmt, vl);
+}
+
+static void show_help(void)
+{
+ av_log_set_callback(log_callback_help);
+ printf("usage: ffmpeg [[infile options] -i infile]... {[outfile options] outfile}...\n"
+ "Hyper fast Audio and Video encoder\n");
+ printf("\n");
+ show_help_options(options, "Main options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO, 0);
+ show_help_options(options, "\nVideo options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
+ OPT_VIDEO);
+ show_help_options(options, "\nAdvanced Video options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
+ OPT_VIDEO | OPT_EXPERT);
+ show_help_options(options, "\nAudio options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
+ OPT_AUDIO);
+ show_help_options(options, "\nAdvanced Audio options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
+ OPT_AUDIO | OPT_EXPERT);
+ show_help_options(options, "\nSubtitle options:\n",
+ OPT_SUBTITLE | OPT_GRAB,
+ OPT_SUBTITLE);
+ show_help_options(options, "\nAudio/Video grab options:\n",
+ OPT_GRAB,
+ OPT_GRAB);
+ show_help_options(options, "\nAdvanced options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
+ OPT_EXPERT);
+ av_opt_show(avctx_opts[0], NULL);
+ av_opt_show(avformat_opts, NULL);
+ av_opt_show(sws_opts, NULL);
+}
+
static void opt_show_help(void)
{
show_help();
opt_vstats_file(filename);
}
-static void opt_video_bsf(const char *arg)
+static void opt_bsf(const char *opt, const char *arg)
{
AVBitStreamFilterContext *bsfc= av_bitstream_filter_init(arg); //FIXME split name and args for filter at '='
AVBitStreamFilterContext **bsfp;
exit(1);
}
- bsfp= &video_bitstream_filters;
+ bsfp= *opt == 'v' ? &video_bitstream_filters : &audio_bitstream_filters;
while(*bsfp)
bsfp= &(*bsfp)->next;
*bsfp= bsfc;
}
-//FIXME avoid audio - video code duplication
-static void opt_audio_bsf(const char *arg)
+static void opt_show_license(void)
{
- AVBitStreamFilterContext *bsfc= av_bitstream_filter_init(arg); //FIXME split name and args for filter at '='
- AVBitStreamFilterContext **bsfp;
-
- if(!bsfc){
- fprintf(stderr, "Unknown bitstream filter %s\n", arg);
- exit(1);
- }
-
- bsfp= &audio_bitstream_filters;
- while(*bsfp)
- bsfp= &(*bsfp)->next;
-
- *bsfp= bsfc;
+ show_license();
+ exit(0);
}
static void opt_show_version(void)
exit(0);
}
-static int opt_default(const char *opt, const char *arg){
- int type;
- const AVOption *o= NULL;
- int opt_types[]={AV_OPT_FLAG_VIDEO_PARAM, AV_OPT_FLAG_AUDIO_PARAM, 0, AV_OPT_FLAG_SUBTITLE_PARAM, 0};
-
- for(type=0; type<CODEC_TYPE_NB; type++){
- const AVOption *o2 = av_find_opt(avctx_opts[0], opt, NULL, opt_types[type], opt_types[type]);
- if(o2)
- o = av_set_string(avctx_opts[type], opt, arg);
- }
- if(!o)
- o = av_set_string(avformat_opts, opt, arg);
- if(!o)
- o = av_set_string(sws_opts, opt, arg);
- if(!o){
- if(opt[0] == 'a')
- o = av_set_string(avctx_opts[CODEC_TYPE_AUDIO], opt+1, arg);
- else if(opt[0] == 'v')
- o = av_set_string(avctx_opts[CODEC_TYPE_VIDEO], opt+1, arg);
- else if(opt[0] == 's')
- o = av_set_string(avctx_opts[CODEC_TYPE_SUBTITLE], opt+1, arg);
- }
- if(!o)
- return -1;
-
-// av_log(NULL, AV_LOG_ERROR, "%s:%s: %f 0x%0X\n", opt, arg, av_get_double(avctx_opts, opt, NULL), (int)av_get_int(avctx_opts, opt, NULL));
-
- //FIXME we should always use avctx_opts, ... for storing options so there wont be any need to keep track of whats set over this
- opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1));
- opt_names[opt_name_count++]= o->name;
-
-#if defined(CONFIG_FFM_DEMUXER) || defined(CONFIG_FFM_MUXER)
- /* disable generate of real time pts in ffm (need to be supressed anyway) */
- if(avctx_opts[0]->flags & CODEC_FLAG_BITEXACT)
- ffm_nopts = 1;
-#endif
-
- if(avctx_opts[0]->debug)
- av_log_level = AV_LOG_DEBUG;
- return 0;
-}
-
const OptionDef options[] = {
/* main options */
{ "L", 0, {(void*)opt_show_license}, "show license" },
{ "copyts", OPT_BOOL | OPT_EXPERT, {(void*)©_ts}, "copy timestamps" },
{ "shortest", OPT_BOOL | OPT_EXPERT, {(void*)&opt_shortest}, "finish encoding within shortest input" }, //
{ "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&dts_delta_threshold}, "timestamp discontinuity delta threshold", "" },
+ { "programid", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&opt_programid}, "desired program number", "" },
/* video options */
+ { "b", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "" },
+ { "vb", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "" },
{ "vframes", OPT_INT | HAS_ARG | OPT_VIDEO, {(void*)&max_frames[CODEC_TYPE_VIDEO]}, "set the number of video frames to record", "number" },
{ "dframes", OPT_INT | HAS_ARG, {(void*)&max_frames[CODEC_TYPE_DATA]}, "set the number of data frames to record", "number" },
{ "r", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" },
{ "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" },
/* audio options */
+ { "ab", OPT_FUNC2 | HAS_ARG | OPT_AUDIO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "" },
{ "aframes", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&max_frames[CODEC_TYPE_AUDIO]}, "set the number of audio frames to record", "number" },
{ "aq", OPT_FLOAT | HAS_ARG | OPT_AUDIO, {(void*)&audio_qscale}, "set audio quality (codec-specific)", "quality", },
{ "ar", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" },
{ "muxdelay", OPT_FLOAT | HAS_ARG | OPT_EXPERT, {(void*)&mux_max_delay}, "set the maximum demux-decode delay", "seconds" },
{ "muxpreload", OPT_FLOAT | HAS_ARG | OPT_EXPERT, {(void*)&mux_preload}, "set the initial demux-decode delay", "seconds" },
- { "absf", HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_audio_bsf}, "", "bitstream filter" },
- { "vbsf", HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_video_bsf}, "", "bitstream filter" },
+ { "absf", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream filter" },
+ { "vbsf", OPT_FUNC2 | HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream filter" },
{ "default", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" },
{ NULL, },
};
-static void opt_show_license(void)
-{
- show_license();
- exit(0);
-}
-
-/**
- * Trivial log callback.
- * Only suitable for show_help and similar since it lacks prefix handling.
- */
-static void log_callback_help(void* ptr, int level, const char* fmt, va_list vl)
-{
- vfprintf(stdout, fmt, vl);
-}
-
-static void show_help(void)
-{
- av_log_set_callback(log_callback_help);
- printf("usage: ffmpeg [[infile options] -i infile]... {[outfile options] outfile}...\n"
- "Hyper fast Audio and Video encoder\n");
- printf("\n");
- show_help_options(options, "Main options:\n",
- OPT_EXPERT | OPT_AUDIO | OPT_VIDEO, 0);
- show_help_options(options, "\nVideo options:\n",
- OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
- OPT_VIDEO);
- show_help_options(options, "\nAdvanced Video options:\n",
- OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
- OPT_VIDEO | OPT_EXPERT);
- show_help_options(options, "\nAudio options:\n",
- OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
- OPT_AUDIO);
- show_help_options(options, "\nAdvanced Audio options:\n",
- OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
- OPT_AUDIO | OPT_EXPERT);
- show_help_options(options, "\nSubtitle options:\n",
- OPT_SUBTITLE | OPT_GRAB,
- OPT_SUBTITLE);
- show_help_options(options, "\nAudio/Video grab options:\n",
- OPT_GRAB,
- OPT_GRAB);
- show_help_options(options, "\nAdvanced options:\n",
- OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
- OPT_EXPERT);
- av_opt_show(avctx_opts[0], NULL);
- av_opt_show(avformat_opts, NULL);
- av_opt_show(sws_opts, NULL);
-}
-
static int av_exit()
{
int i;