Newer
Older
static void opt_rec_timestamp(const char *arg)
{
rec_timestamp = parse_date(arg, 0) / 1000000;
}
static void opt_input_ts_offset(const char *arg)
{
input_ts_offset = parse_date(arg, 1);
}
static void opt_input_file(const char *filename)
{
AVFormatContext *ic;
AVFormatParameters params, *ap = ¶ms;
Michael Niedermayer
committed
int err, i, ret, rfps, rfps_base;
if (!strcmp(filename, "-"))
filename = "pipe:";
using_stdin |= !strncmp(filename, "pipe:", 5) ||
!strcmp( filename, "/dev/stdin" );
memset(ap, 0, sizeof(*ap));
ap->sample_rate = audio_sample_rate;
ap->channels = audio_channels;
ap->time_base.den = frame_rate;
ap->time_base.num = frame_rate_base;
Todd Kirby
committed
ap->width = frame_width + frame_padleft + frame_padright;
ap->height = frame_height + frame_padtop + frame_padbottom;
Fabrice Bellard
committed
ap->image_format = image_format;
ap->pix_fmt = frame_pix_fmt;
ap->device = grab_device;
ap->channel = video_channel;
ap->standard = video_standard;
ap->video_codec_id = video_codec_id;
ap->audio_codec_id = audio_codec_id;
if(pgmyuv_compatibility_hack)
ap->video_codec_id= CODEC_ID_PGMYUV;
/* open the input file with generic libav function */
err = av_open_input_file(&ic, filename, file_iformat, 0, ap);
print_error(filename, err);
if(genpts)
ic->flags|= AVFMT_FLAG_GENPTS;
/* If not enough info to get the stream parameters, we decode the
first frames to get it. (used in mpeg case for example) */
ret = av_find_stream_info(ic);
if (ret < 0 && verbose >= 0) {
fprintf(stderr, "%s: could not find codec parameters\n", filename);
exit(1);
}
timestamp = start_time;
/* add the stream start time */
if (ic->start_time != AV_NOPTS_VALUE)
timestamp += ic->start_time;
/* if seeking requested, we execute it */
if (start_time != 0) {
ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);
if (ret < 0) {
fprintf(stderr, "%s: could not seek to position %0.3f\n",
filename, (double)timestamp / AV_TIME_BASE);
}
/* reset seek info */
start_time = 0;
}
/* update the current parameters so that they match the one of the input stream */
for(i=0;i<ic->nb_streams;i++) {
Michael Niedermayer
committed
AVCodecContext *enc = ic->streams[i]->codec;
François Revol
committed
#if defined(HAVE_THREADS)
if(thread_count>1)
avcodec_thread_init(enc, thread_count);
#endif
enc->thread_count= thread_count;
//fprintf(stderr, "\nInput Audio channels: %d", enc->channels);
audio_channels = enc->channels;
audio_sample_rate = enc->sample_rate;
ic->streams[i]->discard= AVDISCARD_ALL;
break;
case CODEC_TYPE_VIDEO:
frame_height = enc->height;
frame_width = enc->width;
frame_aspect_ratio = av_q2d(enc->sample_aspect_ratio) * enc->width / enc->height;
frame_pix_fmt = enc->pix_fmt;
rfps = ic->streams[i]->r_frame_rate.num;
rfps_base = ic->streams[i]->r_frame_rate.den;
Michael Niedermayer
committed
enc->workaround_bugs = workaround_bugs;
enc->error_resilience = error_resilience;
enc->error_concealment = error_concealment;
Wolfgang Hesseler
committed
enc->idct_algo = idct_algo;
enc->debug = debug;
enc->debug_mv = debug_mv;
if(bitexact)
enc->flags|= CODEC_FLAG_BITEXACT;
Michael Niedermayer
committed
if(me_threshold)
enc->debug |= FF_DEBUG_MV;
if(gray_only)
enc->flags |= CODEC_FLAG_GRAY;
if (enc->time_base.den != rfps || enc->time_base.num != rfps_base) {
if (verbose >= 0)
fprintf(stderr,"\nSeems that stream %d comes from film source: %2.2f (%d/%d) -> %2.2f (%d/%d)\n",
i, (float)enc->time_base.den / enc->time_base.num, enc->time_base.den, enc->time_base.num,
(float)rfps / rfps_base, rfps, rfps_base);
/* update the current frame rate to match the stream frame rate */
Michael Niedermayer
committed
frame_rate = rfps;
frame_rate_base = rfps_base;
Max Krasnyansky
committed
enc->rate_emu = rate_emu;
ic->streams[i]->discard= AVDISCARD_ALL;
else if(video_discard)
ic->streams[i]->discard= video_discard;
case CODEC_TYPE_DATA:
break;
Fabrice Bellard
committed
case CODEC_TYPE_SUBTITLE:
break;
case CODEC_TYPE_UNKNOWN:
break;
default:
av_abort();
input_files_ts_offset[nb_input_files] = input_ts_offset - (copy_ts ? 0 : timestamp);
if (verbose >= 0)
dump_format(ic, nb_input_files, filename, 0);
file_iformat = NULL;
file_oformat = NULL;
Fabrice Bellard
committed
image_format = NULL;
Max Krasnyansky
committed
grab_device = NULL;
video_channel = 0;
Max Krasnyansky
committed
rate_emu = 0;
static void opt_grab(const char *arg)
{
file_iformat = av_find_input_format(arg);
opt_input_file("");
}
static void check_audio_video_inputs(int *has_video_ptr, int *has_audio_ptr)
Fabrice Bellard
committed
{
int has_video, has_audio, i, j;
AVFormatContext *ic;
has_video = 0;
has_audio = 0;
for(j=0;j<nb_input_files;j++) {
ic = input_files[j];
for(i=0;i<ic->nb_streams;i++) {
Michael Niedermayer
committed
AVCodecContext *enc = ic->streams[i]->codec;
Fabrice Bellard
committed
switch(enc->codec_type) {
case CODEC_TYPE_AUDIO:
has_audio = 1;
break;
case CODEC_TYPE_VIDEO:
has_video = 1;
break;
Wolfram Gloger
committed
case CODEC_TYPE_DATA:
case CODEC_TYPE_UNKNOWN:
Fabrice Bellard
committed
case CODEC_TYPE_SUBTITLE:
Wolfram Gloger
committed
break;
default:
av_abort();
Fabrice Bellard
committed
}
}
}
*has_video_ptr = has_video;
*has_audio_ptr = has_audio;
}
Fabrice Bellard
committed
static void new_video_stream(AVFormatContext *oc)
Fabrice Bellard
committed
AVCodecContext *video_enc;
int codec_id;
st = av_new_stream(oc, oc->nb_streams);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
exit(1);
}
#if defined(HAVE_THREADS)
if(thread_count>1)
Michael Niedermayer
committed
avcodec_thread_init(st->codec, thread_count);
Fabrice Bellard
committed
#endif
Michael Niedermayer
committed
video_enc = st->codec;
Fabrice Bellard
committed
if(video_codec_tag)
video_enc->codec_tag= video_codec_tag;
Michael Niedermayer
committed
if( (video_global_header&1)
|| (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER)))
Fabrice Bellard
committed
video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
Michael Niedermayer
committed
if(video_global_header&2)
video_enc->flags2 |= CODEC_FLAG2_LOCAL_HEADER;
Fabrice Bellard
committed
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
if (video_stream_copy) {
st->stream_copy = 1;
video_enc->codec_type = CODEC_TYPE_VIDEO;
} else {
char *p;
int i;
AVCodec *codec;
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);
if (video_codec_id != CODEC_ID_NONE)
codec_id = video_codec_id;
video_enc->codec_id = codec_id;
codec = avcodec_find_encoder(codec_id);
video_enc->bit_rate = video_bit_rate;
video_enc->bit_rate_tolerance = video_bit_rate_tolerance;
video_enc->time_base.den = frame_rate;
video_enc->time_base.num = frame_rate_base;
if(codec && codec->supported_framerates){
const AVRational *p= codec->supported_framerates;
AVRational req= (AVRational){frame_rate, frame_rate_base};
const AVRational *best=NULL;
AVRational best_error= (AVRational){INT_MAX, 1};
for(; p->den!=0; p++){
AVRational error= av_sub_q(req, *p);
if(error.num <0) error.num *= -1;
if(av_cmp_q(error, best_error) < 0){
best_error= error;
best= p;
}
}
video_enc->time_base.den= best->num;
video_enc->time_base.num= best->den;
}
video_enc->width = frame_width + frame_padright + frame_padleft;
video_enc->height = frame_height + frame_padtop + frame_padbottom;
video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255);
video_enc->pix_fmt = frame_pix_fmt;
if(codec && codec->pix_fmts){
const enum PixelFormat *p= codec->pix_fmts;
for(; *p!=-1; p++){
if(*p == video_enc->pix_fmt)
break;
}
if(*p == -1)
video_enc->pix_fmt = codec->pix_fmts[0];
}
if (!intra_only)
video_enc->gop_size = gop_size;
else
video_enc->gop_size = 0;
if (video_qscale || same_quality) {
video_enc->flags |= CODEC_FLAG_QSCALE;
video_enc->global_quality=
st->quality = FF_QP2LAMBDA * video_qscale;
}
if(intra_matrix)
video_enc->intra_matrix = intra_matrix;
if(inter_matrix)
video_enc->inter_matrix = inter_matrix;
if(bitexact)
video_enc->flags |= CODEC_FLAG_BITEXACT;
video_enc->mb_decision = mb_decision;
video_enc->mb_cmp = mb_cmp;
video_enc->ildct_cmp = ildct_cmp;
video_enc->me_sub_cmp = sub_cmp;
video_enc->me_cmp = cmp;
video_enc->me_pre_cmp = pre_cmp;
video_enc->pre_me = pre_me;
video_enc->lumi_masking = lumi_mask;
video_enc->dark_masking = dark_mask;
video_enc->spatial_cplx_masking = scplx_mask;
video_enc->temporal_cplx_masking = tcplx_mask;
video_enc->p_masking = p_mask;
video_enc->quantizer_noise_shaping= qns;
if (use_umv) {
video_enc->flags |= CODEC_FLAG_H263P_UMV;
}
if (use_ss) {
video_enc->flags |= CODEC_FLAG_H263P_SLICE_STRUCT;
}
if (use_aic) {
video_enc->flags |= CODEC_FLAG_H263P_AIC;
}
if (use_aiv) {
video_enc->flags |= CODEC_FLAG_H263P_AIV;
}
if (use_4mv) {
video_enc->flags |= CODEC_FLAG_4MV;
}
if (use_obmc) {
video_enc->flags |= CODEC_FLAG_OBMC;
}
if (use_loop) {
video_enc->flags |= CODEC_FLAG_LOOP_FILTER;
}
if(use_part) {
video_enc->flags |= CODEC_FLAG_PART;
}
if (use_alt_scan) {
video_enc->flags |= CODEC_FLAG_ALT_SCAN;
}
if (use_trell) {
video_enc->flags |= CODEC_FLAG_TRELLIS_QUANT;
}
if (use_mv0) {
video_enc->flags |= CODEC_FLAG_MV0;
}
if (do_normalize_aqp) {
video_enc->flags |= CODEC_FLAG_NORMALIZE_AQP;
}
if (use_scan_offset) {
video_enc->flags |= CODEC_FLAG_SVCD_SCAN_OFFSET;
}
if (closed_gop) {
video_enc->flags |= CODEC_FLAG_CLOSED_GOP;
}
if (strict_gop) {
video_enc->flags2 |= CODEC_FLAG2_STRICT_GOP;
}
if (use_qpel) {
video_enc->flags |= CODEC_FLAG_QPEL;
}
if (use_qprd) {
video_enc->flags |= CODEC_FLAG_QP_RD;
}
if (use_cbprd) {
video_enc->flags |= CODEC_FLAG_CBP_RD;
}
if (b_frames) {
video_enc->max_b_frames = b_frames;
video_enc->b_frame_strategy = b_strategy;
video_enc->b_quant_factor = 2.0;
}
if (do_interlace_dct) {
video_enc->flags |= CODEC_FLAG_INTERLACED_DCT;
}
if (do_interlace_me) {
video_enc->flags |= CODEC_FLAG_INTERLACED_ME;
}
if (no_output) {
video_enc->flags2 |= CODEC_FLAG2_NO_OUTPUT;
}
if (gray_only) {
video_enc->flags |= CODEC_FLAG_GRAY;
}
video_enc->qmin = video_qmin;
video_enc->qmax = video_qmax;
video_enc->lmin = video_lmin;
video_enc->lmax = video_lmax;
video_enc->rc_qsquish = video_qsquish;
video_enc->luma_elim_threshold = video_lelim;
video_enc->chroma_elim_threshold = video_celim;
video_enc->mb_lmin = video_mb_lmin;
video_enc->mb_lmax = video_mb_lmax;
video_enc->max_qdiff = video_qdiff;
video_enc->qblur = video_qblur;
video_enc->qcompress = video_qcomp;
video_enc->rc_eq = video_rc_eq;
video_enc->debug = debug;
video_enc->debug_mv = debug_mv;
video_enc->workaround_bugs = workaround_bugs;
video_enc->thread_count = thread_count;
p= video_rc_override_string;
for(i=0; p; i++){
int start, end, q;
int e=sscanf(p, "%d,%d,%d", &start, &end, &q);
if(e!=3){
fprintf(stderr, "error parsing rc_override\n");
exit(1);
}
video_enc->rc_override=
av_realloc(video_enc->rc_override,
sizeof(RcOverride)*(i+1));
video_enc->rc_override[i].start_frame= start;
video_enc->rc_override[i].end_frame = end;
if(q>0){
video_enc->rc_override[i].qscale= q;
video_enc->rc_override[i].quality_factor= 1.0;
}
else{
video_enc->rc_override[i].qscale= 0;
video_enc->rc_override[i].quality_factor= -q/100.0;
}
p= strchr(p, '/');
if(p) p++;
}
video_enc->rc_override_count=i;
video_enc->rc_max_rate = video_rc_max_rate;
video_enc->rc_min_rate = video_rc_min_rate;
video_enc->rc_buffer_size = video_rc_buffer_size;
video_enc->rc_initial_buffer_occupancy = video_rc_buffer_size*3/4;
video_enc->rc_buffer_aggressivity= video_rc_buffer_aggressivity;
video_enc->rc_initial_cplx= video_rc_initial_cplx;
video_enc->i_quant_factor = video_i_qfactor;
video_enc->b_quant_factor = video_b_qfactor;
video_enc->i_quant_offset = video_i_qoffset;
video_enc->b_quant_offset = video_b_qoffset;
video_enc->intra_quant_bias = video_intra_quant_bias;
video_enc->inter_quant_bias = video_inter_quant_bias;
video_enc->dct_algo = dct_algo;
video_enc->idct_algo = idct_algo;
video_enc->me_threshold= me_threshold;
video_enc->mb_threshold= mb_threshold;
video_enc->intra_dc_precision= intra_dc_precision - 8;
video_enc->strict_std_compliance = strict;
video_enc->error_rate = error_rate;
video_enc->noise_reduction= noise_reduction;
video_enc->scenechange_threshold= sc_threshold;
video_enc->me_range = me_range;
video_enc->coder_type= coder;
video_enc->context_model= context;
video_enc->prediction_method= predictor;
video_enc->profile= video_profile;
video_enc->level= video_level;
video_enc->nsse_weight= nsse_weight;
video_enc->me_subpel_quality= subpel_quality;
video_enc->me_penalty_compensation= me_penalty_compensation;
video_enc->frame_skip_threshold= frame_skip_threshold;
video_enc->frame_skip_factor= frame_skip_factor;
video_enc->frame_skip_exp= frame_skip_exp;
video_enc->frame_skip_cmp= frame_skip_cmp;
if(packet_size){
video_enc->rtp_mode= 1;
video_enc->rtp_payload_size= packet_size;
}
if (do_psnr)
video_enc->flags|= CODEC_FLAG_PSNR;
video_enc->me_method = me_method;
/* two pass mode */
if (do_pass) {
if (do_pass == 1) {
video_enc->flags |= CODEC_FLAG_PASS1;
} else {
video_enc->flags |= CODEC_FLAG_PASS2;
}
}
}
/* reset some key parameters */
video_disable = 0;
video_codec_id = CODEC_ID_NONE;
video_stream_copy = 0;
}
static void new_audio_stream(AVFormatContext *oc)
{
AVStream *st;
AVCodecContext *audio_enc;
Fabrice Bellard
committed
st = av_new_stream(oc, oc->nb_streams);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
exit(1);
}
#if defined(HAVE_THREADS)
if(thread_count>1)
Michael Niedermayer
committed
avcodec_thread_init(st->codec, thread_count);
Fabrice Bellard
committed
#endif
Michael Niedermayer
committed
audio_enc = st->codec;
Fabrice Bellard
committed
audio_enc->codec_type = CODEC_TYPE_AUDIO;
if(audio_codec_tag)
audio_enc->codec_tag= audio_codec_tag;
if (oc->oformat->flags & AVFMT_GLOBALHEADER)
audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
if (audio_stream_copy) {
st->stream_copy = 1;
audio_enc->channels = audio_channels;
} else {
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO);
if (audio_codec_id != CODEC_ID_NONE)
codec_id = audio_codec_id;
audio_enc->codec_id = codec_id;
audio_enc->bit_rate = audio_bit_rate;
if (audio_qscale > QSCALE_NONE) {
audio_enc->flags |= CODEC_FLAG_QSCALE;
audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale;
}
Fabrice Bellard
committed
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
audio_enc->strict_std_compliance = strict;
audio_enc->thread_count = thread_count;
/* For audio codecs other than AC3 or DTS we limit */
/* the number of coded channels to stereo */
if (audio_channels > 2 && codec_id != CODEC_ID_AC3
&& codec_id != CODEC_ID_DTS) {
audio_enc->channels = 2;
} else
audio_enc->channels = audio_channels;
}
audio_enc->sample_rate = audio_sample_rate;
if (audio_language) {
pstrcpy(st->language, sizeof(st->language), audio_language);
av_free(audio_language);
audio_language = NULL;
}
/* reset some key parameters */
audio_disable = 0;
audio_codec_id = CODEC_ID_NONE;
audio_stream_copy = 0;
}
static void opt_new_subtitle_stream(void)
{
AVFormatContext *oc;
AVStream *st;
AVCodecContext *subtitle_enc;
if (nb_output_files <= 0) {
fprintf(stderr, "At least one output file must be specified\n");
exit(1);
}
oc = output_files[nb_output_files - 1];
st = av_new_stream(oc, oc->nb_streams);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
exit(1);
}
Michael Niedermayer
committed
subtitle_enc = st->codec;
Fabrice Bellard
committed
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
subtitle_enc->codec_type = CODEC_TYPE_SUBTITLE;
if (subtitle_stream_copy) {
st->stream_copy = 1;
} else {
subtitle_enc->codec_id = subtitle_codec_id;
}
if (subtitle_language) {
pstrcpy(st->language, sizeof(st->language), subtitle_language);
av_free(subtitle_language);
subtitle_language = NULL;
}
subtitle_codec_id = CODEC_ID_NONE;
subtitle_stream_copy = 0;
}
static void opt_new_audio_stream(void)
{
AVFormatContext *oc;
if (nb_output_files <= 0) {
fprintf(stderr, "At least one output file must be specified\n");
exit(1);
}
oc = output_files[nb_output_files - 1];
new_audio_stream(oc);
}
static void opt_new_video_stream(void)
{
AVFormatContext *oc;
if (nb_output_files <= 0) {
fprintf(stderr, "At least one output file must be specified\n");
exit(1);
}
oc = output_files[nb_output_files - 1];
new_video_stream(oc);
}
static void opt_output_file(const char *filename)
{
AVFormatContext *oc;
int use_video, use_audio, input_has_video, input_has_audio;
Fabrice Bellard
committed
AVFormatParameters params, *ap = ¶ms;
oc = av_alloc_format_context();
if (!file_oformat) {
file_oformat = guess_format(NULL, filename, NULL);
if (!file_oformat) {
fprintf(stderr, "Unable for find a suitable output format for '%s'\n",
filename);
exit(1);
}
oc->oformat = file_oformat;
Fabrice Bellard
committed
pstrcpy(oc->filename, sizeof(oc->filename), filename);
if (!strcmp(file_oformat->name, "ffm") &&
strstart(filename, "http:", NULL)) {
/* special case for files sent to ffserver: we get the stream
parameters from ffserver */
if (read_ffserver_streams(oc, filename) < 0) {
fprintf(stderr, "Could not read stream parameters from '%s'\n", filename);
exit(1);
}
} else {
Luca Abeni
committed
use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_id != CODEC_ID_NONE;
use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_id != CODEC_ID_NONE;
Fabrice Bellard
committed
/* disable if no corresponding type found and at least one
input file */
if (nb_input_files > 0) {
check_audio_video_inputs(&input_has_video, &input_has_audio);
if (!input_has_video)
use_video = 0;
if (!input_has_audio)
use_audio = 0;
}
Fabrice Bellard
committed
/* manual disable */
if (audio_disable) {
use_audio = 0;
}
if (video_disable) {
use_video = 0;
}
if (use_video) {
Fabrice Bellard
committed
new_video_stream(oc);
Fabrice Bellard
committed
new_audio_stream(oc);
Fabrice Bellard
committed
if (!oc->nb_streams) {
Fabrice Bellard
committed
fprintf(stderr, "No audio or video streams available\n");
oc->timestamp = rec_timestamp;
if (str_title)
pstrcpy(oc->title, sizeof(oc->title), str_title);
pstrcpy(oc->author, sizeof(oc->author), str_author);
pstrcpy(oc->copyright, sizeof(oc->copyright), str_copyright);
pstrcpy(oc->comment, sizeof(oc->comment), str_comment);
output_files[nb_output_files++] = oc;
Fabrice Bellard
committed
/* check filename in case of an image number is expected */
if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
if (filename_number_test(oc->filename) < 0) {
print_error(oc->filename, AVERROR_NUMEXPECTED);
Fabrice Bellard
committed
exit(1);
Fabrice Bellard
committed
}
if (!(oc->oformat->flags & AVFMT_NOFILE)) {
/* test if it already exists to avoid loosing precious files */
if (!file_overwrite &&
(strchr(filename, ':') == NULL ||
strstart(filename, "file:", NULL))) {
if (url_exist(filename)) {
int c;
if ( !using_stdin ) {
fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
fflush(stderr);
c = getchar();
if (toupper(c) != 'Y') {
fprintf(stderr, "Not overwriting - exiting\n");
exit(1);
}
}
else {
fprintf(stderr,"File '%s' already exists. Exiting.\n", filename);
}
}
/* open the file */
if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) {
fprintf(stderr, "Could not open '%s'\n", filename);
exit(1);
}
}
Fabrice Bellard
committed
memset(ap, 0, sizeof(*ap));
ap->image_format = image_format;
if (av_set_parameters(oc, ap) < 0) {
fprintf(stderr, "%s: Invalid encoding parameters\n",
oc->filename);
exit(1);
}
oc->packet_size= mux_packet_size;
oc->mux_rate= mux_rate;
oc->preload= (int)(mux_preload*AV_TIME_BASE);
oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
oc->loop_output = loop_output;
file_oformat = NULL;
file_iformat = NULL;
Fabrice Bellard
committed
image_format = NULL;
/* prepare dummy protocols for grab */
static void prepare_grab(void)
{
int has_video, has_audio, i, j;
AVFormatContext *oc;
AVFormatContext *ic;
Fabrice Bellard
committed
AVFormatParameters vp1, *vp = &vp1;
AVFormatParameters ap1, *ap = &ap1;
Fabrice Bellard
committed
/* see if audio/video inputs are needed */
has_video = 0;
has_audio = 0;
memset(ap, 0, sizeof(*ap));
Fabrice Bellard
committed
memset(vp, 0, sizeof(*vp));
for(j=0;j<nb_output_files;j++) {
oc = output_files[j];
for(i=0;i<oc->nb_streams;i++) {
Michael Niedermayer
committed
AVCodecContext *enc = oc->streams[i]->codec;
switch(enc->codec_type) {
case CODEC_TYPE_AUDIO:
if (enc->sample_rate > ap->sample_rate)
ap->sample_rate = enc->sample_rate;
if (enc->channels > ap->channels)
ap->channels = enc->channels;
has_audio = 1;
break;
case CODEC_TYPE_VIDEO:
Fabrice Bellard
committed
if (enc->width > vp->width)
vp->width = enc->width;
if (enc->height > vp->height)
vp->height = enc->height;
Michael Niedermayer
committed
if (vp->time_base.num*(int64_t)enc->time_base.den > enc->time_base.num*(int64_t)vp->time_base.den){
vp->time_base = enc->time_base;
Michael Niedermayer
committed
}
has_video = 1;
break;
default:
av_abort();
}
}
}
if (has_video == 0 && has_audio == 0) {
fprintf(stderr, "Output file must have at least one audio or video stream\n");
exit(1);
}
if (has_video) {
AVInputFormat *fmt1;
fmt1 = av_find_input_format(video_grab_format);
Fabrice Bellard
committed
vp->device = video_device;
vp->channel = video_channel;
vp->standard = video_standard;
Fabrice Bellard
committed
if (av_open_input_file(&ic, "", fmt1, 0, vp) < 0) {
fprintf(stderr, "Could not find video grab device\n");
exit(1);
}
/* If not enough info to get the stream parameters, we decode the
first frames to get it. */
if ((ic->ctx_flags & AVFMTCTX_NOHEADER) && av_find_stream_info(ic) < 0) {
fprintf(stderr, "Could not find video grab parameters\n");
exit(1);
}
/* by now video grab has one stream */
ic->streams[0]->r_frame_rate.num = vp->time_base.den;
ic->streams[0]->r_frame_rate.den = vp->time_base.num;
input_files[nb_input_files] = ic;
if (verbose >= 0)
dump_format(ic, nb_input_files, "", 0);
nb_input_files++;
}
if (has_audio && audio_grab_format) {
AVInputFormat *fmt1;
fmt1 = av_find_input_format(audio_grab_format);
Fabrice Bellard
committed
ap->device = audio_device;
if (av_open_input_file(&ic, "", fmt1, 0, ap) < 0) {
fprintf(stderr, "Could not find audio grab device\n");
exit(1);
}
input_files[nb_input_files] = ic;
if (verbose >= 0)
dump_format(ic, nb_input_files, "", 0);
nb_input_files++;
}
}
/* same option as mencoder */
static void opt_pass(const char *pass_str)
{
int pass;
pass = atoi(pass_str);
if (pass != 1 && pass != 2) {
fprintf(stderr, "pass number can be only 1 or 2\n");
exit(1);
}
do_pass = pass;
}
#if defined(CONFIG_WIN32) || defined(CONFIG_OS2)
return av_gettime();
struct rusage rusage;
getrusage(RUSAGE_SELF, &rusage);
return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
extern int ffm_nopts;
static void opt_bitexact(void)
/* disable generate of real time pts in ffm (need to be supressed anyway) */
ffm_nopts = 1;
}
static void show_formats(void)
AVInputFormat *ifmt;
AVOutputFormat *ofmt;
Fabrice Bellard
committed
AVImageFormat *image_fmt;
AVCodec *p, *p2;
const char **pp, *last_name;
printf("File formats:\n");
last_name= "000";
for(;;){
int decode=0;
int encode=0;
const char *name=NULL;
Michael Niedermayer
committed
const char *long_name=NULL;
for(ofmt = first_oformat; ofmt != NULL; ofmt = ofmt->next) {
if((name == NULL || strcmp(ofmt->name, name)<0) &&
strcmp(ofmt->name, last_name)>0){
name= ofmt->name;
Michael Niedermayer
committed
long_name= ofmt->long_name;
encode=1;
}
}
for(ifmt = first_iformat; ifmt != NULL; ifmt = ifmt->next) {
if((name == NULL || strcmp(ifmt->name, name)<0) &&
strcmp(ifmt->name, last_name)>0){
name= ifmt->name;
Michael Niedermayer
committed
long_name= ifmt->long_name;
encode=0;
}
if(name && strcmp(ifmt->name, name)==0)
decode=1;
}
if(name==NULL)
break;
last_name= name;
printf(
Michael Niedermayer
committed
" %s%s %-15s %s\n",
decode ? "D":" ",
encode ? "E":" ",
Michael Niedermayer
committed
name,
long_name ? long_name:" ");
Fabrice Bellard
committed
}
printf("\n");
Michael Niedermayer
committed
printf("Image formats (filename extensions, if any, follow):\n");
Fabrice Bellard
committed
for(image_fmt = first_image_format; image_fmt != NULL;
image_fmt = image_fmt->next) {
Michael Niedermayer
committed
" %s%s %-6s %s\n",
image_fmt->img_read ? "D":" ",
image_fmt->img_write ? "E":" ",
Michael Niedermayer
committed
image_fmt->name,
image_fmt->extensions ? image_fmt->extensions:" ");
Fabrice Bellard
committed
}
printf("\n");
last_name= "000";
for(;;){
int decode=0;
int encode=0;
int cap=0;
Fabrice Bellard
committed
const char *type_str;
p2=NULL;
for(p = first_avcodec; p != NULL; p = p->next) {
if((p2==NULL || strcmp(p->name, p2->name)<0) &&
strcmp(p->name, last_name)>0){
p2= p;
decode= encode= cap=0;
}
if(p2 && strcmp(p->name, p2->name)==0){
if(p->decode) decode=1;
if(p->encode) encode=1;
cap |= p->capabilities;
}
}
if(p2==NULL)
break;
last_name= p2->name;
Fabrice Bellard
committed
switch(p2->type) {
case CODEC_TYPE_VIDEO:
type_str = "V";
break;
case CODEC_TYPE_AUDIO:
type_str = "A";
break;
case CODEC_TYPE_SUBTITLE:
type_str = "S";
break;
default:
type_str = "?";
break;
}
printf(
" %s%s%s%s%s%s %s",
decode ? "D": (/*p2->decoder ? "d":*/" "),
encode ? "E":" ",
Fabrice Bellard
committed
type_str,
cap & CODEC_CAP_DRAW_HORIZ_BAND ? "S":" ",
cap & CODEC_CAP_DR1 ? "D":" ",
cap & CODEC_CAP_TRUNCATED ? "T":" ",
p2->name);
/* if(p2->decoder && decode==0)
printf(" use %s for decoding", p2->decoder->name);*/
printf("\n");
printf("Supported file protocols:\n");
for(up = first_protocol; up != NULL; up = up->next)
printf(" %s:", up->name);
printf("\n");
printf("Frame size, frame rate abbreviations:\n ntsc pal qntsc qpal sntsc spal film ntsc-film sqcif qcif cif 4cif\n");
printf("Motion estimation methods:\n");
if ((pp - motion_str + 1) == ME_ZERO)
else if ((pp - motion_str + 1) == ME_FULL)
else if ((pp - motion_str + 1) == ME_EPZS)