static av_cold int encode_init(AVCodecContext *avctx) { MpegEncContext *s = avctx->priv_data; if(MPV_encode_init(avctx) < 0) return -1; #if FF_API_MPEGVIDEO_GLOBAL_OPTS if (avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) s->drop_frame_timecode = 1; if (avctx->flags & CODEC_FLAG_SVCD_SCAN_OFFSET) s->scan_offset = 1; #endif 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->tc.drop = s->drop_frame_timecode || !!(avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE); 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.str) { s->tc.rate = ff_frame_rate_tab[s->frame_rate_index]; if (ff_init_smtpe_timecode(s, &s->tc) < 0) return -1; s->avctx->timecode_frame_start = s->tc.start; } 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; } 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(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 */ } } if((avctx->flags2 & CODEC_FLAG2_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 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; }
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; } #if FF_API_PRIVATE_OPT FF_DISABLE_DEPRECATION_WARNINGS if (avctx->timecode_frame_start) s->timecode_frame_start = avctx->timecode_frame_start; FF_ENABLE_DEPRECATION_WARNINGS #endif return 0; }
static av_cold int encode_init(AVCodecContext *avctx) { MpegEncContext *s = avctx->priv_data; 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 = avctx->pix_fmt == PIX_FMT_YUV420P ? 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 && avctx->pix_fmt != PIX_FMT_YUV420P){ 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->rc_max_rate && !avctx->rc_buffer_size) { int max = 0; if (avctx->profile == 0) { max = avctx->level == 5 ? 9437184 : 47185920; } else if (avctx->profile == 4) { switch (avctx->level) { case 8: max = 1835008; break; case 6: max = 7340032; break; case 4: max = 9781248; break; } } else { switch (avctx->level) { case 8: max = 2441216; break; case 6: max = 9781248; break; case 4: max = 12222464; break; } } avctx->rc_buffer_size = FFMIN(max, avctx->rc_max_rate*65535LL/90000); } switch (avctx->color_primaries) { case AVCOL_PRI_BT709: avctx->color_transfer = AVCOL_TRC_BT709; avctx->color_matrix = AVCOL_MTX_BT709; break; case AVCOL_PRI_SMPTE170M: case AVCOL_PRI_BT470BG: avctx->color_transfer = AVCOL_TRC_BT709; avctx->color_matrix = AVCOL_MTX_SMPTE170M; break; } if(MPV_encode_init(avctx) < 0) return -1; if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0) { float best_aspect_error = 1E10; float aspect_ratio = av_q2d(s->avctx->sample_aspect_ratio); int i; for (i = 1; i < 15; i++) { float error = aspect_ratio; if (s->codec_id == CODEC_ID_MPEG1VIDEO || i <= 1) error -= 1.0/ff_mpeg1_aspect[i]; else error -= av_q2d(ff_mpeg2_aspect[i])*s->height/s->width; error = FFABS(error); // <= so square pixels can match 4:3 or 16:9 if (error <= best_aspect_error) { best_aspect_error = error; s->aspect_ratio_info = i; } } } if (!s->aspect_ratio_info) s->aspect_ratio_info = 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 (s->timecode) { int drop, framenum; AVRational fps = ff_frame_rate_tab[s->frame_rate_index]; framenum = ff_timecode_to_framenum(s->timecode, (AVRational){fps.den, fps.num}, &drop); if (framenum < 0) { if (framenum == -1) av_log(s, AV_LOG_ERROR, "error parsing timecode, syntax: 00:00:00[;:]00\n"); else if (framenum == -2) av_log(s, AV_LOG_ERROR, "error, unsupported fps for timecode\n"); else if (framenum == -3) av_log(s, AV_LOG_ERROR, "error, drop frame is only allowed with " "30000/1001 or 60000/1001 fps\n"); return -1; } s->timecode_start = framenum; s->timecode_drop_frame = drop; } if (s->pulldown) { if (strcmp(s->pulldown, "3:2")) { av_log(s, AV_LOG_ERROR, "error, unknown pulldown value\n"); return -1; } if (s->frame_rate_index != 1) { av_log(s, AV_LOG_ERROR, "error, pulldown only works with 24000/1001 fps\n"); return -1; } s->frame_rate_index = 4; // override frame rate to 30000/1001 } return 0; }
static av_cold int encode_init(AVCodecContext *avctx) { MpegEncContext *s = avctx->priv_data; 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 = avctx->pix_fmt == PIX_FMT_YUV420P ? 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 && avctx->pix_fmt != PIX_FMT_YUV420P){ 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->rc_max_rate && !avctx->rc_buffer_size) { int max = 0; if (avctx->profile == 0) { max = avctx->level == 5 ? 9437184 : 47185920; } else if (avctx->profile == 4) { switch (avctx->level) { case 8: max = 1835008; break; case 6: max = 7340032; break; case 4: max = 9781248; break; } } else { switch (avctx->level) { case 8: max = 2441216; break; case 6: max = 9781248; break; case 4: max = 12222464; break; } } avctx->rc_buffer_size = FFMIN(max, avctx->rc_max_rate*65535LL/90000); avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size*3/4; } switch (avctx->color_primaries) { case AVCOL_PRI_BT709: avctx->color_transfer = AVCOL_TRC_BT709; avctx->color_matrix = AVCOL_MTX_BT709; break; case AVCOL_PRI_SMPTE170M: case AVCOL_PRI_BT470BG: avctx->color_transfer = AVCOL_TRC_BT709; avctx->color_matrix = AVCOL_MTX_SMPTE170M; break; } if(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 (s->timecode) { int drop, framenum; AVRational fps = ff_frame_rate_tab[s->frame_rate_index]; framenum = ff_timecode_to_framenum(s->timecode, (AVRational){fps.den, fps.num}, &drop); if (framenum < 0) { if (framenum == -1) av_log(s, AV_LOG_ERROR, "error parsing timecode, syntax: 00:00:00[;:]00\n"); else if (framenum == -2) av_log(s, AV_LOG_ERROR, "error, unsupported fps for timecode\n"); else if (framenum == -3) av_log(s, AV_LOG_ERROR, "error, drop frame is only allowed with " "30000/1001 or 60000/1001 fps\n"); return -1; } s->timecode_start = framenum; s->timecode_drop_frame = drop; } return 0; }