Skip to content

Commit

Permalink
update ffmpeg source codes for 1.87.0
Browse files Browse the repository at this point in the history
  • Loading branch information
USBhost committed Nov 22, 2024
1 parent aabab42 commit 3f9ec1e
Show file tree
Hide file tree
Showing 11 changed files with 387 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ffmpeg/JNI/config-ffmpeg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ INC_ICONV=../modified_src/iconv
INC_MXV=../modified_src/mxv
INC_MXD=../modified_src/mxd
INC_USB=../modified_src/usb
INC_DOWNLOAD=../modified_src/download
INC_MODPLUG=../libmodplug/src
INC_LIBMXL2=../libxml2/include
INC_LIBSMB2=../libsmb2/include
Expand Down Expand Up @@ -302,7 +303,7 @@ FF_FEATURE_DEMUXER="\
--disable-demuxer=subviewer \
--disable-demuxer=subviewer1 \
--disable-demuxer=vplayer \
--disable-demuxer=webvtt \
--enable-demuxer=webvtt \
"
FF_FEATURE_MUXER="\
--disable-muxers \
Expand Down Expand Up @@ -334,6 +335,7 @@ FF_FEATURE_ENCODER="\
--enable-libmp3lame \
--enable-encoder=libmp3lame \
--enable-encoder=aac \
--enable-encoder=text \
"

FF_FEATURE_FILTER="\
Expand Down Expand Up @@ -399,7 +401,7 @@ FFCOMPILER="\
$EXTRA_PARAMETERS \
"

EXTRA_CFLAGS+=" -I$INC_LIBMP3LAME -I$INC_ICONV -I$INC_MXV -I$INC_MXD -I$INC_USB -I$INC_OPENSSL -I$INC_OPUS -I$INC_SPEEX -I$INC_MODPLUG -I$INC_LIBMXL2 -I$INC_LIBSMB2 -I$INC_LIBDAV1D -DNDEBUG -DMXTECHS -DFF_API_AVPICTURE=1 -DCONFIG_MXV_FROM_MXVP=1 -DMXD_BUILTIN -ftree-vectorize -ffunction-sections -funwind-tables -fomit-frame-pointer -no-canonical-prefixes -pipe"
EXTRA_CFLAGS+=" -I$INC_LIBMP3LAME -I$INC_ICONV -I$INC_MXV -I$INC_MXD -I$INC_USB -I$INC_DOWNLOAD -I$INC_OPENSSL -I$INC_OPUS -I$INC_SPEEX -I$INC_MODPLUG -I$INC_LIBMXL2 -I$INC_LIBSMB2 -I$INC_LIBDAV1D -DNDEBUG -DMXTECHS -DFF_API_AVPICTURE=1 -DCONFIG_MXV_FROM_MXVP=1 -DMXD_BUILTIN -ftree-vectorize -ffunction-sections -funwind-tables -fomit-frame-pointer -no-canonical-prefixes -pipe"
EXTRA_LIBS=" -L$LIB_MX -lmxutil -lm -lc++_shared"

# Don't ask me why i need bash here when its already #!/bin/bash. This fixes ffmpeg ./configure: 1283: shift: can't shift that many
Expand Down
1 change: 1 addition & 0 deletions ffmpeg/JNI/ffmpeg/libavcodec/allcodecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ extern AVCodec ff_text_decoder;
extern AVCodec ff_vplayer_decoder;
extern AVCodec ff_webvtt_encoder;
extern AVCodec ff_webvtt_decoder;
extern AVCodec ff_webvtt_secondary_decoder;
extern AVCodec ff_xsub_encoder;
extern AVCodec ff_xsub_decoder;

Expand Down
91 changes: 91 additions & 0 deletions ffmpeg/JNI/ffmpeg/libavcodec/webvttdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

#ifdef MXTECHS
#include "mxsubdec.c"
#include "avcodec.h"
#include "ass.h"
#include "libavutil/bprint.h"

#if CONFIG_WEBVTT_DECODER
AVCodec ff_webvtt_decoder = {
.name = "webvtt",
Expand All @@ -35,6 +39,93 @@ AVCodec ff_webvtt_decoder = {
.id = AV_CODEC_ID_WEBVTT,
.decode = mx_decode_frame,
};


static const struct {
const char *from;
const char *to;
} webvtt_tag_replace[] = {
{"<i>", "{\\i1}"}, {"</i>", "{\\i0}"},
{"<b>", "{\\b1}"}, {"</b>", "{\\b0}"},
{"<u>", "{\\u1}"}, {"</u>", "{\\u0}"},
{"{", "\\{"}, {"}", "\\}"}, // escape to avoid ASS markup conflicts
{"&gt;", ">"}, {"&lt;", "<"},
{"&lrm;", ""}, {"&rlm;", ""}, // FIXME: properly honor bidi marks
{"&amp;", "&"}, {"&nbsp;", "\\h"},
};

static int webvtt_event_to_ass(AVBPrint *buf, const char *p)
{
int i, again = 0, skip = 0;

while (*p) {

for (i = 0; i < FF_ARRAY_ELEMS(webvtt_tag_replace); i++) {
const char *from = webvtt_tag_replace[i].from;
const size_t len = strlen(from);
if (!strncmp(p, from, len)) {
av_bprintf(buf, "%s", webvtt_tag_replace[i].to);
p += len;
again = 1;
break;
}
}
if (!*p)
break;

if (again) {
again = 0;
skip = 0;
continue;
}
if (*p == '<')
skip = 1;
else if (*p == '>')
skip = 0;
else if (p[0] == '\n' && p[1])
av_bprintf(buf, "\\N");
else if (!skip && *p != '\r')
av_bprint_chars(buf, *p, 1);
p++;
}
return 0;
}

static int webvtt_decode_frame(AVCodecContext *avctx,
void *data, int *got_sub_ptr, AVPacket *avpkt)
{
int ret = 0;
AVSubtitle *sub = data;
const char *ptr = avpkt->data;
FFASSDecoderContext *s = avctx->priv_data;
AVBPrint buf;

av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
if (ptr && avpkt->size > 0 && !webvtt_event_to_ass(&buf, ptr))
ret = ff_ass_add_rect(sub, buf.str, s->readorder++, 0, NULL, NULL);
av_bprint_finalize(&buf, NULL);
if (ret < 0)
return ret;
*got_sub_ptr = sub->num_rects > 0;
return avpkt->size;
}

/*
* since we have updated subtitle decoding logic to mx_decode_frame,
* but there still some requirement need standard decoding in ffmpeg,
* so we keep it and rename it, then we can opt it manually.
*/
AVCodec ff_webvtt_secondary_decoder = {
.name = "secondary_webvtt",
.long_name = NULL_IF_CONFIG_SMALL("secndary WebVTT subtitle"),
.type = AVMEDIA_TYPE_SUBTITLE,
.id = AV_CODEC_ID_WEBVTT,
.decode = webvtt_decode_frame,
.init = ff_ass_subtitle_header_default,
.flush = ff_ass_decoder_flush,
.priv_data_size = sizeof(FFASSDecoderContext),
};

#endif
#else
#include "avcodec.h"
Expand Down
1 change: 1 addition & 0 deletions ffmpeg/JNI/ffmpeg/libavformat/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ OBJS = allformats.o \
url.o \
utils.o \
ijkutils.o \
downloadhttp.o \

OBJS-$(HAVE_LIBC_MSVCRT) += file_open.o

Expand Down
Loading

0 comments on commit 3f9ec1e

Please sign in to comment.