]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mpeg12enc.c
avformat/audiointerleave: only keep the retime functionality of the audio interleaver
[ffmpeg] / libavcodec / mpeg12enc.c
index d0b458e34bdb492992358d0b6465f885e08f556b..643ba8165a97a9c3a85be7ad105c93710c6b3494 100644 (file)
@@ -61,6 +61,8 @@ static uint32_t mpeg1_chr_dc_uni[512];
 static uint8_t mpeg1_index_run[2][64];
 static int8_t  mpeg1_max_level[2][64];
 
+#define A53_MAX_CC_COUNT 0x1f
+
 static av_cold void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len)
 {
     int i;
@@ -160,17 +162,17 @@ static av_cold int encode_init(AVCodecContext *avctx)
             return -1;
         }
         /* Main or 4:2:2 */
-        avctx->profile = s->chroma_format == CHROMA_420 ? 4 : 0;
+        avctx->profile = s->chroma_format == CHROMA_420 ? FF_PROFILE_MPEG2_MAIN : FF_PROFILE_MPEG2_422;
     }
 
     if (avctx->level == FF_LEVEL_UNKNOWN) {
-        if (avctx->profile == 0) {                  /* 4:2:2 */
+        if (avctx->profile == FF_PROFILE_MPEG2_422) {   /* 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) {
+            if (avctx->profile != FF_PROFILE_MPEG2_HIGH && 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;
@@ -319,7 +321,7 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
             put_header(s, EXT_START_CODE);
             put_bits(&s->pb, 4, 1);                 // seq ext
 
-            put_bits(&s->pb, 1, s->avctx->profile == 0); // escx 1 for 4:2:2 profile
+            put_bits(&s->pb, 1, s->avctx->profile == FF_PROFILE_MPEG2_422); // escx 1 for 4:2:2 profile
 
             put_bits(&s->pb, 3, s->avctx->profile); // profile
             put_bits(&s->pb, 4, s->avctx->level);   // level
@@ -544,6 +546,36 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
         }
     }
 
+    if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->a53_cc) {
+        side_data = av_frame_get_side_data(s->current_picture_ptr->f,
+            AV_FRAME_DATA_A53_CC);
+        if (side_data) {
+            if (side_data->size <= A53_MAX_CC_COUNT * 3 && side_data->size % 3 == 0) {
+                int i = 0;
+
+                put_header (s, USER_START_CODE);
+
+                put_bits(&s->pb, 8, 'G');                   // user_identifier
+                put_bits(&s->pb, 8, 'A');
+                put_bits(&s->pb, 8, '9');
+                put_bits(&s->pb, 8, '4');
+                put_bits(&s->pb, 8, 3);                     // user_data_type_code
+                put_bits(&s->pb, 8,
+                    (side_data->size / 3 & A53_MAX_CC_COUNT) | 0x40); // flags, cc_count
+                put_bits(&s->pb, 8, 0xff);                  // em_data
+
+                for (i = 0; i < side_data->size; i++)
+                    put_bits(&s->pb, 8, side_data->data[i]);
+
+                put_bits(&s->pb, 8, 0xff);                  // marker_bits
+            } else {
+                av_log(s->avctx, AV_LOG_WARNING,
+                    "Warning Closed Caption size (%d) can not exceed 93 bytes "
+                    "and must be a multiple of 3\n", side_data->size);
+            }
+        }
+    }
+
     s->mb_y = 0;
     ff_mpeg1_encode_slice_header(s);
 }
@@ -1102,7 +1134,7 @@ av_cold void ff_mpeg1_encode_init(MpegEncContext *s)
 #define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
 #define COMMON_OPTS                                                           \
     { "gop_timecode",        "MPEG GOP Timecode in hh:mm:ss[:;.]ff format. Overrides timecode_frame_start.",   \
-      OFFSET(tc_opt_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, VE },\
+      OFFSET(tc_opt_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE },\
     { "intra_vlc",           "Use MPEG-2 intra VLC table.",                   \
       OFFSET(intra_vlc_format),    AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, \
     { "drop_frame_timecode", "Timecode is in drop frame format.",             \
@@ -1161,6 +1193,7 @@ AVCodec ff_mpeg1video_encoder = {
     .pix_fmts             = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
                                                            AV_PIX_FMT_NONE },
     .capabilities         = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
+    .caps_internal        = FF_CODEC_CAP_INIT_CLEANUP,
     .priv_class           = &mpeg1_class,
 };
 
@@ -1178,5 +1211,6 @@ AVCodec ff_mpeg2video_encoder = {
                                                            AV_PIX_FMT_YUV422P,
                                                            AV_PIX_FMT_NONE },
     .capabilities         = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
+    .caps_internal        = FF_CODEC_CAP_INIT_CLEANUP,
     .priv_class           = &mpeg2_class,
 };