Merge pull request #1574 in FS/freeswitch from fs-11189-av-fix to master
* commit 'be782776b535c52f49f0d64145ee9dc3e12e4d19': FS-11189 add back default flags LOOP_FILTER and PSNR for H264 FS-11189 set default cpu string to cpu/2/4 if not configured FS-11189 add helper functions and macros to dump encoder context params FS-11189 add default av conf to vanilla FS-11189 use AV_INPUT_BUFFER_PADDING_SIZE instead of FF_INPUT_BUFFER_PADDING_SIZE in newer ffmpeg
This commit is contained in:
commit
59df2a31b0
|
@ -0,0 +1,145 @@
|
|||
<configuration name="avcodec.conf" description="AVCodec Config">
|
||||
<settings>
|
||||
<!-- max bitrate the system support, truncate if over limit -->
|
||||
<!-- <param name="max-bitrate" value="5mb"/> -->
|
||||
|
||||
<!-- <param name="rtp-slice-size" value="1200"/> -->
|
||||
|
||||
<!-- minimum time to generate a new key frame in ms /> -->
|
||||
<!-- <param name="key-frame-min-freq" value="250"/> -->
|
||||
|
||||
<!-- integer of cpus, or 'auto', or 'cpu/<divisor>/<max> -->
|
||||
<param name="dec-threads" value="cpu/2/4"/>
|
||||
<param name="enc-threads" value="cpu/2/4"/>
|
||||
<param name="h263-profile" value="H263"/>
|
||||
<param name="h263+-profile" value="H263+"/>
|
||||
<param name="h264-profile" value="H264"/>
|
||||
<param name="h265-profile" value="H265"/>
|
||||
</settings>
|
||||
|
||||
<profiles>
|
||||
<profile name="H263">
|
||||
</profile>
|
||||
|
||||
<profile name="H263+">
|
||||
</profile>
|
||||
|
||||
<profile name="H264">
|
||||
<!-- <param name="dec-threads" value="cpu/2/4"/> -->
|
||||
<!-- <param name="enc-threads" value="1"/> -->
|
||||
|
||||
<!-- <param name="profile" value="2"/> -->
|
||||
<!-- <param name="level" value="41"/> -->
|
||||
<!-- <param name="timebase" value="1/90"/> -->
|
||||
|
||||
<!--
|
||||
|
||||
#define AV_CODEC_FLAG_UNALIGNED (1 << 0)
|
||||
#define AV_CODEC_FLAG_QSCALE (1 << 1)
|
||||
#define AV_CODEC_FLAG_4MV (1 << 2)
|
||||
#define AV_CODEC_FLAG_OUTPUT_CORRUPT (1 << 3)
|
||||
#define AV_CODEC_FLAG_QPEL (1 << 4)
|
||||
#define AV_CODEC_FLAG_PASS1 (1 << 9)
|
||||
#define AV_CODEC_FLAG_PASS2 (1 << 10)
|
||||
#define AV_CODEC_FLAG_LOOP_FILTER (1 << 11)
|
||||
#define AV_CODEC_FLAG_GRAY (1 << 13)
|
||||
#define AV_CODEC_FLAG_PSNR (1 << 15)
|
||||
#define AV_CODEC_FLAG_TRUNCATED (1 << 16)
|
||||
#define AV_CODEC_FLAG_INTERLACED_DCT (1 << 18)
|
||||
#define AV_CODEC_FLAG_LOW_DELAY (1 << 19)
|
||||
#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
|
||||
#define AV_CODEC_FLAG_BITEXACT (1 << 23)
|
||||
#define AV_CODEC_FLAG_AC_PRED (1 << 24)
|
||||
#define AV_CODEC_FLAG_INTERLACED_ME (1 << 29)
|
||||
#define AV_CODEC_FLAG_CLOSED_GOP (1U << 31)
|
||||
|
||||
-->
|
||||
|
||||
<param name="flags" value="LOOP_FILTER|PSNR"/>
|
||||
|
||||
<!--
|
||||
#define FF_CMP_SAD 0
|
||||
#define FF_CMP_SSE 1
|
||||
#define FF_CMP_SATD 2
|
||||
#define FF_CMP_DCT 3
|
||||
#define FF_CMP_PSNR 4
|
||||
#define FF_CMP_BIT 5
|
||||
#define FF_CMP_RD 6
|
||||
#define FF_CMP_ZERO 7
|
||||
#define FF_CMP_VSAD 8
|
||||
#define FF_CMP_VSSE 9
|
||||
#define FF_CMP_NSSE 10
|
||||
#define FF_CMP_W53 11
|
||||
#define FF_CMP_W97 12
|
||||
#define FF_CMP_DCTMAX 13
|
||||
#define FF_CMP_DCT264 14
|
||||
#define FF_CMP_MEDIAN_SAD 15
|
||||
#define FF_CMP_CHROMA 256
|
||||
-->
|
||||
|
||||
<!-- <param name="me-cmp" value="1"/> -->
|
||||
<!-- <param name="me-range" value="16"/> -->
|
||||
<!-- <param name="max-b-frames" value="3"/> -->
|
||||
<!-- <param name="refs" value="3"/> -->
|
||||
<!-- <param name="gop-size" value="250"/> -->
|
||||
<!-- <param name="keyint-min" value="25"/> -->
|
||||
<!-- <param name="i-quant-factor" value="0.71"/> -->
|
||||
<!-- <param name="b-quant-factor" value="0.76923078"/> -->
|
||||
<!-- <param name="qcompress" value="0.6"/> -->
|
||||
<!-- <param name="qmin" value="10"/> -->
|
||||
<!-- <param name="qmax" value="51"/> -->
|
||||
<!-- <param name="max-qdiff" value="4"/> -->
|
||||
|
||||
<!--
|
||||
enum AVColorSpace {
|
||||
AVCOL_SPC_RGB = 0, ///< order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
|
||||
AVCOL_SPC_BT709 = 1, ///< also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
|
||||
AVCOL_SPC_UNSPECIFIED = 2,
|
||||
AVCOL_SPC_RESERVED = 3,
|
||||
AVCOL_SPC_FCC = 4, ///< FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
|
||||
AVCOL_SPC_BT470BG = 5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
|
||||
AVCOL_SPC_SMPTE170M = 6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
|
||||
AVCOL_SPC_SMPTE240M = 7, ///< functionally identical to above
|
||||
AVCOL_SPC_YCGCO = 8, ///< Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16
|
||||
AVCOL_SPC_YCOCG = AVCOL_SPC_YCGCO,
|
||||
AVCOL_SPC_BT2020_NCL = 9, ///< ITU-R BT2020 non-constant luminance system
|
||||
AVCOL_SPC_BT2020_CL = 10, ///< ITU-R BT2020 constant luminance system
|
||||
AVCOL_SPC_SMPTE2085 = 11, ///< SMPTE 2085, Y'D'zD'x
|
||||
AVCOL_SPC_CHROMA_DERIVED_NCL = 12, ///< Chromaticity-derived non-constant luminance system
|
||||
AVCOL_SPC_CHROMA_DERIVED_CL = 13, ///< Chromaticity-derived constant luminance system
|
||||
AVCOL_SPC_ICTCP = 14, ///< ITU-R BT.2100-0, ICtCp
|
||||
AVCOL_SPC_NB ///< Not part of ABI
|
||||
};
|
||||
-->
|
||||
<param name="colorspace" value="0"/>
|
||||
|
||||
<!--
|
||||
enum AVColorRange {
|
||||
AVCOL_RANGE_UNSPECIFIED = 0,
|
||||
AVCOL_RANGE_MPEG = 1, ///< the normal 219*2^(n-8) "MPEG" YUV ranges
|
||||
AVCOL_RANGE_JPEG = 2, ///< the normal 2^n-1 "JPEG" YUV ranges
|
||||
AVCOL_RANGE_NB ///< Not part of ABI
|
||||
};
|
||||
-->
|
||||
<param name="color-range" value="2"/>
|
||||
|
||||
<!-- x264 private options-->
|
||||
<options>
|
||||
<option name="preset" value="veryfast"/>
|
||||
<option name="intra_refresh" value="1"/>
|
||||
<option name="tune" value="animation+zerolatency"/>
|
||||
<option name="sc_threshold" value="40"/>
|
||||
<option name="b_strategy" value="1"/>
|
||||
<option name="crf" value="18"/>
|
||||
</options>
|
||||
</profile>
|
||||
|
||||
<profile name="H265">
|
||||
</profile>
|
||||
</profiles>
|
||||
</configuration>
|
||||
|
||||
<configuration name="avformat.conf" description="AVFormat Config">
|
||||
<settings>
|
||||
</settings>
|
||||
</configuration>
|
|
@ -45,6 +45,8 @@ int SLICE_SIZE = SWITCH_DEFAULT_VIDEO_SIZE;
|
|||
#define H263_MODE_B // else Mode A only
|
||||
#define KEY_FRAME_MIN_FREQ 250000
|
||||
|
||||
// #define DUMP_ENCODER_CTX
|
||||
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_avcodec_load);
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_avcodec_shutdown);
|
||||
|
||||
|
@ -103,6 +105,207 @@ const uint8_t *fs_avc_find_startcode(const uint8_t *p, const uint8_t *end){
|
|||
return out;
|
||||
}
|
||||
|
||||
static void dump_encoder_ctx(AVCodecContext *ctx)
|
||||
{
|
||||
#ifdef DUMP_ENCODER_CTX
|
||||
#define STRINGIFY(x) #x
|
||||
#define my_dump_int(x) switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, STRINGIFY(x) " = %d\n", ctx->x);
|
||||
#define my_dump_int64(x) switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, STRINGIFY(x) " = % " SWITCH_INT64_T_FMT "\n", ctx->x);
|
||||
#define my_dump_float(x) switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, STRINGIFY(x) " = %f\n", ctx->x);
|
||||
#define my_dump_enum(x) switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, STRINGIFY(x) " = %d\n", ctx->x);
|
||||
#define my_dump_uint(x) switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, STRINGIFY(x) " = 0x%x\n", ctx->x);
|
||||
|
||||
my_dump_int(log_level_offset);
|
||||
my_dump_enum(codec_type); /* see AVMEDIA_TYPE_xxx */
|
||||
my_dump_enum(codec_id); /* see AV_CODEC_ID_xxx */
|
||||
my_dump_int(codec_tag);
|
||||
my_dump_int64(bit_rate);
|
||||
my_dump_int(bit_rate_tolerance);
|
||||
my_dump_int(global_quality);
|
||||
my_dump_int(compression_level);
|
||||
my_dump_uint(flags);
|
||||
my_dump_uint(flags2);
|
||||
my_dump_int(extradata_size);
|
||||
my_dump_int(time_base.num);
|
||||
my_dump_int(time_base.den);
|
||||
my_dump_int(ticks_per_frame);
|
||||
my_dump_int(delay);
|
||||
my_dump_int(width);
|
||||
my_dump_int(height);
|
||||
my_dump_int(coded_width);
|
||||
my_dump_int(coded_height);
|
||||
my_dump_int(gop_size);
|
||||
my_dump_enum(pix_fmt);
|
||||
my_dump_int(max_b_frames);
|
||||
my_dump_float(b_quant_factor);
|
||||
my_dump_float(b_quant_offset);
|
||||
my_dump_int(has_b_frames);
|
||||
my_dump_float(i_quant_factor);
|
||||
my_dump_float(i_quant_offset);
|
||||
my_dump_float(lumi_masking);
|
||||
my_dump_float(temporal_cplx_masking);
|
||||
my_dump_float(spatial_cplx_masking);
|
||||
my_dump_float(p_masking);
|
||||
my_dump_float(dark_masking);
|
||||
my_dump_int(slice_count);
|
||||
my_dump_int(sample_aspect_ratio.num);
|
||||
my_dump_int(sample_aspect_ratio.den);
|
||||
my_dump_int(me_cmp);
|
||||
my_dump_int(me_sub_cmp);
|
||||
my_dump_int(mb_cmp);
|
||||
my_dump_int(ildct_cmp);
|
||||
my_dump_int(dia_size);
|
||||
my_dump_int(last_predictor_count);
|
||||
my_dump_int(me_pre_cmp);
|
||||
my_dump_int(pre_dia_size);
|
||||
my_dump_int(me_subpel_quality);
|
||||
my_dump_int(me_range);
|
||||
my_dump_uint(slice_flags);
|
||||
my_dump_int(mb_decision);
|
||||
my_dump_int(scenechange_threshold);
|
||||
my_dump_int(noise_reduction);
|
||||
// my_dump_int(me_threshold);
|
||||
// my_dump_int(mb_threshold);
|
||||
my_dump_int(intra_dc_precision);
|
||||
my_dump_int(skip_top);
|
||||
my_dump_int(skip_bottom);
|
||||
my_dump_int(mb_lmin);
|
||||
my_dump_int(mb_lmax);
|
||||
my_dump_int(me_penalty_compensation);
|
||||
my_dump_int(bidir_refine);
|
||||
my_dump_int(brd_scale);
|
||||
my_dump_int(keyint_min);
|
||||
my_dump_int(refs);
|
||||
my_dump_int(chromaoffset);
|
||||
my_dump_int(mv0_threshold);
|
||||
my_dump_int(b_sensitivity);
|
||||
my_dump_enum(color_primaries);
|
||||
my_dump_enum(color_trc);
|
||||
my_dump_enum(colorspace);
|
||||
my_dump_enum(color_range);
|
||||
my_dump_enum(chroma_sample_location);
|
||||
my_dump_int(slices);
|
||||
my_dump_enum(field_order);
|
||||
my_dump_int(sample_rate); ///< samples per second
|
||||
my_dump_int(channels); ///< number of audio channels
|
||||
my_dump_enum(sample_fmt); ///< sample format
|
||||
my_dump_int(frame_size);
|
||||
my_dump_int(frame_number);
|
||||
my_dump_int(block_align);
|
||||
my_dump_int(cutoff);
|
||||
my_dump_int64(channel_layout);
|
||||
my_dump_int64(request_channel_layout);
|
||||
my_dump_enum(audio_service_type);
|
||||
my_dump_enum(request_sample_fmt);
|
||||
my_dump_int(refcounted_frames);
|
||||
my_dump_float(qcompress); ///< amount of qscale change between easy & hard scenes (0.0-1.0)
|
||||
my_dump_float(qblur); ///< amount of qscale smoothing over time (0.0-1.0)
|
||||
my_dump_int(qmin);
|
||||
my_dump_int(qmax);
|
||||
my_dump_int(max_qdiff);
|
||||
my_dump_int(rc_buffer_size);
|
||||
my_dump_int(rc_override_count);
|
||||
my_dump_int64(rc_max_rate);
|
||||
my_dump_int64(rc_min_rate);
|
||||
my_dump_float(rc_max_available_vbv_use);
|
||||
my_dump_float(rc_min_vbv_overflow_use);
|
||||
my_dump_int(rc_initial_buffer_occupancy);
|
||||
my_dump_int(trellis);
|
||||
my_dump_int(workaround_bugs);
|
||||
my_dump_int(strict_std_compliance);
|
||||
my_dump_int(error_concealment);
|
||||
my_dump_int(debug);
|
||||
my_dump_int(debug_mv);
|
||||
my_dump_int(err_recognition);
|
||||
my_dump_int64(reordered_opaque);
|
||||
my_dump_int(dct_algo);
|
||||
my_dump_int(idct_algo);
|
||||
my_dump_int(bits_per_coded_sample);
|
||||
my_dump_int(bits_per_raw_sample);
|
||||
my_dump_int(lowres);
|
||||
my_dump_int(thread_count);
|
||||
my_dump_int(thread_type);
|
||||
my_dump_int(active_thread_type);
|
||||
my_dump_int(thread_safe_callbacks);
|
||||
my_dump_int(nsse_weight);
|
||||
my_dump_int(profile);
|
||||
my_dump_int(level);
|
||||
my_dump_enum(skip_loop_filter);
|
||||
my_dump_enum(skip_idct);
|
||||
my_dump_enum(skip_frame);
|
||||
my_dump_int(subtitle_header_size);
|
||||
my_dump_int(initial_padding);
|
||||
my_dump_int(framerate.num);
|
||||
my_dump_int(framerate.den);
|
||||
my_dump_enum(sw_pix_fmt);
|
||||
my_dump_int(pkt_timebase.num);
|
||||
my_dump_int(pkt_timebase.den);
|
||||
my_dump_int(lowres);
|
||||
my_dump_int64(pts_correction_num_faulty_pts); /// Number of incorrect PTS values so far
|
||||
my_dump_int64(pts_correction_num_faulty_dts); /// Number of incorrect DTS values so far
|
||||
my_dump_int64(pts_correction_last_pts); /// PTS of the last frame
|
||||
my_dump_int64(pts_correction_last_dts); /// DTS of the last frame
|
||||
my_dump_int(sub_charenc_mode);
|
||||
my_dump_int(skip_alpha);
|
||||
my_dump_int(seek_preroll);
|
||||
my_dump_int(debug_mv);
|
||||
my_dump_int(sub_text_format);
|
||||
my_dump_int(trailing_padding);
|
||||
my_dump_int64(max_pixels);
|
||||
my_dump_int(hwaccel_flags);
|
||||
my_dump_int(apply_cropping);
|
||||
|
||||
#if 0
|
||||
// depracated
|
||||
my_dump_int(rc_strategy);
|
||||
my_dump_int(b_frame_strategy);
|
||||
my_dump_int(prediction_method);
|
||||
my_dump_int(pre_me);
|
||||
my_dump_int(intra_quant_bias);
|
||||
my_dump_int(inter_quant_bias);
|
||||
my_dump_int(xvmc_acceleration);
|
||||
my_dump_int(scenechange_factor);
|
||||
my_dump_float(rc_qsquish);
|
||||
my_dump_float(rc_qmod_amp);
|
||||
my_dump_int(rc_qmod_freq);
|
||||
my_dump_float(rc_buffer_aggressivity);
|
||||
my_dump_float(rc_initial_cplx);
|
||||
my_dump_int(coder_type);
|
||||
my_dump_int(context_model);
|
||||
// my_dump_int(lmin);
|
||||
// my_dump_int(lmax);
|
||||
my_dump_int(frame_skip_threshold);
|
||||
my_dump_int(frame_skip_factor);
|
||||
my_dump_int(frame_skip_exp);
|
||||
my_dump_int(frame_skip_cmp);
|
||||
my_dump_int(min_prediction_order);
|
||||
my_dump_int(max_prediction_order);
|
||||
my_dump_int64(timecode_frame_start);
|
||||
my_dump_int(rtp_payload_size);
|
||||
my_dump_int(mv_bits);
|
||||
my_dump_int(header_bits);
|
||||
my_dump_int(i_tex_bits);
|
||||
my_dump_int(p_tex_bits);
|
||||
my_dump_int(i_count);
|
||||
my_dump_int(p_count);
|
||||
my_dump_int(skip_count);
|
||||
my_dump_int(misc_bits);
|
||||
my_dump_int(frame_bits);
|
||||
// my_dump_int64(vbv_delay);
|
||||
my_dump_int(side_data_only_packets);
|
||||
#endif
|
||||
|
||||
|
||||
#undef my_dump_int
|
||||
#undef my_dump_int64
|
||||
#undef my_dump_float
|
||||
#undef my_dump_enum
|
||||
#undef my_dump_uint
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* RFC 2190 MODE A
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
|
@ -195,7 +398,11 @@ typedef struct h264_codec_context_s {
|
|||
int hw_encoder;
|
||||
} h264_codec_context_t;
|
||||
|
||||
static uint8_t ff_input_buffer_padding[FF_INPUT_BUFFER_PADDING_SIZE] = { 0 };
|
||||
#ifndef AV_INPUT_BUFFER_PADDING_SIZE
|
||||
#define AV_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE
|
||||
#endif
|
||||
|
||||
static uint8_t ff_input_buffer_padding[AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
|
||||
|
||||
#define MAX_CODECS 4
|
||||
|
||||
|
@ -1034,6 +1241,15 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
avcodec_string(buf, sizeof(buf), context->encoder_ctx, 0);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s\n", buf);
|
||||
}
|
||||
|
||||
dump_encoder_ctx(context->encoder_ctx);
|
||||
|
||||
if (avcodec_open2(context->encoder_ctx, context->encoder, NULL) < 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not open codec\n");
|
||||
return SWITCH_STATUS_FALSE;
|
||||
|
@ -1642,10 +1858,13 @@ static void load_config()
|
|||
profile->ctx.qmin = -1;
|
||||
profile->ctx.qmax = -1;
|
||||
profile->ctx.max_qdiff = -1;
|
||||
profile->ctx.thread_count = switch_parse_cpu_string("cpu/2/4");
|
||||
profile->decoder_thread_count = switch_parse_cpu_string("cpu/2/4");
|
||||
|
||||
if (!strcasecmp(CODEC_MAPS[i], "H264")) {
|
||||
profile->ctx.profile = FF_PROFILE_H264_BASELINE;
|
||||
profile->ctx.level = 41;
|
||||
profile->ctx.flags |= (CODEC_FLAG_LOOP_FILTER | AV_CODEC_FLAG_PSNR);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue