static av_cold int encode_init(AVCodecContext *avctx) { MpegEncContext *s = avctx->priv_data; if(ff_MPV_encode_init(avctx) < 0) return -1; if(find_frame_rate_index(s) < 0){ if(s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ av_log(avctx, AV_LOG_ERROR, "MPEG1/2 does not support %d/%d fps\n", avctx->time_base.den, avctx->time_base.num); return -1; }else{ av_log(avctx, AV_LOG_INFO, "MPEG1/2 does not support %d/%d fps, there may be AV sync issues\n", avctx->time_base.den, avctx->time_base.num); } } if(avctx->profile == FF_PROFILE_UNKNOWN){ if(avctx->level != FF_LEVEL_UNKNOWN){ av_log(avctx, AV_LOG_ERROR, "Set profile and level\n"); return -1; } avctx->profile = s->chroma_format == CHROMA_420 ? 4 : 0; /* Main or 4:2:2 */ } if(avctx->level == FF_LEVEL_UNKNOWN){ if(avctx->profile == 0){ /* 4:2:2 */ if(avctx->width <= 720 && avctx->height <= 608) avctx->level = 5; /* Main */ else avctx->level = 2; /* High */ }else{ if(avctx->profile != 1 && s->chroma_format != CHROMA_420){ av_log(avctx, AV_LOG_ERROR, "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n"); return -1; } if(avctx->width <= 720 && avctx->height <= 576) avctx->level = 8; /* Main */ else if(avctx->width <= 1440) avctx->level = 6; /* High 1440 */ else avctx->level = 4; /* High */ } } s->drop_frame_timecode = s->drop_frame_timecode || !!(avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE); if (s->drop_frame_timecode) s->tc.flags |= AV_TIMECODE_FLAG_DROPFRAME; if (s->drop_frame_timecode && s->frame_rate_index != 4) { av_log(avctx, AV_LOG_ERROR, "Drop frame time code only allowed with 1001/30000 fps\n"); return -1; } if (s->tc_opt_str) { AVRational rate = avpriv_frame_rate_tab[s->frame_rate_index]; int ret = av_timecode_init_from_string(&s->tc, rate, s->tc_opt_str, s); if (ret < 0) return ret; s->drop_frame_timecode = !!(s->tc.flags & AV_TIMECODE_FLAG_DROPFRAME); s->avctx->timecode_frame_start = s->tc.start; } else { s->avctx->timecode_frame_start = 0; // default is -1 } return 0; }
static av_cold int encode_init(AVCodecContext *avctx) { MpegEncContext *s = avctx->priv_data; if (ff_MPV_encode_init(avctx) < 0) return -1; if (find_frame_rate_index(s) < 0) { if (s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { av_log(avctx, AV_LOG_ERROR, "MPEG1/2 does not support %d/%d fps\n", avctx->time_base.den, avctx->time_base.num); return -1; } else { av_log(avctx, AV_LOG_INFO, "MPEG1/2 does not support %d/%d fps, there may be AV sync issues\n", avctx->time_base.den, avctx->time_base.num); } } if (avctx->profile == FF_PROFILE_UNKNOWN) { if (avctx->level != FF_LEVEL_UNKNOWN) { av_log(avctx, AV_LOG_ERROR, "Set profile and level\n"); return -1; } /* Main or 4:2:2 */ avctx->profile = s->chroma_format == CHROMA_420 ? 4 : 0; } if (avctx->level == FF_LEVEL_UNKNOWN) { if (avctx->profile == 0) { /* 4:2:2 */ if (avctx->width <= 720 && avctx->height <= 608) avctx->level = 5; /* Main */ else avctx->level = 2; /* High */ } else { if (avctx->profile != 1 && s->chroma_format != CHROMA_420) { av_log(avctx, AV_LOG_ERROR, "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n"); return -1; } if (avctx->width <= 720 && avctx->height <= 576) avctx->level = 8; /* Main */ else if (avctx->width <= 1440) avctx->level = 6; /* High 1440 */ else avctx->level = 4; /* High */ } } if (s->drop_frame_timecode && s->frame_rate_index != 4) { av_log(avctx, AV_LOG_ERROR, "Drop frame time code only allowed with 1001/30000 fps\n"); return -1; } return 0; }
static av_cold int wmv2_encode_init(AVCodecContext *avctx){ Wmv2Context * const w= avctx->priv_data; if(ff_MPV_encode_init(avctx) < 0) return -1; ff_wmv2_common_init(w); avctx->extradata_size= 4; avctx->extradata= av_mallocz(avctx->extradata_size + 10); encode_ext_header(w); return 0; }
static av_cold int encode_init(AVCodecContext *avctx) { MpegEncContext *s = avctx->priv_data; if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO && avctx->height > 2800) avctx->thread_count = 1; if (ff_MPV_encode_init(avctx) < 0) return -1; if (find_frame_rate_index(s) < 0) { if (s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { av_log(avctx, AV_LOG_ERROR, "MPEG1/2 does not support %d/%d fps\n", avctx->time_base.den, avctx->time_base.num); return -1; } else { av_log(avctx, AV_LOG_INFO, "MPEG1/2 does not support %d/%d fps, there may be AV sync issues\n", avctx->time_base.den, avctx->time_base.num); } } if (avctx->profile == FF_PROFILE_UNKNOWN) { if (avctx->level != FF_LEVEL_UNKNOWN) { av_log(avctx, AV_LOG_ERROR, "Set profile and level\n"); return -1; } /* Main or 4:2:2 */ avctx->profile = s->chroma_format == CHROMA_420 ? 4 : 0; } if (avctx->level == FF_LEVEL_UNKNOWN) { if (avctx->profile == 0) { /* 4:2:2 */ if (avctx->width <= 720 && avctx->height <= 608) avctx->level = 5; /* Main */ else avctx->level = 2; /* High */ } else { if (avctx->profile != 1 && s->chroma_format != CHROMA_420) { av_log(avctx, AV_LOG_ERROR, "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n"); return -1; } if (avctx->width <= 720 && avctx->height <= 576) avctx->level = 8; /* Main */ else if (avctx->width <= 1440) avctx->level = 6; /* High 1440 */ else avctx->level = 4; /* High */ } } if ((avctx->width & 0xFFF) == 0 && (avctx->height & 0xFFF) == 1) { av_log(avctx, AV_LOG_ERROR, "Width / Height is invalid for MPEG2\n"); return AVERROR(EINVAL); } if (s->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) { if ((avctx->width & 0xFFF) == 0 || (avctx->height & 0xFFF) == 0) { av_log(avctx, AV_LOG_ERROR, "Width or Height are not allowed to be multiplies of 4096\n" "add '-strict %d' if you want to use them anyway.\n", FF_COMPLIANCE_UNOFFICIAL); return AVERROR(EINVAL); } } s->drop_frame_timecode = s->drop_frame_timecode || !!(avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE); if (s->drop_frame_timecode) s->tc.flags |= AV_TIMECODE_FLAG_DROPFRAME; if (s->drop_frame_timecode && s->frame_rate_index != 4) { av_log(avctx, AV_LOG_ERROR, "Drop frame time code only allowed with 1001/30000 fps\n"); return -1; } if (s->tc_opt_str) { AVRational rate = ff_mpeg12_frame_rate_tab[s->frame_rate_index]; int ret = av_timecode_init_from_string(&s->tc, rate, s->tc_opt_str, s); if (ret < 0) return ret; s->drop_frame_timecode = !!(s->tc.flags & AV_TIMECODE_FLAG_DROPFRAME); s->avctx->timecode_frame_start = s->tc.start; } else { s->avctx->timecode_frame_start = 0; // default is -1 } return 0; }