Annotation of pkgsrc/multimedia/transcode/patches/patch-export_export_ffmpeg.c, revision 1.2

1.1       markd       1: $NetBSD$
                      2: 
1.2     ! adam        3: Fixes building against FFmpeg version >= 2.0.0 (gentoo patch).
1.1       markd       4: 
                      5: --- export/export_ffmpeg.c.orig        2011-11-19 16:50:27.000000000 +0000
                      6: +++ export/export_ffmpeg.c
                      7: @@ -122,6 +122,7 @@ static uint8_t             *img_buffer =
                      8:  static AVFrame             *lavc_convert_frame = NULL;
                      9:  
                     10:  static AVCodec             *lavc_venc_codec = NULL;
1.2     ! adam       11: +static AVDictionary        *lavc_venc_opts = NULL;
1.1       markd      12:  static AVFrame             *lavc_venc_frame = NULL;
                     13:  static AVCodecContext      *lavc_venc_context;
                     14:  static avi_t               *avifile = NULL;
                     15: @@ -180,7 +181,7 @@ static char *tc_strchrnul(const char *s,
                     16:  
                     17:  
                     18:  /* START: COPIED FROM ffmpeg-0.5_p22846(ffmpeg.c, cmdutils.c) */
                     19: -#include <libavcodec/opt.h>
                     20: +#include <libavutil/opt.h>
                     21:  #include <libavutil/avstring.h>
                     22:  #include <libswscale/swscale.h>
                     23:  
                     24: @@ -470,7 +471,6 @@ MOD_init
                     25:      }
                     26:  
                     27:      TC_LOCK_LIBAVCODEC;
                     28: -    avcodec_init();
                     29:      avcodec_register_all();
                     30:      TC_UNLOCK_LIBAVCODEC;
                     31:  
1.2     ! adam       32: @@ -486,7 +486,7 @@ MOD_init
        !            33:                            codec->name, codec->fourCC, codec->comments);
        !            34:      }
        !            35:  
        !            36: -    lavc_venc_context = avcodec_alloc_context();
        !            37: +    lavc_venc_context = avcodec_alloc_context3(lavc_venc_codec);
        !            38:      lavc_venc_frame   = avcodec_alloc_frame();
        !            39:  
        !            40:      lavc_convert_frame= avcodec_alloc_frame();
1.1       markd      41: @@ -634,7 +634,7 @@ MOD_init
                     42:          lavc_param_rc_max_rate = 2516;
                     43:          lavc_param_rc_buffer_size = 224 * 8;
                     44:          lavc_param_rc_buffer_aggressivity = 99;
                     45: -        lavc_param_scan_offset = CODEC_FLAG_SVCD_SCAN_OFFSET;
                     46: +        lavc_param_scan_offset = 1;
                     47:  
                     48:          break;
                     49:  
                     50: @@ -674,7 +674,7 @@ MOD_init
                     51:  
                     52:          lavc_param_rc_buffer_size = 224 * 8;
                     53:          lavc_param_rc_buffer_aggressivity = 99;
                     54: -        lavc_param_scan_offset = CODEC_FLAG_SVCD_SCAN_OFFSET;
                     55: +        lavc_param_scan_offset = 1;
                     56:  
                     57:          break;
                     58:  
1.2     ! adam       59: @@ -838,8 +838,13 @@ MOD_init
        !            60:      lavc_venc_context->rc_strategy        = lavc_param_vrc_strategy;
        !            61:      lavc_venc_context->b_frame_strategy   = lavc_param_vb_strategy;
        !            62:      lavc_venc_context->b_quant_offset     = lavc_param_vb_qoffset;
        !            63: -    lavc_venc_context->luma_elim_threshold= lavc_param_luma_elim_threshold;
        !            64: -    lavc_venc_context->chroma_elim_threshold= lavc_param_chroma_elim_threshold;
        !            65: +
        !            66: +    char buf[1024];
        !            67: +#define set_dict_opt(val, opt) \
        !            68: +      snprintf(buf, sizeof(buf), "%i", val); \
        !            69: +      av_dict_set(&lavc_venc_opts, opt, buf, 0)
        !            70: +    set_dict_opt(lavc_param_luma_elim_threshold, "luma_elim_threshold");
        !            71: +    set_dict_opt(lavc_param_chroma_elim_threshold, "chroma_elim_threshold");
        !            72:      lavc_venc_context->rtp_payload_size   = lavc_param_packet_size;
        !            73:  #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)   
        !            74:      if (lavc_param_packet_size)
        !            75: @@ -870,7 +875,7 @@ MOD_init
        !            76:      lavc_venc_context->context_model      = lavc_param_context;
        !            77:      lavc_venc_context->scenechange_threshold= lavc_param_sc_threshold;
        !            78:      lavc_venc_context->noise_reduction    = lavc_param_noise_reduction;
        !            79: -    lavc_venc_context->inter_threshold    = lavc_param_inter_threshold;
        !            80: +    set_dict_opt(lavc_param_inter_threshold, "inter_threshold");
        !            81:      lavc_venc_context->intra_dc_precision = lavc_param_intra_dc_precision;
        !            82:      lavc_venc_context->skip_top           = lavc_param_skip_top;
        !            83:      lavc_venc_context->skip_bottom        = lavc_param_skip_bottom;
        !            84: @@ -887,7 +892,7 @@ MOD_init
1.1       markd      85:                    lavc_venc_context->thread_count);
                     86:      }
                     87:  
                     88: -    avcodec_thread_init(lavc_venc_context, lavc_param_threads);
                     89: +    lavc_venc_context->thread_count = lavc_param_threads;
                     90:  
                     91:      if (lavc_param_intra_matrix) {
                     92:          char *tmp;
1.2     ! adam       93: @@ -1065,15 +1070,12 @@ MOD_init
1.1       markd      94:      lavc_venc_context->flags |= lavc_param_closedgop;
                     95:      lavc_venc_context->flags |= lavc_param_trunc;
                     96:      lavc_venc_context->flags |= lavc_param_aic;
                     97: -    lavc_venc_context->flags |= lavc_param_umv;
                     98:      lavc_venc_context->flags |= lavc_param_v4mv;
                     99: -    lavc_venc_context->flags |= lavc_param_data_partitioning;
1.2     ! adam      100: -    lavc_venc_context->flags |= lavc_param_cbp;
        !           101: +    if(lavc_param_cbp)
        !           102: +      av_dict_set(&lavc_venc_opts, "mpv_flags", "+cbp_rd", 0);
1.1       markd     103:      lavc_venc_context->flags |= lavc_param_mv0;
1.2     ! adam      104: -    lavc_venc_context->flags |= lavc_param_qp_rd;
1.1       markd     105: -    lavc_venc_context->flags |= lavc_param_scan_offset;
                    106: -    lavc_venc_context->flags |= lavc_param_ss;
                    107: -    lavc_venc_context->flags |= lavc_param_alt;
1.2     ! adam      108: +    if(lavc_param_qp_rd)
        !           109: +      av_dict_set(&lavc_venc_opts, "mpv_flags", "+qp_rd", 0);
1.1       markd     110:      lavc_venc_context->flags |= lavc_param_ilme;
                    111:  #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)   
                    112:      lavc_venc_context->flags |= lavc_param_trell;
1.2     ! adam      113: @@ -1203,9 +1205,8 @@ MOD_init
1.1       markd     114:  
                    115:      lavc_venc_context->me_method = ME_ZERO + lavc_param_vme;
                    116:  
                    117: -
                    118:        /* FIXME: transcode itself contains "broken ffmpeg default settings", thus we need to override them! */
1.2     ! adam      119: -      if (lavc_param_video_preset) {
        !           120: +      if (lavc_param_video_preset && strcmp(lavc_param_video_preset, "none")) {
1.1       markd     121:                avcodec_opts[AVMEDIA_TYPE_VIDEO] = lavc_venc_context;
1.2     ! adam      122:                video_codec_name = ffmpeg_codec_name(codec->name);
        !           123:  
        !           124: @@ -1241,20 +1242,39 @@ MOD_init
1.1       markd     125:                }
                    126:        }
                    127:  
                    128: +    if (lavc_param_scan_offset) {
1.2     ! adam      129: +      av_dict_set(&lavc_venc_opts, "scan_offset", "1", 0);
1.1       markd     130: +    }
                    131: +
                    132: +    if (lavc_param_ss) {
1.2     ! adam      133: +      av_dict_set(&lavc_venc_opts, "structured_slices", "1", 0);
1.1       markd     134: +    }
                    135: +
                    136: +    if (lavc_param_alt) {
1.2     ! adam      137: +      av_dict_set(&lavc_venc_opts, "alternate_scan", "1", 0);
1.1       markd     138: +    }
                    139: +
                    140: +    if (lavc_param_umv) {
1.2     ! adam      141: +      av_dict_set(&lavc_venc_opts, "umv", "1", 0);
1.1       markd     142: +    }
                    143: +
                    144: +    if (lavc_param_data_partitioning) {
1.2     ! adam      145: +      av_dict_set(&lavc_venc_opts, "vdpart", "1", 0);
1.1       markd     146: +    }
                    147:  
                    148:      //-- open codec --
                    149:      //----------------
                    150:      TC_LOCK_LIBAVCODEC;
                    151: -    ret = avcodec_open(lavc_venc_context, lavc_venc_codec);
1.2     ! adam      152: +    ret = avcodec_open2(lavc_venc_context, lavc_venc_codec, &lavc_venc_opts);
1.1       markd     153:      TC_UNLOCK_LIBAVCODEC;
                    154:      if (ret < 0) {
                    155:        tc_log_warn(MOD_NAME, "could not open FFMPEG codec");
                    156:        return TC_EXPORT_ERROR;
                    157:      }
                    158:  
                    159: -    if (lavc_venc_context->codec->encode == NULL) {
                    160: +    if (av_codec_is_encoder(lavc_venc_context->codec) == 0) {
                    161:        tc_log_warn(MOD_NAME, "could not open FFMPEG codec "
                    162: -              "(lavc_venc_context->codec->encode == NULL)");
                    163: +              "(av_codec_is_encoder(lavc_venc_context->codec) == 0)");
                    164:        return TC_EXPORT_ERROR;
                    165:      }
                    166:  

CVSweb <webmaster@jp.NetBSD.org>