| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * MPEG-1/2 encoder | ||
| 3 | * Copyright (c) 2000,2001 Fabrice Bellard | ||
| 4 | * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | ||
| 5 | * | ||
| 6 | * This file is part of FFmpeg. | ||
| 7 | * | ||
| 8 | * FFmpeg is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU Lesser General Public | ||
| 10 | * License as published by the Free Software Foundation; either | ||
| 11 | * version 2.1 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * Lesser General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public | ||
| 19 | * License along with FFmpeg; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 21 | */ | ||
| 22 | |||
| 23 | /** | ||
| 24 | * @file | ||
| 25 | * MPEG-1/2 encoder | ||
| 26 | */ | ||
| 27 | |||
| 28 | #include <assert.h> | ||
| 29 | #include <stdint.h> | ||
| 30 | |||
| 31 | #include "config.h" | ||
| 32 | #include "config_components.h" | ||
| 33 | #include "libavutil/attributes.h" | ||
| 34 | #include "libavutil/avassert.h" | ||
| 35 | #include "libavutil/log.h" | ||
| 36 | #include "libavutil/opt.h" | ||
| 37 | #include "libavutil/thread.h" | ||
| 38 | #include "libavutil/timecode.h" | ||
| 39 | #include "libavutil/stereo3d.h" | ||
| 40 | |||
| 41 | #include "avcodec.h" | ||
| 42 | #include "codec_internal.h" | ||
| 43 | #include "mathops.h" | ||
| 44 | #include "mpeg12.h" | ||
| 45 | #include "mpeg12data.h" | ||
| 46 | #include "mpeg12enc.h" | ||
| 47 | #include "mpeg12vlc.h" | ||
| 48 | #include "mpegutils.h" | ||
| 49 | #include "mpegvideo.h" | ||
| 50 | #include "mpegvideoenc.h" | ||
| 51 | #include "profiles.h" | ||
| 52 | #include "put_bits.h" | ||
| 53 | #include "rl.h" | ||
| 54 | |||
| 55 | #if CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER | ||
| 56 | static const uint8_t svcd_scan_offset_placeholder[] = { | ||
| 57 | 0x10, 0x0E, 0x00, 0x80, 0x81, 0x00, 0x80, | ||
| 58 | 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
| 59 | }; | ||
| 60 | |||
| 61 | static uint8_t mv_penalty[MAX_FCODE + 1][MAX_DMV * 2 + 1]; | ||
| 62 | static uint8_t fcode_tab[MAX_MV * 2 + 1]; | ||
| 63 | |||
| 64 | static uint8_t uni_mpeg1_ac_vlc_len[64 * 64 * 2]; | ||
| 65 | static uint8_t uni_mpeg2_ac_vlc_len[64 * 64 * 2]; | ||
| 66 | |||
| 67 | static uint8_t mpeg12_max_level[MAX_LEVEL + 1]; | ||
| 68 | static uint8_t mpeg12_index_run[MAX_RUN + 1]; | ||
| 69 | |||
| 70 | /* simple include everything table for dc, first byte is bits | ||
| 71 | * number next 3 are code */ | ||
| 72 | static uint32_t mpeg1_lum_dc_uni[512]; | ||
| 73 | static uint32_t mpeg1_chr_dc_uni[512]; | ||
| 74 | |||
| 75 | typedef struct MPEG12EncContext { | ||
| 76 | MPVMainEncContext mpeg; | ||
| 77 | AVRational frame_rate_ext; | ||
| 78 | unsigned frame_rate_index; | ||
| 79 | |||
| 80 | int gop_picture_number; ///< index of the first picture of a GOP based on fake_pic_num | ||
| 81 | |||
| 82 | int64_t timecode_frame_start; ///< GOP timecode frame start number, in non drop frame format | ||
| 83 | AVTimecode tc; ///< timecode context | ||
| 84 | char *tc_opt_str; ///< timecode option string | ||
| 85 | int drop_frame_timecode; ///< timecode is in drop frame format. | ||
| 86 | int scan_offset; ///< reserve space for SVCD scan offset user data. | ||
| 87 | |||
| 88 | int a53_cc; | ||
| 89 | int seq_disp_ext; | ||
| 90 | int video_format; | ||
| 91 | #define VIDEO_FORMAT_COMPONENT 0 | ||
| 92 | #define VIDEO_FORMAT_PAL 1 | ||
| 93 | #define VIDEO_FORMAT_NTSC 2 | ||
| 94 | #define VIDEO_FORMAT_SECAM 3 | ||
| 95 | #define VIDEO_FORMAT_MAC 4 | ||
| 96 | #define VIDEO_FORMAT_UNSPECIFIED 5 | ||
| 97 | } MPEG12EncContext; | ||
| 98 | |||
| 99 | #define A53_MAX_CC_COUNT 0x1f | ||
| 100 | #endif /* CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER */ | ||
| 101 | |||
| 102 | 125 | av_cold void ff_mpeg1_init_uni_ac_vlc(const int8_t max_level[], | |
| 103 | const uint8_t index_run[], | ||
| 104 | const uint16_t table_vlc[][2], | ||
| 105 | uint8_t uni_ac_vlc_len[]) | ||
| 106 | { | ||
| 107 | int i; | ||
| 108 | |||
| 109 |
2/2✓ Branch 0 taken 16000 times.
✓ Branch 1 taken 125 times.
|
16125 | for (i = 0; i < 128; i++) { |
| 110 | 16000 | int level = i - 64; | |
| 111 | int run; | ||
| 112 |
2/2✓ Branch 0 taken 125 times.
✓ Branch 1 taken 15875 times.
|
16000 | if (!level) |
| 113 | 125 | continue; | |
| 114 |
2/2✓ Branch 0 taken 1016000 times.
✓ Branch 1 taken 15875 times.
|
1031875 | for (run = 0; run < 64; run++) { |
| 115 | int len, code; | ||
| 116 | 1016000 | int alevel = FFABS(level); | |
| 117 | |||
| 118 |
2/2✓ Branch 0 taken 988070 times.
✓ Branch 1 taken 27930 times.
|
1016000 | if (alevel > max_level[run]) |
| 119 | 988070 | code = 111; /* rl->n */ | |
| 120 | else | ||
| 121 | 27930 | code = index_run[run] + alevel - 1; | |
| 122 | |||
| 123 |
2/2✓ Branch 0 taken 27750 times.
✓ Branch 1 taken 988250 times.
|
1016000 | if (code < 111) { /* rl->n */ |
| 124 | /* length of VLC and sign */ | ||
| 125 | 27750 | len = table_vlc[code][1] + 1; | |
| 126 | } else { | ||
| 127 | 988250 | len = table_vlc[MPEG12_RL_NB_ELEMS][1] + 6; | |
| 128 | |||
| 129 |
1/2✓ Branch 0 taken 988250 times.
✗ Branch 1 not taken.
|
988250 | if (alevel < 128) |
| 130 | 988250 | len += 8; | |
| 131 | else | ||
| 132 | ✗ | len += 16; | |
| 133 | } | ||
| 134 | |||
| 135 | 1016000 | uni_ac_vlc_len[UNI_AC_ENC_INDEX(run, i)] = len; | |
| 136 | } | ||
| 137 | } | ||
| 138 | 125 | } | |
| 139 | |||
| 140 | #if CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER | ||
| 141 | 325025 | static void put_header(MPVEncContext *const s, uint32_t header) | |
| 142 | { | ||
| 143 | 325025 | align_put_bits(&s->pb); | |
| 144 | 325025 | put_bits32(&s->pb, header); | |
| 145 | 325025 | } | |
| 146 | |||
| 147 | /* put sequence header if needed */ | ||
| 148 | 5144 | static void mpeg1_encode_sequence_header(MPEG12EncContext *mpeg12) | |
| 149 | { | ||
| 150 | 5144 | MPVEncContext *const s = &mpeg12->mpeg.s; | |
| 151 | unsigned int vbv_buffer_size, fps, v; | ||
| 152 | int constraint_parameter_flag; | ||
| 153 | 5144 | AVRational framerate = ff_mpeg12_frame_rate_tab[mpeg12->frame_rate_index]; | |
| 154 | uint64_t time_code; | ||
| 155 | 5144 | int64_t best_aspect_error = INT64_MAX; | |
| 156 | 5144 | AVRational aspect_ratio = s->c.avctx->sample_aspect_ratio; | |
| 157 | int aspect_ratio_info; | ||
| 158 | |||
| 159 | 5144 | put_bits_assume_flushed(&s->pb); | |
| 160 | |||
| 161 |
2/2✓ Branch 0 taken 4699 times.
✓ Branch 1 taken 445 times.
|
5144 | if (!(s->c.cur_pic.ptr->f->flags & AV_FRAME_FLAG_KEY)) |
| 162 | 4699 | return; | |
| 163 | |||
| 164 |
3/4✓ Branch 0 taken 34 times.
✓ Branch 1 taken 411 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 34 times.
|
445 | if (aspect_ratio.num == 0 || aspect_ratio.den == 0) |
| 165 | 411 | aspect_ratio = (AVRational){1,1}; // pixel aspect 1.1 (VGA) | |
| 166 | |||
| 167 | /* MPEG-1 header repeated every GOP */ | ||
| 168 | 445 | put_header(s, SEQ_START_CODE); | |
| 169 | |||
| 170 | 445 | put_sbits(&s->pb, 12, s->c.width & 0xFFF); | |
| 171 | 445 | put_sbits(&s->pb, 12, s->c.height & 0xFFF); | |
| 172 | |||
| 173 |
2/2✓ Branch 0 taken 6230 times.
✓ Branch 1 taken 445 times.
|
6675 | for (int i = 1; i < 15; i++) { |
| 174 | 6230 | int64_t error = aspect_ratio.num * (1LL<<32) / aspect_ratio.den; | |
| 175 |
4/4✓ Branch 0 taken 5488 times.
✓ Branch 1 taken 742 times.
✓ Branch 2 taken 392 times.
✓ Branch 3 taken 5096 times.
|
6230 | if (s->c.codec_id == AV_CODEC_ID_MPEG1VIDEO || i <= 1) |
| 176 | 1134 | error -= (1LL<<32) / ff_mpeg1_aspect[i]; | |
| 177 | else | ||
| 178 | 5096 | error -= (1LL<<32)*ff_mpeg2_aspect[i].num * s->c.height / s->c.width / ff_mpeg2_aspect[i].den; | |
| 179 | |||
| 180 | 6230 | error = FFABS(error); | |
| 181 | |||
| 182 |
2/2✓ Branch 0 taken 474 times.
✓ Branch 1 taken 5756 times.
|
6230 | if (error - 2 <= best_aspect_error) { |
| 183 | 474 | best_aspect_error = error; | |
| 184 | 474 | aspect_ratio_info = i; | |
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | 445 | put_bits(&s->pb, 4, aspect_ratio_info); | |
| 189 | 445 | put_bits(&s->pb, 4, mpeg12->frame_rate_index); | |
| 190 | |||
| 191 |
2/2✓ Branch 0 taken 153 times.
✓ Branch 1 taken 292 times.
|
445 | if (s->c.avctx->rc_max_rate) { |
| 192 | 153 | v = (s->c.avctx->rc_max_rate + 399) / 400; | |
| 193 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 153 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
153 | if (v > 0x3ffff && s->c.codec_id == AV_CODEC_ID_MPEG1VIDEO) |
| 194 | ✗ | v = 0x3ffff; | |
| 195 | } else { | ||
| 196 | 292 | v = 0x3FFFF; | |
| 197 | } | ||
| 198 | |||
| 199 |
2/2✓ Branch 0 taken 153 times.
✓ Branch 1 taken 292 times.
|
445 | if (s->c.avctx->rc_buffer_size) |
| 200 | 153 | vbv_buffer_size = s->c.avctx->rc_buffer_size; | |
| 201 | else | ||
| 202 | /* VBV calculation: Scaled so that a VCD has the proper | ||
| 203 | * VBV size of 40 kilobytes */ | ||
| 204 | 292 | vbv_buffer_size = av_rescale_rnd(mpeg12->mpeg.bit_rate, 20, 1151929 / 2, AV_ROUND_ZERO) * 8 * 1024; | |
| 205 | 445 | vbv_buffer_size = (vbv_buffer_size + 16383) / 16384; | |
| 206 | |||
| 207 | 445 | put_sbits(&s->pb, 18, v); | |
| 208 | 445 | put_bits(&s->pb, 1, 1); // marker | |
| 209 | 445 | put_sbits(&s->pb, 10, vbv_buffer_size); | |
| 210 | |||
| 211 | 445 | constraint_parameter_flag = | |
| 212 | 887 | s->c.width <= 768 && | |
| 213 |
2/2✓ Branch 0 taken 292 times.
✓ Branch 1 taken 150 times.
|
442 | s->c.height <= 576 && |
| 214 |
2/2✓ Branch 0 taken 269 times.
✓ Branch 1 taken 23 times.
|
292 | s->c.mb_width * s->c.mb_height <= 396 && |
| 215 |
2/2✓ Branch 0 taken 263 times.
✓ Branch 1 taken 6 times.
|
269 | s->c.mb_width * s->c.mb_height * framerate.num <= 396 * 25 * framerate.den && |
| 216 |
1/2✓ Branch 0 taken 263 times.
✗ Branch 1 not taken.
|
263 | framerate.num <= framerate.den * 30 && |
| 217 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 263 times.
|
263 | s->c.avctx->me_range && |
| 218 | ✗ | s->c.avctx->me_range < 128 && | |
| 219 | ✗ | vbv_buffer_size <= 20 && | |
| 220 |
2/2✓ Branch 0 taken 442 times.
✓ Branch 1 taken 3 times.
|
887 | v <= 1856000 / 400 && |
| 221 | ✗ | s->c.codec_id == AV_CODEC_ID_MPEG1VIDEO; | |
| 222 | |||
| 223 | 445 | put_bits(&s->pb, 1, constraint_parameter_flag); | |
| 224 | |||
| 225 | 445 | ff_write_quant_matrix(&s->pb, s->c.avctx->intra_matrix); | |
| 226 | 445 | ff_write_quant_matrix(&s->pb, s->c.avctx->inter_matrix); | |
| 227 | |||
| 228 |
2/2✓ Branch 0 taken 392 times.
✓ Branch 1 taken 53 times.
|
445 | if (s->c.codec_id == AV_CODEC_ID_MPEG2VIDEO) { |
| 229 | const AVFrameSideData *side_data; | ||
| 230 | 392 | int width = s->c.width; | |
| 231 | 392 | int height = s->c.height; | |
| 232 | int use_seq_disp_ext; | ||
| 233 | |||
| 234 | 392 | put_header(s, EXT_START_CODE); | |
| 235 | 392 | put_bits(&s->pb, 4, 1); // seq ext | |
| 236 | |||
| 237 | 392 | put_bits(&s->pb, 1, s->c.avctx->profile == AV_PROFILE_MPEG2_422); // escx 1 for 4:2:2 profile | |
| 238 | |||
| 239 | 392 | put_bits(&s->pb, 3, s->c.avctx->profile); // profile | |
| 240 | 392 | put_bits(&s->pb, 4, s->c.avctx->level); // level | |
| 241 | |||
| 242 | 392 | put_bits(&s->pb, 1, s->c.progressive_sequence); | |
| 243 | 392 | put_bits(&s->pb, 2, s->c.chroma_format); | |
| 244 | 392 | put_bits(&s->pb, 2, s->c.width >> 12); | |
| 245 | 392 | put_bits(&s->pb, 2, s->c.height >> 12); | |
| 246 | 392 | put_bits(&s->pb, 12, v >> 18); // bitrate ext | |
| 247 | 392 | put_bits(&s->pb, 1, 1); // marker | |
| 248 | 392 | put_bits(&s->pb, 8, vbv_buffer_size >> 10); // vbv buffer ext | |
| 249 | 392 | put_bits(&s->pb, 1, s->c.low_delay); | |
| 250 | 392 | put_bits(&s->pb, 2, mpeg12->frame_rate_ext.num-1); // frame_rate_ext_n | |
| 251 | 392 | put_bits(&s->pb, 5, mpeg12->frame_rate_ext.den-1); // frame_rate_ext_d | |
| 252 | |||
| 253 | 392 | side_data = av_frame_get_side_data(s->c.cur_pic.ptr->f, AV_FRAME_DATA_PANSCAN); | |
| 254 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 387 times.
|
392 | if (side_data) { |
| 255 | 5 | const AVPanScan *pan_scan = (AVPanScan *)side_data->data; | |
| 256 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | if (pan_scan->width && pan_scan->height) { |
| 257 | 5 | width = pan_scan->width >> 4; | |
| 258 | 5 | height = pan_scan->height >> 4; | |
| 259 | } | ||
| 260 | } | ||
| 261 | |||
| 262 | 1176 | use_seq_disp_ext = (width != s->c.width || | |
| 263 |
1/2✓ Branch 0 taken 392 times.
✗ Branch 1 not taken.
|
392 | height != s->c.height || |
| 264 |
2/2✓ Branch 0 taken 383 times.
✓ Branch 1 taken 9 times.
|
392 | s->c.avctx->color_primaries != AVCOL_PRI_UNSPECIFIED || |
| 265 |
2/2✓ Branch 0 taken 380 times.
✓ Branch 1 taken 3 times.
|
383 | s->c.avctx->color_trc != AVCOL_TRC_UNSPECIFIED || |
| 266 |
3/4✓ Branch 0 taken 392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 354 times.
✓ Branch 3 taken 26 times.
|
1138 | s->c.avctx->colorspace != AVCOL_SPC_UNSPECIFIED || |
| 267 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 354 times.
|
354 | mpeg12->video_format != VIDEO_FORMAT_UNSPECIFIED); |
| 268 | |||
| 269 |
1/2✓ Branch 0 taken 392 times.
✗ Branch 1 not taken.
|
392 | if (mpeg12->seq_disp_ext == 1 || |
| 270 |
3/4✓ Branch 0 taken 392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
✓ Branch 3 taken 354 times.
|
392 | (mpeg12->seq_disp_ext == -1 && use_seq_disp_ext)) { |
| 271 | 38 | put_header(s, EXT_START_CODE); | |
| 272 | 38 | put_bits(&s->pb, 4, 2); // sequence display extension | |
| 273 | 38 | put_bits(&s->pb, 3, mpeg12->video_format); // video_format | |
| 274 | 38 | put_bits(&s->pb, 1, 1); // colour_description | |
| 275 | 38 | put_bits(&s->pb, 8, s->c.avctx->color_primaries); // colour_primaries | |
| 276 | 38 | put_bits(&s->pb, 8, s->c.avctx->color_trc); // transfer_characteristics | |
| 277 | 38 | put_bits(&s->pb, 8, s->c.avctx->colorspace); // matrix_coefficients | |
| 278 | 38 | put_bits(&s->pb, 14, width); // display_horizontal_size | |
| 279 | 38 | put_bits(&s->pb, 1, 1); // marker_bit | |
| 280 | 38 | put_bits(&s->pb, 14, height); // display_vertical_size | |
| 281 | 38 | put_bits(&s->pb, 3, 0); // remaining 3 bits are zero padding | |
| 282 | } | ||
| 283 | } | ||
| 284 | |||
| 285 | 445 | put_header(s, GOP_START_CODE); | |
| 286 | 445 | put_bits(&s->pb, 1, mpeg12->drop_frame_timecode); // drop frame flag | |
| 287 | /* time code: we must convert from the real frame rate to a | ||
| 288 | * fake MPEG frame rate in case of low frame rate */ | ||
| 289 | 445 | fps = (framerate.num + framerate.den / 2) / framerate.den; | |
| 290 | 445 | time_code = s->c.cur_pic.ptr->coded_picture_number + | |
| 291 | 445 | mpeg12->timecode_frame_start; | |
| 292 | |||
| 293 | 445 | mpeg12->gop_picture_number = s->c.cur_pic.ptr->coded_picture_number; | |
| 294 | |||
| 295 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 445 times.
|
445 | av_assert0(mpeg12->drop_frame_timecode == !!(mpeg12->tc.flags & AV_TIMECODE_FLAG_DROPFRAME)); |
| 296 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 436 times.
|
445 | if (mpeg12->drop_frame_timecode) |
| 297 | 9 | time_code = av_timecode_adjust_ntsc_framenum2(time_code, fps); | |
| 298 | |||
| 299 | 445 | put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24)); | |
| 300 | 445 | put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60)); | |
| 301 | 445 | put_bits(&s->pb, 1, 1); | |
| 302 | 445 | put_bits(&s->pb, 6, (uint32_t)((time_code / fps) % 60)); | |
| 303 | 445 | put_bits(&s->pb, 6, (uint32_t)((time_code % fps))); | |
| 304 | 445 | put_bits(&s->pb, 1, !!(s->c.avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) || | |
| 305 |
5/6✓ Branch 0 taken 445 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 295 times.
✓ Branch 3 taken 150 times.
✓ Branch 4 taken 57 times.
✓ Branch 5 taken 238 times.
|
445 | mpeg12->mpeg.intra_only || !mpeg12->gop_picture_number); |
| 306 | 445 | put_bits(&s->pb, 1, 0); // broken link | |
| 307 | } | ||
| 308 | |||
| 309 | 1813605 | static inline void encode_mb_skip_run(MPVEncContext *const s, int run) | |
| 310 | { | ||
| 311 |
2/2✓ Branch 0 taken 69199 times.
✓ Branch 1 taken 1813605 times.
|
1882804 | while (run >= 33) { |
| 312 | 69199 | put_bits(&s->pb, 11, 0x008); | |
| 313 | 69199 | run -= 33; | |
| 314 | } | ||
| 315 | 1813605 | put_bits(&s->pb, ff_mpeg12_mbAddrIncrTable[run][1], | |
| 316 | 1813605 | ff_mpeg12_mbAddrIncrTable[run][0]); | |
| 317 | 1813605 | } | |
| 318 | |||
| 319 | 495921 | static av_always_inline void put_qscale(MPVEncContext *const s) | |
| 320 | { | ||
| 321 | 495921 | put_bits(&s->pb, 5, s->c.qscale); | |
| 322 | 495921 | } | |
| 323 | |||
| 324 | 313763 | void ff_mpeg1_encode_slice_header(MPVEncContext *const s) | |
| 325 | { | ||
| 326 |
3/4✓ Branch 0 taken 306490 times.
✓ Branch 1 taken 7273 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 306490 times.
|
313763 | if (s->c.codec_id == AV_CODEC_ID_MPEG2VIDEO && s->c.height > 2800) { |
| 327 | ✗ | put_header(s, SLICE_MIN_START_CODE + (s->c.mb_y & 127)); | |
| 328 | /* slice_vertical_position_extension */ | ||
| 329 | ✗ | put_bits(&s->pb, 3, s->c.mb_y >> 7); | |
| 330 | } else { | ||
| 331 | av_assert1(s->c.mb_y <= SLICE_MAX_START_CODE - SLICE_MIN_START_CODE); | ||
| 332 | 313763 | put_header(s, SLICE_MIN_START_CODE + s->c.mb_y); | |
| 333 | } | ||
| 334 | 313763 | put_qscale(s); | |
| 335 | /* slice extra information */ | ||
| 336 | 313763 | put_bits(&s->pb, 1, 0); | |
| 337 | 313763 | } | |
| 338 | |||
| 339 | 5144 | static int mpeg1_encode_picture_header(MPVMainEncContext *const m) | |
| 340 | { | ||
| 341 | 5144 | MPEG12EncContext *const mpeg12 = (MPEG12EncContext*)m; | |
| 342 | 5144 | MPVEncContext *const s = &m->s; | |
| 343 | const AVFrameSideData *side_data; | ||
| 344 | |||
| 345 | 5144 | put_bits_assume_flushed(&s->pb); | |
| 346 | |||
| 347 | 5144 | mpeg1_encode_sequence_header(mpeg12); | |
| 348 | |||
| 349 | /* MPEG-1 picture header */ | ||
| 350 | 5144 | put_header(s, PICTURE_START_CODE); | |
| 351 | /* temporal reference */ | ||
| 352 | |||
| 353 | 5144 | put_bits(&s->pb, 10, | |
| 354 | 5144 | (s->picture_number - mpeg12->gop_picture_number) & 0x3ff); | |
| 355 | 5144 | put_bits(&s->pb, 3, s->c.pict_type); | |
| 356 | |||
| 357 | 5144 | m->vbv_delay_pos = put_bytes_count(&s->pb, 0); | |
| 358 | 5144 | put_bits(&s->pb, 16, 0xFFFF); /* vbv_delay */ | |
| 359 | |||
| 360 | // RAL: Forward f_code also needed for B-frames | ||
| 361 |
2/2✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 3992 times.
|
5144 | if (s->c.pict_type == AV_PICTURE_TYPE_P || |
| 362 |
2/2✓ Branch 0 taken 707 times.
✓ Branch 1 taken 445 times.
|
1152 | s->c.pict_type == AV_PICTURE_TYPE_B) { |
| 363 | 4699 | put_bits(&s->pb, 1, 0); /* half pel coordinates */ | |
| 364 |
2/2✓ Branch 0 taken 427 times.
✓ Branch 1 taken 4272 times.
|
4699 | if (s->c.codec_id == AV_CODEC_ID_MPEG1VIDEO) |
| 365 | 427 | put_bits(&s->pb, 3, s->f_code); /* forward_f_code */ | |
| 366 | else | ||
| 367 | 4272 | put_bits(&s->pb, 3, 7); /* forward_f_code */ | |
| 368 | } | ||
| 369 | |||
| 370 | // RAL: Backward f_code necessary for B-frames | ||
| 371 |
2/2✓ Branch 0 taken 707 times.
✓ Branch 1 taken 4437 times.
|
5144 | if (s->c.pict_type == AV_PICTURE_TYPE_B) { |
| 372 | 707 | put_bits(&s->pb, 1, 0); /* half pel coordinates */ | |
| 373 |
2/2✓ Branch 0 taken 144 times.
✓ Branch 1 taken 563 times.
|
707 | if (s->c.codec_id == AV_CODEC_ID_MPEG1VIDEO) |
| 374 | 144 | put_bits(&s->pb, 3, s->b_code); /* backward_f_code */ | |
| 375 | else | ||
| 376 | 563 | put_bits(&s->pb, 3, 7); /* backward_f_code */ | |
| 377 | } | ||
| 378 | |||
| 379 | 5144 | put_bits(&s->pb, 1, 0); /* extra bit picture */ | |
| 380 | |||
| 381 | 5144 | s->c.frame_pred_frame_dct = 1; | |
| 382 |
2/2✓ Branch 0 taken 4664 times.
✓ Branch 1 taken 480 times.
|
5144 | if (s->c.codec_id == AV_CODEC_ID_MPEG2VIDEO) { |
| 383 | 4664 | put_header(s, EXT_START_CODE); | |
| 384 | 4664 | put_bits(&s->pb, 4, 8); /* pic ext */ | |
| 385 |
2/2✓ Branch 0 taken 955 times.
✓ Branch 1 taken 3709 times.
|
4664 | if (s->c.pict_type == AV_PICTURE_TYPE_P || |
| 386 |
2/2✓ Branch 0 taken 563 times.
✓ Branch 1 taken 392 times.
|
955 | s->c.pict_type == AV_PICTURE_TYPE_B) { |
| 387 | 4272 | put_bits(&s->pb, 4, s->f_code); | |
| 388 | 4272 | put_bits(&s->pb, 4, s->f_code); | |
| 389 | } else { | ||
| 390 | 392 | put_bits(&s->pb, 8, 255); | |
| 391 | } | ||
| 392 |
2/2✓ Branch 0 taken 563 times.
✓ Branch 1 taken 4101 times.
|
4664 | if (s->c.pict_type == AV_PICTURE_TYPE_B) { |
| 393 | 563 | put_bits(&s->pb, 4, s->b_code); | |
| 394 | 563 | put_bits(&s->pb, 4, s->b_code); | |
| 395 | } else { | ||
| 396 | 4101 | put_bits(&s->pb, 8, 255); | |
| 397 | } | ||
| 398 | 4664 | put_bits(&s->pb, 2, s->c.intra_dc_precision); | |
| 399 | |||
| 400 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4664 times.
|
4664 | av_assert0(s->c.picture_structure == PICT_FRAME); |
| 401 | 4664 | put_bits(&s->pb, 2, s->c.picture_structure); | |
| 402 |
2/2✓ Branch 0 taken 3514 times.
✓ Branch 1 taken 1150 times.
|
4664 | if (s->c.progressive_sequence) |
| 403 | 3514 | put_bits(&s->pb, 1, 0); /* no repeat */ | |
| 404 | else | ||
| 405 | 1150 | put_bits(&s->pb, 1, !!(s->c.cur_pic.ptr->f->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST)); | |
| 406 | /* XXX: optimize the generation of this flag with entropy measures */ | ||
| 407 | 4664 | s->c.frame_pred_frame_dct = s->c.progressive_sequence; | |
| 408 | |||
| 409 | 4664 | put_bits(&s->pb, 1, s->c.frame_pred_frame_dct); | |
| 410 | 4664 | put_bits(&s->pb, 1, s->c.concealment_motion_vectors); | |
| 411 | 4664 | put_bits(&s->pb, 1, s->c.q_scale_type); | |
| 412 | 4664 | put_bits(&s->pb, 1, s->c.intra_vlc_format); | |
| 413 | 4664 | put_bits(&s->pb, 1, s->c.alternate_scan); | |
| 414 | 4664 | put_bits(&s->pb, 1, s->c.repeat_first_field); | |
| 415 | 4664 | s->c.progressive_frame = s->c.progressive_sequence; | |
| 416 | /* chroma_420_type */ | ||
| 417 |
2/2✓ Branch 0 taken 4314 times.
✓ Branch 1 taken 350 times.
|
8978 | put_bits(&s->pb, 1, s->c.chroma_format == |
| 418 | 4314 | CHROMA_420 ? s->c.progressive_frame : 0); | |
| 419 | 4664 | put_bits(&s->pb, 1, s->c.progressive_frame); | |
| 420 | 4664 | put_bits(&s->pb, 1, 0); /* composite_display_flag */ | |
| 421 | } | ||
| 422 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5144 times.
|
5144 | if (mpeg12->scan_offset) { |
| 423 | int i; | ||
| 424 | |||
| 425 | ✗ | put_header(s, USER_START_CODE); | |
| 426 | ✗ | for (i = 0; i < sizeof(svcd_scan_offset_placeholder); i++) | |
| 427 | ✗ | put_bits(&s->pb, 8, svcd_scan_offset_placeholder[i]); | |
| 428 | } | ||
| 429 | 5144 | side_data = av_frame_get_side_data(s->c.cur_pic.ptr->f, | |
| 430 | AV_FRAME_DATA_STEREO3D); | ||
| 431 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5144 times.
|
5144 | if (side_data) { |
| 432 | ✗ | const AVStereo3D *stereo = (AVStereo3D *)side_data->data; | |
| 433 | uint8_t fpa_type; | ||
| 434 | |||
| 435 | ✗ | switch (stereo->type) { | |
| 436 | ✗ | case AV_STEREO3D_SIDEBYSIDE: | |
| 437 | ✗ | fpa_type = 0x03; | |
| 438 | ✗ | break; | |
| 439 | ✗ | case AV_STEREO3D_TOPBOTTOM: | |
| 440 | ✗ | fpa_type = 0x04; | |
| 441 | ✗ | break; | |
| 442 | ✗ | case AV_STEREO3D_2D: | |
| 443 | ✗ | fpa_type = 0x08; | |
| 444 | ✗ | break; | |
| 445 | ✗ | case AV_STEREO3D_SIDEBYSIDE_QUINCUNX: | |
| 446 | ✗ | fpa_type = 0x23; | |
| 447 | ✗ | break; | |
| 448 | ✗ | default: | |
| 449 | ✗ | fpa_type = 0; | |
| 450 | ✗ | break; | |
| 451 | } | ||
| 452 | |||
| 453 | ✗ | if (fpa_type != 0) { | |
| 454 | ✗ | put_header(s, USER_START_CODE); | |
| 455 | // S3D_video_format_signaling_identifier | ||
| 456 | ✗ | put_bits32(&s->pb, MKBETAG('J','P','3','D')); | |
| 457 | ✗ | put_bits(&s->pb, 8, 0x03); // S3D_video_format_length | |
| 458 | |||
| 459 | ✗ | put_bits(&s->pb, 1, 1); // reserved_bit | |
| 460 | ✗ | put_bits(&s->pb, 7, fpa_type); // S3D_video_format_type | |
| 461 | ✗ | put_bits(&s->pb, 16, 0x04FF); // reserved_data | |
| 462 | } | ||
| 463 | } | ||
| 464 | |||
| 465 |
2/2✓ Branch 0 taken 4664 times.
✓ Branch 1 taken 480 times.
|
5144 | if (CONFIG_MPEG2VIDEO_ENCODER && mpeg12->a53_cc) { |
| 466 | 4664 | side_data = av_frame_get_side_data(s->c.cur_pic.ptr->f, | |
| 467 | AV_FRAME_DATA_A53_CC); | ||
| 468 |
2/2✓ Branch 0 taken 135 times.
✓ Branch 1 taken 4529 times.
|
4664 | if (side_data) { |
| 469 |
3/4✓ Branch 0 taken 134 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 134 times.
✗ Branch 3 not taken.
|
135 | if (side_data->size <= A53_MAX_CC_COUNT * 3 && side_data->size % 3 == 0) { |
| 470 | 134 | put_header (s, USER_START_CODE); | |
| 471 | |||
| 472 | 134 | put_bits32(&s->pb, MKBETAG('G','A','9','4')); // user_identifier | |
| 473 | 134 | put_bits(&s->pb, 8, 3); // user_data_type_code | |
| 474 | 134 | put_bits(&s->pb, 8, | |
| 475 | 134 | (side_data->size / 3 & A53_MAX_CC_COUNT) | 0x40); // flags, cc_count | |
| 476 | 134 | put_bits(&s->pb, 8, 0xff); // em_data | |
| 477 | |||
| 478 |
2/2✓ Branch 0 taken 8040 times.
✓ Branch 1 taken 134 times.
|
8174 | for (int i = 0; i < side_data->size; i++) |
| 479 | 8040 | put_bits(&s->pb, 8, side_data->data[i]); | |
| 480 | |||
| 481 | 134 | put_bits(&s->pb, 8, 0xff); // marker_bits | |
| 482 | } else { | ||
| 483 | 1 | av_log(s->c.avctx, AV_LOG_WARNING, | |
| 484 | "Closed Caption size (%zu) can not exceed " | ||
| 485 | 1 | "93 bytes and must be a multiple of 3\n", side_data->size); | |
| 486 | } | ||
| 487 | } | ||
| 488 | } | ||
| 489 | |||
| 490 | 5144 | s->c.mb_y = 0; | |
| 491 | 5144 | ff_mpeg1_encode_slice_header(s); | |
| 492 | |||
| 493 | 5144 | return 0; | |
| 494 | } | ||
| 495 | |||
| 496 | 1464560 | static inline void put_mb_modes(MPVEncContext *const s, int n, int bits, | |
| 497 | int has_mv, int field_motion) | ||
| 498 | { | ||
| 499 | 1464560 | put_bits(&s->pb, n, bits); | |
| 500 |
2/2✓ Branch 0 taken 751049 times.
✓ Branch 1 taken 713511 times.
|
1464560 | if (!s->c.frame_pred_frame_dct) { |
| 501 |
2/2✓ Branch 0 taken 407012 times.
✓ Branch 1 taken 344037 times.
|
751049 | if (has_mv) |
| 502 | /* motion_type: frame/field */ | ||
| 503 | 407012 | put_bits(&s->pb, 2, 2 - field_motion); | |
| 504 | 751049 | put_bits(&s->pb, 1, s->c.interlaced_dct); | |
| 505 | } | ||
| 506 | 1464560 | } | |
| 507 | |||
| 508 | // RAL: Parameter added: f_or_b_code | ||
| 509 | 3339596 | static void mpeg1_encode_motion(MPVEncContext *const s, int val, int f_or_b_code) | |
| 510 | { | ||
| 511 |
2/2✓ Branch 0 taken 1368962 times.
✓ Branch 1 taken 1970634 times.
|
3339596 | if (val == 0) { |
| 512 | /* zero vector, corresponds to ff_mpeg12_mbMotionVectorTable[0] */ | ||
| 513 | 1368962 | put_bits(&s->pb, 1, 0x01); | |
| 514 | } else { | ||
| 515 | int code, sign, bits; | ||
| 516 | 1970634 | int bit_size = f_or_b_code - 1; | |
| 517 | 1970634 | int range = 1 << bit_size; | |
| 518 | /* modulo encoding */ | ||
| 519 | 1970634 | val = sign_extend(val, 5 + bit_size); | |
| 520 | |||
| 521 |
2/2✓ Branch 0 taken 950678 times.
✓ Branch 1 taken 1019956 times.
|
1970634 | if (val >= 0) { |
| 522 | 950678 | val--; | |
| 523 | 950678 | code = (val >> bit_size) + 1; | |
| 524 | 950678 | bits = val & (range - 1); | |
| 525 | 950678 | sign = 0; | |
| 526 | } else { | ||
| 527 | 1019956 | val = -val; | |
| 528 | 1019956 | val--; | |
| 529 | 1019956 | code = (val >> bit_size) + 1; | |
| 530 | 1019956 | bits = val & (range - 1); | |
| 531 | 1019956 | sign = 1; | |
| 532 | } | ||
| 533 | |||
| 534 | av_assert2(code > 0 && code <= 16); | ||
| 535 | |||
| 536 | 1970634 | put_bits(&s->pb, | |
| 537 | 1970634 | ff_mpeg12_mbMotionVectorTable[code][1], | |
| 538 | 1970634 | ff_mpeg12_mbMotionVectorTable[code][0]); | |
| 539 | |||
| 540 | 1970634 | put_bits(&s->pb, 1, sign); | |
| 541 |
2/2✓ Branch 0 taken 1418976 times.
✓ Branch 1 taken 551658 times.
|
1970634 | if (bit_size > 0) |
| 542 | 1418976 | put_bits(&s->pb, bit_size, bits); | |
| 543 | } | ||
| 544 | 3339596 | } | |
| 545 | |||
| 546 | 3476150 | static inline void encode_dc(MPVEncContext *const s, int diff, int component) | |
| 547 | { | ||
| 548 | 3476150 | unsigned int diff_u = diff + 255; | |
| 549 |
2/2✓ Branch 0 taken 162210 times.
✓ Branch 1 taken 3313940 times.
|
3476150 | if (diff_u >= 511) { |
| 550 | int index; | ||
| 551 | |||
| 552 |
2/2✓ Branch 0 taken 113286 times.
✓ Branch 1 taken 48924 times.
|
162210 | if (diff < 0) { |
| 553 | 113286 | index = av_log2_16bit(-2 * diff); | |
| 554 | 113286 | diff--; | |
| 555 | } else { | ||
| 556 | 48924 | index = av_log2_16bit(2 * diff); | |
| 557 | } | ||
| 558 |
2/2✓ Branch 0 taken 91380 times.
✓ Branch 1 taken 70830 times.
|
162210 | if (component == 0) |
| 559 | 91380 | put_bits(&s->pb, | |
| 560 | 91380 | ff_mpeg12_vlc_dc_lum_bits[index] + index, | |
| 561 | 91380 | (ff_mpeg12_vlc_dc_lum_code[index] << index) + | |
| 562 | 91380 | av_zero_extend(diff, index)); | |
| 563 | else | ||
| 564 | 70830 | put_bits(&s->pb, | |
| 565 | 70830 | ff_mpeg12_vlc_dc_chroma_bits[index] + index, | |
| 566 | 70830 | (ff_mpeg12_vlc_dc_chroma_code[index] << index) + | |
| 567 | 70830 | av_zero_extend(diff, index)); | |
| 568 | } else { | ||
| 569 |
2/2✓ Branch 0 taken 1832372 times.
✓ Branch 1 taken 1481568 times.
|
3313940 | if (component == 0) |
| 570 | 1832372 | put_bits(&s->pb, | |
| 571 | 1832372 | mpeg1_lum_dc_uni[diff + 255] & 0xFF, | |
| 572 | 1832372 | mpeg1_lum_dc_uni[diff + 255] >> 8); | |
| 573 | else | ||
| 574 | 1481568 | put_bits(&s->pb, | |
| 575 | 1481568 | mpeg1_chr_dc_uni[diff + 255] & 0xFF, | |
| 576 | 1481568 | mpeg1_chr_dc_uni[diff + 255] >> 8); | |
| 577 | } | ||
| 578 | 3476150 | } | |
| 579 | |||
| 580 | 7053593 | static void mpeg1_encode_block(MPVEncContext *const s, const int16_t block[], int n) | |
| 581 | { | ||
| 582 | int alevel, level, last_non_zero, dc, diff, i, j, run, last_index, sign; | ||
| 583 | int code, component; | ||
| 584 | 7053593 | const uint16_t (*table_vlc)[2] = ff_mpeg1_vlc_table; | |
| 585 | |||
| 586 | 7053593 | last_index = s->c.block_last_index[n]; | |
| 587 | |||
| 588 | /* DC coef */ | ||
| 589 |
2/2✓ Branch 0 taken 3476150 times.
✓ Branch 1 taken 3577443 times.
|
7053593 | if (s->c.mb_intra) { |
| 590 |
2/2✓ Branch 0 taken 1552398 times.
✓ Branch 1 taken 1923752 times.
|
3476150 | component = (n <= 3 ? 0 : (n & 1) + 1); |
| 591 | 3476150 | dc = block[0]; /* overflow is impossible */ | |
| 592 | 3476150 | diff = dc - s->last_dc[component]; | |
| 593 | 3476150 | encode_dc(s, diff, component); | |
| 594 | 3476150 | s->last_dc[component] = dc; | |
| 595 | 3476150 | i = 1; | |
| 596 |
2/2✓ Branch 0 taken 2641700 times.
✓ Branch 1 taken 834450 times.
|
3476150 | if (s->c.intra_vlc_format) |
| 597 | 2641700 | table_vlc = ff_mpeg2_vlc_table; | |
| 598 | } else { | ||
| 599 | /* encode the first coefficient: needs to be done here because | ||
| 600 | * it is handled slightly differently */ | ||
| 601 | 3577443 | level = block[0]; | |
| 602 |
2/2✓ Branch 0 taken 1068623 times.
✓ Branch 1 taken 2508820 times.
|
3577443 | if (abs(level) == 1) { |
| 603 | 1068623 | code = ((uint32_t)level >> 31); /* the sign bit */ | |
| 604 | 1068623 | put_bits(&s->pb, 2, code | 0x02); | |
| 605 | 1068623 | i = 1; | |
| 606 | } else { | ||
| 607 | 2508820 | i = 0; | |
| 608 | 2508820 | last_non_zero = -1; | |
| 609 | 2508820 | goto next_coef; | |
| 610 | } | ||
| 611 | } | ||
| 612 | |||
| 613 | /* now quantify & encode AC coefs */ | ||
| 614 | 4544773 | last_non_zero = i - 1; | |
| 615 | |||
| 616 |
2/2✓ Branch 0 taken 164307324 times.
✓ Branch 1 taken 7053593 times.
|
171360917 | for (; i <= last_index; i++) { |
| 617 | 164307324 | j = s->c.intra_scantable.permutated[i]; | |
| 618 | 164307324 | level = block[j]; | |
| 619 | |||
| 620 | 166816144 | next_coef: | |
| 621 | /* encode using VLC */ | ||
| 622 |
2/2✓ Branch 0 taken 68979402 times.
✓ Branch 1 taken 97836742 times.
|
166816144 | if (level != 0) { |
| 623 | 68979402 | run = i - last_non_zero - 1; | |
| 624 | |||
| 625 | 68979402 | alevel = level; | |
| 626 | 68979402 | MASK_ABS(sign, alevel); | |
| 627 | 68979402 | sign &= 1; | |
| 628 | |||
| 629 |
2/2✓ Branch 0 taken 66783108 times.
✓ Branch 1 taken 2196294 times.
|
68979402 | if (alevel <= mpeg12_max_level[run]) { |
| 630 | 66783108 | code = mpeg12_index_run[run] + alevel - 1; | |
| 631 | /* store the VLC & sign at once */ | ||
| 632 | 66783108 | put_bits(&s->pb, table_vlc[code][1] + 1, | |
| 633 | 66783108 | (table_vlc[code][0] << 1) + sign); | |
| 634 | } else { | ||
| 635 | /* Escape seems to be pretty rare <5% so I do not optimize it. | ||
| 636 | * The following encodes run together with the common escape | ||
| 637 | * value of both tables 000001b. */ | ||
| 638 | 2196294 | put_bits(&s->pb, 6 + 6, 0x01 << 6 | run); | |
| 639 | /* escape: only clip in this case */ | ||
| 640 |
2/2✓ Branch 0 taken 82680 times.
✓ Branch 1 taken 2113614 times.
|
2196294 | if (s->c.codec_id == AV_CODEC_ID_MPEG1VIDEO) { |
| 641 |
1/2✓ Branch 0 taken 82680 times.
✗ Branch 1 not taken.
|
82680 | if (alevel < 128) { |
| 642 | 82680 | put_sbits(&s->pb, 8, level); | |
| 643 | } else { | ||
| 644 | ✗ | if (level < 0) | |
| 645 | ✗ | put_bits(&s->pb, 16, 0x8001 + level + 255); | |
| 646 | else | ||
| 647 | ✗ | put_sbits(&s->pb, 16, level); | |
| 648 | } | ||
| 649 | } else { | ||
| 650 | 2113614 | put_sbits(&s->pb, 12, level); | |
| 651 | } | ||
| 652 | } | ||
| 653 | 68979402 | last_non_zero = i; | |
| 654 | } | ||
| 655 | } | ||
| 656 | /* end of block */ | ||
| 657 | 7053593 | put_bits(&s->pb, table_vlc[112][1], table_vlc[112][0]); | |
| 658 | 7053593 | } | |
| 659 | |||
| 660 | 2193110 | static av_always_inline void mpeg1_encode_mb_internal(MPVEncContext *const s, | |
| 661 | const int16_t block[8][64], | ||
| 662 | int motion_x, int motion_y, | ||
| 663 | int mb_block_count, | ||
| 664 | int chroma_y_shift) | ||
| 665 | { | ||
| 666 | /* MPEG-1 is always 420. */ | ||
| 667 | #define IS_MPEG1(s) (chroma_y_shift == 1 && (s)->c.codec_id == AV_CODEC_ID_MPEG1VIDEO) | ||
| 668 | int i, cbp; | ||
| 669 | 2193110 | const int mb_x = s->c.mb_x; | |
| 670 | 2193110 | const int mb_y = s->c.mb_y; | |
| 671 |
4/4✓ Branch 0 taken 345603 times.
✓ Branch 1 taken 1847507 times.
✓ Branch 2 taken 340946 times.
✓ Branch 3 taken 4657 times.
|
2193110 | const int first_mb = mb_x == s->c.resync_mb_x && mb_y == s->c.resync_mb_y; |
| 672 | |||
| 673 | /* compute cbp */ | ||
| 674 | 2193110 | cbp = 0; | |
| 675 |
2/2✓ Branch 0 taken 14444570 times.
✓ Branch 1 taken 2193110 times.
|
16637680 | for (i = 0; i < mb_block_count; i++) |
| 676 |
2/2✓ Branch 0 taken 7053593 times.
✓ Branch 1 taken 7390977 times.
|
14444570 | if (s->c.block_last_index[i] >= 0) |
| 677 | 7053593 | cbp |= 1 << (mb_block_count - 1 - i); | |
| 678 | |||
| 679 |
6/6✓ Branch 0 taken 728550 times.
✓ Branch 1 taken 1464560 times.
✓ Branch 2 taken 703085 times.
✓ Branch 3 taken 25465 times.
✓ Branch 4 taken 682862 times.
✓ Branch 5 taken 20223 times.
|
2193110 | if (cbp == 0 && !first_mb && s->c.mv_type == MV_TYPE_16X16 && |
| 680 |
2/2✓ Branch 0 taken 25948 times.
✓ Branch 1 taken 656914 times.
|
682862 | (mb_x != s->c.mb_width - 1 || |
| 681 |
6/6✓ Branch 0 taken 24038 times.
✓ Branch 1 taken 1910 times.
✓ Branch 2 taken 22078 times.
✓ Branch 3 taken 1960 times.
✓ Branch 4 taken 552 times.
✓ Branch 5 taken 21526 times.
|
25948 | (mb_y != s->c.end_mb_y - 1 && IS_MPEG1(s))) && |
| 682 |
4/4✓ Branch 0 taken 487230 times.
✓ Branch 1 taken 170236 times.
✓ Branch 2 taken 112067 times.
✓ Branch 3 taken 375163 times.
|
657466 | ((s->c.pict_type == AV_PICTURE_TYPE_P && (motion_x | motion_y) == 0) || |
| 683 |
4/4✓ Branch 0 taken 170236 times.
✓ Branch 1 taken 112067 times.
✓ Branch 2 taken 22008 times.
✓ Branch 3 taken 148228 times.
|
282303 | (s->c.pict_type == AV_PICTURE_TYPE_B && s->c.mv_dir == s->last_mv_dir && |
| 684 | 22008 | (((s->c.mv_dir & MV_DIR_FORWARD) | |
| 685 | 20311 | ? ((s->c.mv[0][0][0] - s->c.last_mv[0][0][0]) | | |
| 686 |
4/4✓ Branch 0 taken 20311 times.
✓ Branch 1 taken 1697 times.
✓ Branch 2 taken 4342 times.
✓ Branch 3 taken 17666 times.
|
44016 | (s->c.mv[0][0][1] - s->c.last_mv[0][0][1])) : 0) | |
| 687 | 22008 | ((s->c.mv_dir & MV_DIR_BACKWARD) | |
| 688 | 21679 | ? ((s->c.mv[1][0][0] - s->c.last_mv[1][0][0]) | | |
| 689 |
2/2✓ Branch 0 taken 21679 times.
✓ Branch 1 taken 329 times.
|
22008 | (s->c.mv[1][0][1] - s->c.last_mv[1][0][1])) : 0)) == 0))) { |
| 690 | 379505 | s->mb_skip_run++; | |
| 691 | 379505 | s->c.qscale -= s->dquant; | |
| 692 | 379505 | s->misc_bits++; | |
| 693 | 379505 | s->last_bits++; | |
| 694 |
2/2✓ Branch 0 taken 375163 times.
✓ Branch 1 taken 4342 times.
|
379505 | if (s->c.pict_type == AV_PICTURE_TYPE_P) { |
| 695 | 375163 | s->c.last_mv[0][0][0] = | |
| 696 | 375163 | s->c.last_mv[0][0][1] = | |
| 697 | 375163 | s->c.last_mv[0][1][0] = | |
| 698 | 375163 | s->c.last_mv[0][1][1] = 0; | |
| 699 | } | ||
| 700 | } else { | ||
| 701 |
2/2✓ Branch 0 taken 340946 times.
✓ Branch 1 taken 1472659 times.
|
1813605 | if (first_mb) { |
| 702 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 340946 times.
|
340946 | av_assert0(s->mb_skip_run == 0); |
| 703 | 340946 | encode_mb_skip_run(s, s->c.mb_x); | |
| 704 | } else { | ||
| 705 | 1472659 | encode_mb_skip_run(s, s->mb_skip_run); | |
| 706 | } | ||
| 707 | |||
| 708 |
2/2✓ Branch 0 taken 407200 times.
✓ Branch 1 taken 1406405 times.
|
1813605 | if (s->c.pict_type == AV_PICTURE_TYPE_I) { |
| 709 |
3/4✓ Branch 0 taken 43090 times.
✓ Branch 1 taken 364110 times.
✓ Branch 2 taken 43090 times.
✗ Branch 3 not taken.
|
407200 | if (s->dquant && cbp) { |
| 710 | /* macroblock_type: macroblock_quant = 1 */ | ||
| 711 | 43090 | put_mb_modes(s, 2, 1, 0, 0); | |
| 712 | 43090 | put_qscale(s); | |
| 713 | } else { | ||
| 714 | /* macroblock_type: macroblock_quant = 0 */ | ||
| 715 | 364110 | put_mb_modes(s, 1, 1, 0, 0); | |
| 716 | 364110 | s->c.qscale -= s->dquant; | |
| 717 | } | ||
| 718 | 407200 | s->misc_bits += get_bits_diff(s); | |
| 719 | 407200 | s->i_count++; | |
| 720 |
2/2✓ Branch 0 taken 73738 times.
✓ Branch 1 taken 1332667 times.
|
1406405 | } else if (s->c.mb_intra) { |
| 721 |
3/4✓ Branch 0 taken 11835 times.
✓ Branch 1 taken 61903 times.
✓ Branch 2 taken 11835 times.
✗ Branch 3 not taken.
|
73738 | if (s->dquant && cbp) { |
| 722 | 11835 | put_mb_modes(s, 6, 0x01, 0, 0); | |
| 723 | 11835 | put_qscale(s); | |
| 724 | } else { | ||
| 725 | 61903 | put_mb_modes(s, 5, 0x03, 0, 0); | |
| 726 | 61903 | s->c.qscale -= s->dquant; | |
| 727 | } | ||
| 728 | 73738 | s->misc_bits += get_bits_diff(s); | |
| 729 | 73738 | s->i_count++; | |
| 730 | 73738 | memset(s->c.last_mv, 0, sizeof(s->c.last_mv)); | |
| 731 |
2/2✓ Branch 0 taken 751724 times.
✓ Branch 1 taken 580943 times.
|
1332667 | } else if (s->c.pict_type == AV_PICTURE_TYPE_P) { |
| 732 |
2/2✓ Branch 0 taken 728875 times.
✓ Branch 1 taken 22849 times.
|
751724 | if (s->c.mv_type == MV_TYPE_16X16) { |
| 733 |
2/2✓ Branch 0 taken 575986 times.
✓ Branch 1 taken 152889 times.
|
728875 | if (cbp != 0) { |
| 734 |
2/2✓ Branch 0 taken 63739 times.
✓ Branch 1 taken 512247 times.
|
575986 | if ((motion_x | motion_y) == 0) { |
| 735 |
2/2✓ Branch 0 taken 1554 times.
✓ Branch 1 taken 62185 times.
|
63739 | if (s->dquant) { |
| 736 | /* macroblock_pattern & quant */ | ||
| 737 | 1554 | put_mb_modes(s, 5, 1, 0, 0); | |
| 738 | 1554 | put_qscale(s); | |
| 739 | } else { | ||
| 740 | /* macroblock_pattern only */ | ||
| 741 | 62185 | put_mb_modes(s, 2, 1, 0, 0); | |
| 742 | } | ||
| 743 | 63739 | s->misc_bits += get_bits_diff(s); | |
| 744 | } else { | ||
| 745 |
2/2✓ Branch 0 taken 72389 times.
✓ Branch 1 taken 439858 times.
|
512247 | if (s->dquant) { |
| 746 | 72389 | put_mb_modes(s, 5, 2, 1, 0); /* motion + cbp */ | |
| 747 | 72389 | put_qscale(s); | |
| 748 | } else { | ||
| 749 | 439858 | put_mb_modes(s, 1, 1, 1, 0); /* motion + cbp */ | |
| 750 | } | ||
| 751 | 512247 | s->misc_bits += get_bits_diff(s); | |
| 752 | // RAL: f_code parameter added | ||
| 753 | 512247 | mpeg1_encode_motion(s, | |
| 754 | 512247 | motion_x - s->c.last_mv[0][0][0], | |
| 755 | s->f_code); | ||
| 756 | // RAL: f_code parameter added | ||
| 757 | 512247 | mpeg1_encode_motion(s, | |
| 758 | 512247 | motion_y - s->c.last_mv[0][0][1], | |
| 759 | s->f_code); | ||
| 760 | 512247 | s->mv_bits += get_bits_diff(s); | |
| 761 | } | ||
| 762 | } else { | ||
| 763 | 152889 | put_bits(&s->pb, 3, 1); /* motion only */ | |
| 764 |
2/2✓ Branch 0 taken 24679 times.
✓ Branch 1 taken 128210 times.
|
152889 | if (!s->c.frame_pred_frame_dct) |
| 765 | 24679 | put_bits(&s->pb, 2, 2); /* motion_type: frame */ | |
| 766 | 152889 | s->misc_bits += get_bits_diff(s); | |
| 767 | // RAL: f_code parameter added | ||
| 768 | 152889 | mpeg1_encode_motion(s, | |
| 769 | 152889 | motion_x - s->c.last_mv[0][0][0], | |
| 770 | s->f_code); | ||
| 771 | // RAL: f_code parameter added | ||
| 772 | 152889 | mpeg1_encode_motion(s, | |
| 773 | 152889 | motion_y - s->c.last_mv[0][0][1], | |
| 774 | s->f_code); | ||
| 775 | 152889 | s->c.qscale -= s->dquant; | |
| 776 | 152889 | s->mv_bits += get_bits_diff(s); | |
| 777 | } | ||
| 778 | 728875 | s->c.last_mv[0][1][0] = s->c.last_mv[0][0][0] = motion_x; | |
| 779 | 728875 | s->c.last_mv[0][1][1] = s->c.last_mv[0][0][1] = motion_y; | |
| 780 | } else { | ||
| 781 | av_assert2(!s->c.frame_pred_frame_dct && s->c.mv_type == MV_TYPE_FIELD); | ||
| 782 | |||
| 783 |
2/2✓ Branch 0 taken 21344 times.
✓ Branch 1 taken 1505 times.
|
22849 | if (cbp) { |
| 784 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21344 times.
|
21344 | if (s->dquant) { |
| 785 | ✗ | put_mb_modes(s, 5, 2, 1, 1); /* motion + cbp */ | |
| 786 | ✗ | put_qscale(s); | |
| 787 | } else { | ||
| 788 | 21344 | put_mb_modes(s, 1, 1, 1, 1); /* motion + cbp */ | |
| 789 | } | ||
| 790 | } else { | ||
| 791 | 1505 | put_bits(&s->pb, 3, 1); /* motion only */ | |
| 792 | 1505 | put_bits(&s->pb, 2, 1); /* motion_type: field */ | |
| 793 | 1505 | s->c.qscale -= s->dquant; | |
| 794 | } | ||
| 795 | 22849 | s->misc_bits += get_bits_diff(s); | |
| 796 |
2/2✓ Branch 0 taken 45698 times.
✓ Branch 1 taken 22849 times.
|
68547 | for (i = 0; i < 2; i++) { |
| 797 | 45698 | put_bits(&s->pb, 1, s->c.field_select[0][i]); | |
| 798 | 45698 | mpeg1_encode_motion(s, | |
| 799 | 45698 | s->c.mv[0][i][0] - s->c.last_mv[0][i][0], | |
| 800 | s->f_code); | ||
| 801 | 45698 | mpeg1_encode_motion(s, | |
| 802 | 45698 | s->c.mv[0][i][1] - (s->c.last_mv[0][i][1] >> 1), | |
| 803 | s->f_code); | ||
| 804 | 45698 | s->c.last_mv[0][i][0] = s->c.mv[0][i][0]; | |
| 805 | 45698 | s->c.last_mv[0][i][1] = 2 * s->c.mv[0][i][1]; | |
| 806 | } | ||
| 807 | 22849 | s->mv_bits += get_bits_diff(s); | |
| 808 | } | ||
| 809 |
2/2✓ Branch 0 taken 597330 times.
✓ Branch 1 taken 154394 times.
|
751724 | if (cbp) { |
| 810 |
2/2✓ Branch 0 taken 522518 times.
✓ Branch 1 taken 74812 times.
|
597330 | if (chroma_y_shift) { |
| 811 | 522518 | put_bits(&s->pb, | |
| 812 | 522518 | ff_mpeg12_mbPatTable[cbp][1], | |
| 813 | 522518 | ff_mpeg12_mbPatTable[cbp][0]); | |
| 814 | } else { | ||
| 815 | 74812 | put_bits(&s->pb, | |
| 816 | 74812 | ff_mpeg12_mbPatTable[cbp >> 2][1], | |
| 817 | 74812 | ff_mpeg12_mbPatTable[cbp >> 2][0]); | |
| 818 | 74812 | put_sbits(&s->pb, 2, cbp); | |
| 819 | } | ||
| 820 | } | ||
| 821 | } else { | ||
| 822 |
2/2✓ Branch 0 taken 488110 times.
✓ Branch 1 taken 92833 times.
|
580943 | if (s->c.mv_type == MV_TYPE_16X16) { |
| 823 |
2/2✓ Branch 0 taken 312597 times.
✓ Branch 1 taken 175513 times.
|
488110 | if (cbp) { // With coded bloc pattern |
| 824 |
2/2✓ Branch 0 taken 53290 times.
✓ Branch 1 taken 259307 times.
|
312597 | if (s->dquant) { |
| 825 |
2/2✓ Branch 0 taken 11218 times.
✓ Branch 1 taken 42072 times.
|
53290 | if (s->c.mv_dir == MV_DIR_FORWARD) |
| 826 | 11218 | put_mb_modes(s, 6, 3, 1, 0); | |
| 827 | else | ||
| 828 | 42072 | put_mb_modes(s, 8 - s->c.mv_dir, 2, 1, 0); | |
| 829 | 53290 | put_qscale(s); | |
| 830 | } else { | ||
| 831 | 259307 | put_mb_modes(s, 5 - s->c.mv_dir, 3, 1, 0); | |
| 832 | } | ||
| 833 | } else { // No coded bloc pattern | ||
| 834 | 175513 | put_bits(&s->pb, 5 - s->c.mv_dir, 2); | |
| 835 |
2/2✓ Branch 0 taken 82021 times.
✓ Branch 1 taken 93492 times.
|
175513 | if (!s->c.frame_pred_frame_dct) |
| 836 | 82021 | put_bits(&s->pb, 2, 2); /* motion_type: frame */ | |
| 837 | 175513 | s->c.qscale -= s->dquant; | |
| 838 | } | ||
| 839 | 488110 | s->misc_bits += get_bits_diff(s); | |
| 840 |
2/2✓ Branch 0 taken 351301 times.
✓ Branch 1 taken 136809 times.
|
488110 | if (s->c.mv_dir & MV_DIR_FORWARD) { |
| 841 | 351301 | mpeg1_encode_motion(s, | |
| 842 | 351301 | s->c.mv[0][0][0] - s->c.last_mv[0][0][0], | |
| 843 | s->f_code); | ||
| 844 | 351301 | mpeg1_encode_motion(s, | |
| 845 | 351301 | s->c.mv[0][0][1] - s->c.last_mv[0][0][1], | |
| 846 | s->f_code); | ||
| 847 | 351301 | s->c.last_mv[0][0][0] = | |
| 848 | 351301 | s->c.last_mv[0][1][0] = s->c.mv[0][0][0]; | |
| 849 | 351301 | s->c.last_mv[0][0][1] = | |
| 850 | 351301 | s->c.last_mv[0][1][1] = s->c.mv[0][0][1]; | |
| 851 | } | ||
| 852 |
2/2✓ Branch 0 taken 369943 times.
✓ Branch 1 taken 118167 times.
|
488110 | if (s->c.mv_dir & MV_DIR_BACKWARD) { |
| 853 | 369943 | mpeg1_encode_motion(s, | |
| 854 | 369943 | s->c.mv[1][0][0] - s->c.last_mv[1][0][0], | |
| 855 | s->b_code); | ||
| 856 | 369943 | mpeg1_encode_motion(s, | |
| 857 | 369943 | s->c.mv[1][0][1] - s->c.last_mv[1][0][1], | |
| 858 | s->b_code); | ||
| 859 | 369943 | s->c.last_mv[1][0][0] = | |
| 860 | 369943 | s->c.last_mv[1][1][0] = s->c.mv[1][0][0]; | |
| 861 | 369943 | s->c.last_mv[1][0][1] = | |
| 862 | 369943 | s->c.last_mv[1][1][1] = s->c.mv[1][0][1]; | |
| 863 | } | ||
| 864 | } else { | ||
| 865 | av_assert2(s->c.mv_type == MV_TYPE_FIELD); | ||
| 866 | av_assert2(!s->c.frame_pred_frame_dct); | ||
| 867 |
2/2✓ Branch 0 taken 73695 times.
✓ Branch 1 taken 19138 times.
|
92833 | if (cbp) { // With coded bloc pattern |
| 868 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 73695 times.
|
73695 | if (s->dquant) { |
| 869 | ✗ | if (s->c.mv_dir == MV_DIR_FORWARD) | |
| 870 | ✗ | put_mb_modes(s, 6, 3, 1, 1); | |
| 871 | else | ||
| 872 | ✗ | put_mb_modes(s, 8 - s->c.mv_dir, 2, 1, 1); | |
| 873 | ✗ | put_qscale(s); | |
| 874 | } else { | ||
| 875 | 73695 | put_mb_modes(s, 5 - s->c.mv_dir, 3, 1, 1); | |
| 876 | } | ||
| 877 | } else { // No coded bloc pattern | ||
| 878 | 19138 | put_bits(&s->pb, 5 - s->c.mv_dir, 2); | |
| 879 | 19138 | put_bits(&s->pb, 2, 1); /* motion_type: field */ | |
| 880 | 19138 | s->c.qscale -= s->dquant; | |
| 881 | } | ||
| 882 | 92833 | s->misc_bits += get_bits_diff(s); | |
| 883 |
2/2✓ Branch 0 taken 59191 times.
✓ Branch 1 taken 33642 times.
|
92833 | if (s->c.mv_dir & MV_DIR_FORWARD) { |
| 884 |
2/2✓ Branch 0 taken 118382 times.
✓ Branch 1 taken 59191 times.
|
177573 | for (i = 0; i < 2; i++) { |
| 885 | 118382 | put_bits(&s->pb, 1, s->c.field_select[0][i]); | |
| 886 | 118382 | mpeg1_encode_motion(s, | |
| 887 | 118382 | s->c.mv[0][i][0] - s->c.last_mv[0][i][0], | |
| 888 | s->f_code); | ||
| 889 | 118382 | mpeg1_encode_motion(s, | |
| 890 | 118382 | s->c.mv[0][i][1] - (s->c.last_mv[0][i][1] >> 1), | |
| 891 | s->f_code); | ||
| 892 | 118382 | s->c.last_mv[0][i][0] = s->c.mv[0][i][0]; | |
| 893 | 118382 | s->c.last_mv[0][i][1] = s->c.mv[0][i][1] * 2; | |
| 894 | } | ||
| 895 | } | ||
| 896 |
2/2✓ Branch 0 taken 59669 times.
✓ Branch 1 taken 33164 times.
|
92833 | if (s->c.mv_dir & MV_DIR_BACKWARD) { |
| 897 |
2/2✓ Branch 0 taken 119338 times.
✓ Branch 1 taken 59669 times.
|
179007 | for (i = 0; i < 2; i++) { |
| 898 | 119338 | put_bits(&s->pb, 1, s->c.field_select[1][i]); | |
| 899 | 119338 | mpeg1_encode_motion(s, | |
| 900 | 119338 | s->c.mv[1][i][0] - s->c.last_mv[1][i][0], | |
| 901 | s->b_code); | ||
| 902 | 119338 | mpeg1_encode_motion(s, | |
| 903 | 119338 | s->c.mv[1][i][1] - (s->c.last_mv[1][i][1] >> 1), | |
| 904 | s->b_code); | ||
| 905 | 119338 | s->c.last_mv[1][i][0] = s->c.mv[1][i][0]; | |
| 906 | 119338 | s->c.last_mv[1][i][1] = s->c.mv[1][i][1] * 2; | |
| 907 | } | ||
| 908 | } | ||
| 909 | } | ||
| 910 | 580943 | s->mv_bits += get_bits_diff(s); | |
| 911 |
2/2✓ Branch 0 taken 386292 times.
✓ Branch 1 taken 194651 times.
|
580943 | if (cbp) { |
| 912 |
2/2✓ Branch 0 taken 206130 times.
✓ Branch 1 taken 180162 times.
|
386292 | if (chroma_y_shift) { |
| 913 | 206130 | put_bits(&s->pb, | |
| 914 | 206130 | ff_mpeg12_mbPatTable[cbp][1], | |
| 915 | 206130 | ff_mpeg12_mbPatTable[cbp][0]); | |
| 916 | } else { | ||
| 917 | 180162 | put_bits(&s->pb, | |
| 918 | 180162 | ff_mpeg12_mbPatTable[cbp >> 2][1], | |
| 919 | 180162 | ff_mpeg12_mbPatTable[cbp >> 2][0]); | |
| 920 | 180162 | put_sbits(&s->pb, 2, cbp); | |
| 921 | } | ||
| 922 | } | ||
| 923 | } | ||
| 924 |
2/2✓ Branch 0 taken 12166244 times.
✓ Branch 1 taken 1813605 times.
|
13979849 | for (i = 0; i < mb_block_count; i++) |
| 925 |
2/2✓ Branch 0 taken 7053593 times.
✓ Branch 1 taken 5112651 times.
|
12166244 | if (cbp & (1 << (mb_block_count - 1 - i))) |
| 926 | 7053593 | mpeg1_encode_block(s, block[i], i); | |
| 927 | 1813605 | s->mb_skip_run = 0; | |
| 928 |
2/2✓ Branch 0 taken 480938 times.
✓ Branch 1 taken 1332667 times.
|
1813605 | if (s->c.mb_intra) |
| 929 | 480938 | s->i_tex_bits += get_bits_diff(s); | |
| 930 | else | ||
| 931 | 1332667 | s->p_tex_bits += get_bits_diff(s); | |
| 932 | } | ||
| 933 | 2193110 | } | |
| 934 | |||
| 935 | 2193110 | static void mpeg12_encode_mb(MPVEncContext *const s, int16_t block[][64], | |
| 936 | int motion_x, int motion_y) | ||
| 937 | { | ||
| 938 |
2/2✓ Branch 0 taken 1712172 times.
✓ Branch 1 taken 480938 times.
|
2193110 | if (!s->c.mb_intra) |
| 939 | 1712172 | s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 128 << s->c.intra_dc_precision; | |
| 940 |
2/2✓ Branch 0 taken 1550155 times.
✓ Branch 1 taken 642955 times.
|
2193110 | if (s->c.chroma_format == CHROMA_420) |
| 941 | 1550155 | mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 6, 1); | |
| 942 | else | ||
| 943 | 642955 | mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 8, 0); | |
| 944 | 2193110 | } | |
| 945 | |||
| 946 | 58 | static av_cold void mpeg12_encode_init_static(void) | |
| 947 | { | ||
| 948 | 58 | ff_rl_init_level_run(mpeg12_max_level, mpeg12_index_run, | |
| 949 | ff_mpeg12_run, ff_mpeg12_level, MPEG12_RL_NB_ELEMS); | ||
| 950 | |||
| 951 | 58 | ff_mpeg1_init_uni_ac_vlc(mpeg12_max_level, mpeg12_index_run, | |
| 952 | ff_mpeg1_vlc_table, uni_mpeg1_ac_vlc_len); | ||
| 953 | 58 | ff_mpeg1_init_uni_ac_vlc(mpeg12_max_level, mpeg12_index_run, | |
| 954 | ff_mpeg2_vlc_table, uni_mpeg2_ac_vlc_len); | ||
| 955 | |||
| 956 | /* build unified dc encoding tables */ | ||
| 957 |
2/2✓ Branch 0 taken 29638 times.
✓ Branch 1 taken 58 times.
|
29696 | for (int i = -255; i < 256; i++) { |
| 958 | int adiff, index; | ||
| 959 | int bits, code; | ||
| 960 | 29638 | int diff = i; | |
| 961 | |||
| 962 | 29638 | adiff = FFABS(diff); | |
| 963 |
2/2✓ Branch 0 taken 14790 times.
✓ Branch 1 taken 14848 times.
|
29638 | if (diff < 0) |
| 964 | 14790 | diff--; | |
| 965 | 29638 | index = av_log2(2 * adiff); | |
| 966 | |||
| 967 | 29638 | bits = ff_mpeg12_vlc_dc_lum_bits[index] + index; | |
| 968 | 29638 | code = (ff_mpeg12_vlc_dc_lum_code[index] << index) + | |
| 969 | 29638 | av_zero_extend(diff, index); | |
| 970 | 29638 | mpeg1_lum_dc_uni[i + 255] = bits + (code << 8); | |
| 971 | |||
| 972 | 29638 | bits = ff_mpeg12_vlc_dc_chroma_bits[index] + index; | |
| 973 | 29638 | code = (ff_mpeg12_vlc_dc_chroma_code[index] << index) + | |
| 974 | 29638 | av_zero_extend(diff, index); | |
| 975 | 29638 | mpeg1_chr_dc_uni[i + 255] = bits + (code << 8); | |
| 976 | } | ||
| 977 | |||
| 978 |
2/2✓ Branch 0 taken 406 times.
✓ Branch 1 taken 58 times.
|
464 | for (int f_code = 1; f_code <= MAX_FCODE; f_code++) |
| 979 |
2/2✓ Branch 0 taken 6652310 times.
✓ Branch 1 taken 406 times.
|
6652716 | for (int mv = -MAX_DMV; mv <= MAX_DMV; mv++) { |
| 980 | int len; | ||
| 981 | |||
| 982 |
2/2✓ Branch 0 taken 406 times.
✓ Branch 1 taken 6651904 times.
|
6652310 | if (mv == 0) { |
| 983 | 406 | len = 1; /* ff_mpeg12_mbMotionVectorTable[0][1] */ | |
| 984 | } else { | ||
| 985 | int val, bit_size, code; | ||
| 986 | |||
| 987 | 6651904 | bit_size = f_code - 1; | |
| 988 | |||
| 989 | 6651904 | val = mv; | |
| 990 |
2/2✓ Branch 0 taken 3325952 times.
✓ Branch 1 taken 3325952 times.
|
6651904 | if (val < 0) |
| 991 | 3325952 | val = -val; | |
| 992 | 6651904 | val--; | |
| 993 | 6651904 | code = (val >> bit_size) + 1; | |
| 994 |
2/2✓ Branch 0 taken 235712 times.
✓ Branch 1 taken 6416192 times.
|
6651904 | if (code < 17) |
| 995 | 235712 | len = ff_mpeg12_mbMotionVectorTable[code][1] + | |
| 996 | 1 + bit_size; | ||
| 997 | else | ||
| 998 | 6416192 | len = 10 /* ff_mpeg12_mbMotionVectorTable[16][1] */ + | |
| 999 | 2 + bit_size; | ||
| 1000 | } | ||
| 1001 | |||
| 1002 | 6652310 | mv_penalty[f_code][mv + MAX_DMV] = len; | |
| 1003 | } | ||
| 1004 | |||
| 1005 | |||
| 1006 |
2/2✓ Branch 0 taken 406 times.
✓ Branch 1 taken 58 times.
|
464 | for (int f_code = MAX_FCODE; f_code > 0; f_code--) |
| 1007 |
2/2✓ Branch 0 taken 235712 times.
✓ Branch 1 taken 406 times.
|
236118 | for (int mv = -(8 << f_code); mv < (8 << f_code); mv++) |
| 1008 | 235712 | fcode_tab[mv + MAX_MV] = f_code; | |
| 1009 | 58 | } | |
| 1010 | |||
| 1011 | 58 | static av_cold int find_frame_rate_index(AVCodecContext *avctx, MPEG12EncContext *mpeg12) | |
| 1012 | { | ||
| 1013 | 58 | AVRational bestq = (AVRational) {0, 0}; | |
| 1014 | AVRational ext; | ||
| 1015 | 58 | AVRational target = av_inv_q(avctx->time_base); | |
| 1016 | |||
| 1017 |
2/2✓ Branch 0 taken 526 times.
✓ Branch 1 taken 1 times.
|
527 | for (int i = 1; i < 14; i++) { |
| 1018 |
4/4✓ Branch 0 taken 513 times.
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 57 times.
✓ Branch 3 taken 456 times.
|
526 | if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL && |
| 1019 | i >= 9) | ||
| 1020 | 57 | break; | |
| 1021 | |||
| 1022 |
2/2✓ Branch 0 taken 1876 times.
✓ Branch 1 taken 469 times.
|
2345 | for (ext.num = 1; ext.num <= 4; ext.num++) { |
| 1023 |
2/2✓ Branch 0 taken 60032 times.
✓ Branch 1 taken 1876 times.
|
61908 | for (ext.den = 1; ext.den <= 32; ext.den++) { |
| 1024 | 60032 | AVRational q = av_mul_q(ext, ff_mpeg12_frame_rate_tab[i]); | |
| 1025 | |||
| 1026 |
6/6✓ Branch 0 taken 11264 times.
✓ Branch 1 taken 48768 times.
✓ Branch 2 taken 352 times.
✓ Branch 3 taken 10912 times.
✓ Branch 4 taken 264 times.
✓ Branch 5 taken 88 times.
|
60032 | if (avctx->codec_id != AV_CODEC_ID_MPEG2VIDEO && (ext.den!=1 || ext.num!=1)) |
| 1027 | 27178 | continue; | |
| 1028 |
2/2✓ Branch 0 taken 16002 times.
✓ Branch 1 taken 32854 times.
|
48856 | if (av_gcd(ext.den, ext.num) != 1) |
| 1029 | 16002 | continue; | |
| 1030 | |||
| 1031 |
2/2✓ Branch 0 taken 32796 times.
✓ Branch 1 taken 58 times.
|
32854 | if ( bestq.num==0 |
| 1032 |
2/2✓ Branch 1 taken 32656 times.
✓ Branch 2 taken 140 times.
|
32796 | || av_nearer_q(target, bestq, q) < 0 |
| 1033 |
5/6✓ Branch 0 taken 12092 times.
✓ Branch 1 taken 20564 times.
✓ Branch 2 taken 305 times.
✓ Branch 3 taken 11787 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 305 times.
|
32656 | || ext.num==1 && ext.den==1 && av_nearer_q(target, bestq, q) == 0) { |
| 1034 | 198 | bestq = q; | |
| 1035 | 198 | mpeg12->frame_rate_index = i; | |
| 1036 | 198 | mpeg12->frame_rate_ext.num = ext.num; | |
| 1037 | 198 | mpeg12->frame_rate_ext.den = ext.den; | |
| 1038 | } | ||
| 1039 | } | ||
| 1040 | } | ||
| 1041 | } | ||
| 1042 | |||
| 1043 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 57 times.
|
58 | if (av_cmp_q(target, bestq)) |
| 1044 | 1 | return -1; | |
| 1045 | else | ||
| 1046 | 57 | return 0; | |
| 1047 | } | ||
| 1048 | |||
| 1049 | 58 | static av_cold int encode_init(AVCodecContext *avctx) | |
| 1050 | { | ||
| 1051 | static AVOnce init_static_once = AV_ONCE_INIT; | ||
| 1052 | 58 | MPEG12EncContext *const mpeg12 = avctx->priv_data; | |
| 1053 | 58 | MPVMainEncContext *const m = &mpeg12->mpeg; | |
| 1054 | 58 | MPVEncContext *const s = &m->s; | |
| 1055 | int ret; | ||
| 1056 |
2/2✓ Branch 0 taken 47 times.
✓ Branch 1 taken 11 times.
|
58 | int max_size = avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO ? 16383 : 4095; |
| 1057 | |||
| 1058 |
2/4✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 58 times.
|
58 | if (avctx->width > max_size || avctx->height > max_size) { |
| 1059 | ✗ | av_log(avctx, AV_LOG_ERROR, "%s does not support resolutions above %dx%d\n", | |
| 1060 | ✗ | CONFIG_SMALL ? avctx->codec->name : avctx->codec->long_name, | |
| 1061 | max_size, max_size); | ||
| 1062 | ✗ | return AVERROR(EINVAL); | |
| 1063 | } | ||
| 1064 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
58 | if ((avctx->width & 0xFFF) == 0 && (avctx->height & 0xFFF) == 1) { |
| 1065 | ✗ | av_log(avctx, AV_LOG_ERROR, "Width / Height is invalid for MPEG2\n"); | |
| 1066 | ✗ | return AVERROR(EINVAL); | |
| 1067 | } | ||
| 1068 | |||
| 1069 |
2/2✓ Branch 0 taken 57 times.
✓ Branch 1 taken 1 times.
|
58 | if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) { |
| 1070 |
2/4✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 57 times.
|
57 | if ((avctx->width & 0xFFF) == 0 || (avctx->height & 0xFFF) == 0) { |
| 1071 | ✗ | av_log(avctx, AV_LOG_ERROR, "Width or Height are not allowed to be multiples of 4096\n" | |
| 1072 | "add '-strict %d' if you want to use them anyway.\n", FF_COMPLIANCE_UNOFFICIAL); | ||
| 1073 | ✗ | return AVERROR(EINVAL); | |
| 1074 | } | ||
| 1075 | } | ||
| 1076 | |||
| 1077 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 57 times.
|
58 | if (s->c.q_scale_type == 1) { |
| 1078 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (avctx->qmax > 28) { |
| 1079 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
| 1080 | "non linear quant only supports qmax <= 28 currently\n"); | ||
| 1081 | ✗ | return AVERROR_PATCHWELCOME; | |
| 1082 | } | ||
| 1083 | } | ||
| 1084 | |||
| 1085 |
1/2✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
|
58 | if (avctx->profile == AV_PROFILE_UNKNOWN) { |
| 1086 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (avctx->level != AV_LEVEL_UNKNOWN) { |
| 1087 | ✗ | av_log(avctx, AV_LOG_ERROR, "Set profile and level\n"); | |
| 1088 | ✗ | return AVERROR(EINVAL); | |
| 1089 | } | ||
| 1090 | /* Main or 4:2:2 */ | ||
| 1091 | 58 | avctx->profile = avctx->pix_fmt == AV_PIX_FMT_YUV420P ? AV_PROFILE_MPEG2_MAIN | |
| 1092 |
2/2✓ Branch 0 taken 53 times.
✓ Branch 1 taken 5 times.
|
58 | : AV_PROFILE_MPEG2_422; |
| 1093 | } | ||
| 1094 |
1/2✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
|
58 | if (avctx->level == AV_LEVEL_UNKNOWN) { |
| 1095 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 53 times.
|
58 | if (avctx->profile == AV_PROFILE_MPEG2_422) { /* 4:2:2 */ |
| 1096 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | if (avctx->width <= 720 && avctx->height <= 608) |
| 1097 | 5 | avctx->level = 5; /* Main */ | |
| 1098 | else | ||
| 1099 | ✗ | avctx->level = 2; /* High */ | |
| 1100 | } else { | ||
| 1101 |
1/2✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
|
53 | if (avctx->profile != AV_PROFILE_MPEG2_HIGH && |
| 1102 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
|
53 | avctx->pix_fmt != AV_PIX_FMT_YUV420P) { |
| 1103 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
| 1104 | "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n"); | ||
| 1105 | ✗ | return AVERROR(EINVAL); | |
| 1106 | } | ||
| 1107 |
3/4✓ Branch 0 taken 52 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
|
53 | if (avctx->width <= 720 && avctx->height <= 576) |
| 1108 | 52 | avctx->level = 8; /* Main */ | |
| 1109 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | else if (avctx->width <= 1440) |
| 1110 | 1 | avctx->level = 6; /* High 1440 */ | |
| 1111 | else | ||
| 1112 | ✗ | avctx->level = 4; /* High */ | |
| 1113 | } | ||
| 1114 | } | ||
| 1115 | |||
| 1116 | 58 | m->encode_picture_header = mpeg1_encode_picture_header; | |
| 1117 | 58 | s->encode_mb = mpeg12_encode_mb; | |
| 1118 | |||
| 1119 | 58 | s->me.mv_penalty = mv_penalty; | |
| 1120 | 58 | m->fcode_tab = fcode_tab + MAX_MV; | |
| 1121 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 47 times.
|
58 | if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) { |
| 1122 | 11 | s->min_qcoeff = -255; | |
| 1123 | 11 | s->max_qcoeff = 255; | |
| 1124 | } else { | ||
| 1125 | 47 | s->min_qcoeff = -2047; | |
| 1126 | 47 | s->max_qcoeff = 2047; | |
| 1127 | 47 | s->mpeg_quant = 1; | |
| 1128 | } | ||
| 1129 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 45 times.
|
58 | if (s->c.intra_vlc_format) { |
| 1130 | 13 | s->intra_ac_vlc_length = | |
| 1131 | 13 | s->intra_ac_vlc_last_length = uni_mpeg2_ac_vlc_len; | |
| 1132 | } else { | ||
| 1133 | 45 | s->intra_ac_vlc_length = | |
| 1134 | 45 | s->intra_ac_vlc_last_length = uni_mpeg1_ac_vlc_len; | |
| 1135 | } | ||
| 1136 | 58 | s->inter_ac_vlc_length = | |
| 1137 | 58 | s->inter_ac_vlc_last_length = uni_mpeg1_ac_vlc_len; | |
| 1138 | |||
| 1139 | 58 | ret = ff_mpv_encode_init(avctx); | |
| 1140 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (ret < 0) |
| 1141 | ✗ | return ret; | |
| 1142 | |||
| 1143 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 47 times.
|
58 | if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO && |
| 1144 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | s->c.thread_context[s->c.slice_context_count - 1]->start_mb_y > |
| 1145 | SLICE_MAX_START_CODE - SLICE_MIN_START_CODE) { | ||
| 1146 | // MPEG-1 slices must not start at a MB row number that would make | ||
| 1147 | // their start code > SLICE_MAX_START_CODE. So make the last slice | ||
| 1148 | // bigger if needed and evenly distribute the first 174 rows. | ||
| 1149 | static_assert(MAX_THREADS <= 1 + SLICE_MAX_START_CODE - SLICE_MIN_START_CODE, | ||
| 1150 | "With more than 175 slice contexts, we have to handle " | ||
| 1151 | "the case in which there is no work to do for some " | ||
| 1152 | "slice contexts."); | ||
| 1153 | ✗ | const int mb_height = SLICE_MAX_START_CODE - SLICE_MIN_START_CODE; | |
| 1154 | ✗ | const int nb_slices = s->c.slice_context_count - 1; | |
| 1155 | |||
| 1156 | ✗ | s->c.thread_context[nb_slices]->start_mb_y = mb_height; | |
| 1157 | |||
| 1158 | av_assert1(nb_slices >= 1); | ||
| 1159 | ✗ | for (int i = 0; i < nb_slices; i++) { | |
| 1160 | ✗ | s->c.thread_context[i]->start_mb_y = | |
| 1161 | ✗ | (mb_height * (i ) + nb_slices / 2) / nb_slices; | |
| 1162 | ✗ | s->c.thread_context[i]->end_mb_y = | |
| 1163 | ✗ | (mb_height * (i + 1) + nb_slices / 2) / nb_slices; | |
| 1164 | } | ||
| 1165 | } | ||
| 1166 | |||
| 1167 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 57 times.
|
58 | if (find_frame_rate_index(avctx, mpeg12) < 0) { |
| 1168 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { |
| 1169 | ✗ | av_log(avctx, AV_LOG_ERROR, "MPEG-1/2 does not support %d/%d fps\n", | |
| 1170 | avctx->time_base.den, avctx->time_base.num); | ||
| 1171 | ✗ | return AVERROR(EINVAL); | |
| 1172 | } else { | ||
| 1173 | 1 | av_log(avctx, AV_LOG_INFO, | |
| 1174 | "MPEG-1/2 does not support %d/%d fps, there may be AV sync issues\n", | ||
| 1175 | avctx->time_base.den, avctx->time_base.num); | ||
| 1176 | } | ||
| 1177 | } | ||
| 1178 | |||
| 1179 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 56 times.
|
58 | if (avctx->rc_max_rate && |
| 1180 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | avctx->rc_min_rate == avctx->rc_max_rate && |
| 1181 | 2 | 90000LL * (avctx->rc_buffer_size - 1) > | |
| 1182 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | avctx->rc_max_rate * 0xFFFFLL) { |
| 1183 | 1 | av_log(avctx, AV_LOG_INFO, | |
| 1184 | "Warning vbv_delay will be set to 0xFFFF (=VBR) as the " | ||
| 1185 | "specified vbv buffer is too large for the given bitrate!\n"); | ||
| 1186 | } | ||
| 1187 | |||
| 1188 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (mpeg12->drop_frame_timecode) |
| 1189 | ✗ | mpeg12->tc.flags |= AV_TIMECODE_FLAG_DROPFRAME; | |
| 1190 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
58 | if (mpeg12->drop_frame_timecode && mpeg12->frame_rate_index != 4) { |
| 1191 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
| 1192 | "Drop frame time code only allowed with 1001/30000 fps\n"); | ||
| 1193 | ✗ | return AVERROR(EINVAL); | |
| 1194 | } | ||
| 1195 | |||
| 1196 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 52 times.
|
58 | if (mpeg12->tc_opt_str) { |
| 1197 | 6 | AVRational rate = ff_mpeg12_frame_rate_tab[mpeg12->frame_rate_index]; | |
| 1198 | 6 | int ret = av_timecode_init_from_string(&mpeg12->tc, rate, mpeg12->tc_opt_str, avctx); | |
| 1199 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (ret < 0) |
| 1200 | ✗ | return ret; | |
| 1201 | 6 | mpeg12->drop_frame_timecode = !!(mpeg12->tc.flags & AV_TIMECODE_FLAG_DROPFRAME); | |
| 1202 | 6 | mpeg12->timecode_frame_start = mpeg12->tc.start; | |
| 1203 | } else { | ||
| 1204 | 52 | mpeg12->timecode_frame_start = 0; // default is -1 | |
| 1205 | } | ||
| 1206 | |||
| 1207 | 58 | ff_thread_once(&init_static_once, mpeg12_encode_init_static); | |
| 1208 | |||
| 1209 | 58 | return 0; | |
| 1210 | } | ||
| 1211 | |||
| 1212 | #define OFFSET(x) offsetof(MPEG12EncContext, x) | ||
| 1213 | #define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM | ||
| 1214 | #define COMMON_OPTS \ | ||
| 1215 | { "gop_timecode", "MPEG GOP Timecode in hh:mm:ss[:;.]ff format. Overrides timecode_frame_start.", \ | ||
| 1216 | OFFSET(tc_opt_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE },\ | ||
| 1217 | { "drop_frame_timecode", "Timecode is in drop frame format.", \ | ||
| 1218 | OFFSET(drop_frame_timecode), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, \ | ||
| 1219 | { "scan_offset", "Reserve space for SVCD scan offset user data.", \ | ||
| 1220 | OFFSET(scan_offset), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, \ | ||
| 1221 | { "timecode_frame_start", "GOP timecode frame start number, in non-drop-frame format", \ | ||
| 1222 | OFFSET(timecode_frame_start), AV_OPT_TYPE_INT64, {.i64 = -1 }, -1, INT64_MAX, VE}, \ | ||
| 1223 | FF_MPV_COMMON_BFRAME_OPTS | ||
| 1224 | |||
| 1225 | static const AVOption mpeg1_options[] = { | ||
| 1226 | COMMON_OPTS | ||
| 1227 | FF_MPV_COMMON_OPTS | ||
| 1228 | FF_MPV_COMMON_MOTION_EST_OPTS | ||
| 1229 | { NULL }, | ||
| 1230 | }; | ||
| 1231 | |||
| 1232 | static const AVOption mpeg2_options[] = { | ||
| 1233 | COMMON_OPTS | ||
| 1234 | { "intra_vlc", "Use MPEG-2 intra VLC table.", | ||
| 1235 | FF_MPV_OFFSET(c.intra_vlc_format), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, | ||
| 1236 | { "non_linear_quant", "Use nonlinear quantizer.", FF_MPV_OFFSET(c.q_scale_type), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, | ||
| 1237 | { "alternate_scan", "Enable alternate scantable.", FF_MPV_OFFSET(c.alternate_scan), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, | ||
| 1238 | { "a53cc", "Use A53 Closed Captions (if available)", OFFSET(a53_cc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE }, | ||
| 1239 | { "seq_disp_ext", "Write sequence_display_extension blocks.", OFFSET(seq_disp_ext), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE, .unit = "seq_disp_ext" }, | ||
| 1240 | { "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, VE, .unit = "seq_disp_ext" }, | ||
| 1241 | { "never", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, 0, 0, VE, .unit = "seq_disp_ext" }, | ||
| 1242 | { "always", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0, VE, .unit = "seq_disp_ext" }, | ||
| 1243 | { "video_format", "Video_format in the sequence_display_extension indicating the source of the video.", OFFSET(video_format), AV_OPT_TYPE_INT, { .i64 = VIDEO_FORMAT_UNSPECIFIED }, 0, 7, VE, .unit = "video_format" }, | ||
| 1244 | { "component", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VIDEO_FORMAT_COMPONENT }, 0, 0, VE, .unit = "video_format" }, | ||
| 1245 | { "pal", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VIDEO_FORMAT_PAL }, 0, 0, VE, .unit = "video_format" }, | ||
| 1246 | { "ntsc", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VIDEO_FORMAT_NTSC }, 0, 0, VE, .unit = "video_format" }, | ||
| 1247 | { "secam", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VIDEO_FORMAT_SECAM }, 0, 0, VE, .unit = "video_format" }, | ||
| 1248 | { "mac", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VIDEO_FORMAT_MAC }, 0, 0, VE, .unit = "video_format" }, | ||
| 1249 | { "unspecified", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VIDEO_FORMAT_UNSPECIFIED}, 0, 0, VE, .unit = "video_format" }, | ||
| 1250 | #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, { .i64 = value }, 0, 0, VE, .unit = "avctx.level" | ||
| 1251 | { LEVEL("high", 4) }, | ||
| 1252 | { LEVEL("high1440", 6) }, | ||
| 1253 | { LEVEL("main", 8) }, | ||
| 1254 | { LEVEL("low", 10) }, | ||
| 1255 | #undef LEVEL | ||
| 1256 | FF_MPV_COMMON_OPTS | ||
| 1257 | FF_MPV_COMMON_MOTION_EST_OPTS | ||
| 1258 | FF_MPEG2_PROFILE_OPTS | ||
| 1259 | { NULL }, | ||
| 1260 | }; | ||
| 1261 | |||
| 1262 | #define mpeg12_class(x) \ | ||
| 1263 | static const AVClass mpeg ## x ## _class = { \ | ||
| 1264 | .class_name = "mpeg" # x "video encoder", \ | ||
| 1265 | .item_name = av_default_item_name, \ | ||
| 1266 | .option = mpeg ## x ## _options, \ | ||
| 1267 | .version = LIBAVUTIL_VERSION_INT, \ | ||
| 1268 | }; | ||
| 1269 | |||
| 1270 | mpeg12_class(1) | ||
| 1271 | mpeg12_class(2) | ||
| 1272 | |||
| 1273 | const FFCodec ff_mpeg1video_encoder = { | ||
| 1274 | .p.name = "mpeg1video", | ||
| 1275 | CODEC_LONG_NAME("MPEG-1 video"), | ||
| 1276 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
| 1277 | .p.id = AV_CODEC_ID_MPEG1VIDEO, | ||
| 1278 | .priv_data_size = sizeof(MPEG12EncContext), | ||
| 1279 | .init = encode_init, | ||
| 1280 | FF_CODEC_ENCODE_CB(ff_mpv_encode_picture), | ||
| 1281 | .close = ff_mpv_encode_end, | ||
| 1282 | CODEC_FRAMERATES_ARRAY(ff_mpeg12_frame_rate_tab + 1), | ||
| 1283 | CODEC_PIXFMTS(AV_PIX_FMT_YUV420P), | ||
| 1284 | .color_ranges = AVCOL_RANGE_MPEG, | ||
| 1285 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | | ||
| 1286 | AV_CODEC_CAP_SLICE_THREADS | | ||
| 1287 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, | ||
| 1288 | .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, | ||
| 1289 | .p.priv_class = &mpeg1_class, | ||
| 1290 | }; | ||
| 1291 | |||
| 1292 | const FFCodec ff_mpeg2video_encoder = { | ||
| 1293 | .p.name = "mpeg2video", | ||
| 1294 | CODEC_LONG_NAME("MPEG-2 video"), | ||
| 1295 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
| 1296 | .p.id = AV_CODEC_ID_MPEG2VIDEO, | ||
| 1297 | .priv_data_size = sizeof(MPEG12EncContext), | ||
| 1298 | .init = encode_init, | ||
| 1299 | FF_CODEC_ENCODE_CB(ff_mpv_encode_picture), | ||
| 1300 | .close = ff_mpv_encode_end, | ||
| 1301 | CODEC_FRAMERATES_ARRAY(ff_mpeg2_frame_rate_tab), | ||
| 1302 | CODEC_PIXFMTS(AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P), | ||
| 1303 | .color_ranges = AVCOL_RANGE_MPEG, | ||
| 1304 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | | ||
| 1305 | AV_CODEC_CAP_SLICE_THREADS | | ||
| 1306 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, | ||
| 1307 | .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, | ||
| 1308 | .p.priv_class = &mpeg2_class, | ||
| 1309 | }; | ||
| 1310 | #endif /* CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER */ | ||
| 1311 |