[FFmpeg-devel] [PATCH] avformat: Implement subtitle charenc guessing

Lukasz Marek lukasz.m.luki2 at gmail.com
Fri Dec 12 15:24:23 CET 2014


On 12 December 2014 at 07:05, Rodger Combs <rodger.combs at gmail.com> wrote:
>
> diff --git a/configure b/configure
> index e2e3619..a5a9f9b 100755
> --- a/configure
> +++ b/configure
> @@ -199,6 +199,9 @@ External library support:
>    --enable-gnutls          enable gnutls, needed for https support
>                             if openssl is not used [no]
>    --disable-iconv          disable iconv [autodetect]
> +  --disable-libguess       disable libguess [autodetect]
> +  --disable-uchardet       disable universalchardet [autodetect]
> +  --enable-enca            disable enca [no]
>

enable


>    --enable-ladspa          enable LADSPA audio filtering [no]
>    --enable-libaacplus      enable AAC+ encoding via libaacplus [no]
>    --enable-libass          enable libass subtitles rendering,
> @@ -1342,6 +1345,9 @@ EXTERNAL_LIBRARY_LIST="
>      frei0r
>      gnutls
>      iconv
> +    libguess
> +    uchardet
> +    enca
>      ladspa
>      libaacplus
>      libass
> @@ -4358,6 +4364,7 @@ die_license_disabled gpl libxavs
>  die_license_disabled gpl libxvid
>  die_license_disabled gpl libzvbi
>  die_license_disabled gpl x11grab
> +die_license_disabled gpl enca
>
>  die_license_disabled nonfree libaacplus
>  die_license_disabled nonfree libfaac
> @@ -5117,6 +5124,14 @@ enabled vdpau && enabled xlib &&
>  # Funny iconv installations are not unusual, so check it after all flags
> have been set
>  disabled iconv || check_func_headers iconv.h iconv || check_lib2 iconv.h
> iconv -liconv || disable iconv
>
> +disabled iconv || disabled libguess || disable libguess && {
> +    check_pkg_config libguess libguess.h libguess_determine_encoding &&
> require_pkg_config libguess libguess.h libguess_determine_encoding &&
> enable libguess;
> +}
> +disabled iconv || disabled uchardet || disable uchardet && {
> +    check_pkg_config uchardet uchardet.h uchardet_new &&
> require_pkg_config uchardet uchardet.h uchardet_new && enable uchardet;
> +}
> +enabled enca && check_func_headers enca.h enca_analyse || check_lib2
> enca.h enca_analyse -lenca || die "ERROR: enca not found"
> +
>  enabled debug && add_cflags -g"$debuglevel" && add_asflags -g"$debuglevel"
>
>  # add some useful compiler flags if supported
> diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
> index 1d5b078..93b3105 100644
> --- a/libavcodec/options_table.h
> +++ b/libavcodec/options_table.h
> @@ -472,7 +472,7 @@ static const AVOption avcodec_options[] = {
>  {"ka", "Karaoke",            0, AV_OPT_TYPE_CONST, {.i64 =
> AV_AUDIO_SERVICE_TYPE_KARAOKE },           INT_MIN, INT_MAX, A|E,
> "audio_service_type"},
>  {"request_sample_fmt", "sample format audio decoders should prefer",
> OFFSET(request_sample_fmt), AV_OPT_TYPE_SAMPLE_FMT,
> {.i64=AV_SAMPLE_FMT_NONE}, -1, INT_MAX, A|D, "request_sample_fmt"},
>  {"pkt_timebase", NULL, OFFSET(pkt_timebase), AV_OPT_TYPE_RATIONAL, {.dbl
> = 0 }, 0, INT_MAX, 0},
> -{"sub_charenc", "set input text subtitles character encoding",
> OFFSET(sub_charenc), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX,
> S|D},
> +{"sub_charenc_lavc", "set input text subtitles character encoding",
> OFFSET(sub_charenc), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX,
> S|D},
>

hmm, this is API break. is this really required?


+/**
> + * Add a character encoding guess to an AVFormatContext's list
> + *
> + * @param avctx the context to add to
> + * @param enc   the encoding name to add
> + *
> + * A copy is added, so the original string should be free()d if necessary.
> + * If the same encoding name is already present, it isn't added again.
> + * If NULL or an empty string is passed, it's not added.
> + */
> +static void add_charenc(AVFormatContext *avctx, const char *enc)
> +{
> +    char *copy;
> +
> +    if (!enc || !enc[0])
> +        return;
> +
> +    for (unsigned i = 0; i < avctx->nb_sub_charenc_guesses; i++)
> +        if (!strcmp(avctx->sub_charenc_guesses[i], enc))
> +            return;
> +
> +    copy = av_strdup(enc);
> +    if (!copy)
> +        return;
> +
> +    dynarray_add(&avctx->sub_charenc_guesses,
> &avctx->nb_sub_charenc_guesses,
> +                 copy);
>

av_dynarray_add_nofree is probably better.


More information about the ffmpeg-devel mailing list