Skip to content

Commit df7b86d

Browse files
author
Guo, Jiansheng
authored
FFmpeg: make master patch compatible with n4.3 tag (#125)
Signed-off-by: Guo Jiansheng <jiansheng.guo@intel.com>
1 parent 11d000b commit df7b86d

File tree

2 files changed

+70
-62
lines changed

2 files changed

+70
-62
lines changed

ffmpeg_plugin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ cd ffmpeg
3838

3939
Which patch to apply will depend on which version of FFmpeg you are going to use.
4040

41-
master:
41+
n4.3 and master:
4242

4343
```bash
4444
git apply ../ffmpeg_plugin/master-0001-Add-ability-for-ffmpeg-to-run-svt-vp9.patch

ffmpeg_plugin/master-0001-Add-ability-for-ffmpeg-to-run-svt-vp9.patch

Lines changed: 69 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 8f40b8b8417403e2d1d99d3c885a6c9e0c196f1d Mon Sep 17 00:00:00 2001
1+
From 213cabc3d23724beae998e473660702fe30aaad1 Mon Sep 17 00:00:00 2001
22
From: hassene <hassene.tmar@intel.com>
33
Date: Fri, 15 Feb 2019 17:43:54 -0800
44
Subject: [PATCH] Add ability for ffmpeg to run svt vp9
@@ -12,55 +12,55 @@ Signed-off-by: Guo Jiansheng <jiansheng.guo@intel.com>
1212
libavcodec/Makefile | 1 +
1313
libavcodec/allcodecs.c | 1 +
1414
libavcodec/avcodec.h | 4 +
15-
libavcodec/libsvt_vp9.c | 503 ++++++++++++++++++++++++++++++++++++++
15+
libavcodec/libsvt_vp9.c | 509 ++++++++++++++++++++++++++++++++++++++
1616
libavformat/dashenc.c | 49 +++-
1717
libavformat/ivfenc.c | 30 ++-
18-
libavformat/matroskaenc.c | 103 +++++++-
18+
libavformat/matroskaenc.c | 104 +++++++-
1919
libavformat/movenc.c | 42 +++-
20-
9 files changed, 726 insertions(+), 11 deletions(-)
20+
9 files changed, 733 insertions(+), 11 deletions(-)
2121
create mode 100644 libavcodec/libsvt_vp9.c
2222

2323
diff --git a/configure b/configure
24-
index 7495f35faa..5fa3685e97 100755
24+
index bdfd731602..fbe6f838df 100755
2525
--- a/configure
2626
+++ b/configure
27-
@@ -281,6 +281,7 @@ External library support:
27+
@@ -283,6 +283,7 @@ External library support:
2828
--enable-libvorbis enable Vorbis en/decoding via libvorbis,
2929
native implementation exists [no]
3030
--enable-libvpx enable VP8 and VP9 de/encoding via libvpx [no]
3131
+ --enable-libsvtvp9 enable VP9 encoding via svt [no]
3232
--enable-libwavpack enable wavpack encoding via libwavpack [no]
3333
--enable-libwebp enable WebP encoding via libwebp [no]
3434
--enable-libx264 enable H.264 encoding via x264 [no]
35-
@@ -1810,6 +1811,7 @@ EXTERNAL_LIBRARY_LIST="
36-
libv4l2
37-
libvorbis
38-
libvpx
35+
@@ -1800,6 +1801,7 @@ EXTERNAL_LIBRARY_LIST="
36+
librtmp
37+
libshine
38+
libsmbclient
3939
+ libsvtvp9
40-
libwavpack
41-
libwebp
42-
libxml2
43-
@@ -3250,6 +3252,7 @@ libvpx_vp8_decoder_deps="libvpx"
40+
libsnappy
41+
libsoxr
42+
libspeex
43+
@@ -3253,6 +3255,7 @@ libvpx_vp8_decoder_deps="libvpx"
4444
libvpx_vp8_encoder_deps="libvpx"
4545
libvpx_vp9_decoder_deps="libvpx"
4646
libvpx_vp9_encoder_deps="libvpx"
4747
+libsvt_vp9_encoder_deps="libsvtvp9"
4848
libwavpack_encoder_deps="libwavpack"
4949
libwavpack_encoder_select="audio_frame_queue"
5050
libwebp_encoder_deps="libwebp"
51-
@@ -6408,6 +6411,7 @@ enabled libvpx && {
51+
@@ -6412,6 +6415,7 @@ enabled libvpx && {
5252
fi
5353
}
54-
54+
5555
+enabled libsvtvp9 && require_pkg_config libsvtvp9 SvtVp9Enc EbSvtVp9Enc.h eb_vp9_svt_init_handle
5656
enabled libwavpack && require libwavpack wavpack/wavpack.h WavpackOpenFileOutput -lwavpack
5757
enabled libwebp && {
5858
enabled libwebp_encoder && require_pkg_config libwebp "libwebp >= 0.2.0" webp/encode.h WebPGetEncoderVersion
5959
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
60-
index 5a6ea59715..7a31fbcb6a 100644
60+
index 18353da549..230660ea27 100644
6161
--- a/libavcodec/Makefile
6262
+++ b/libavcodec/Makefile
63-
@@ -1034,6 +1034,7 @@ OBJS-$(CONFIG_LIBVPX_VP8_DECODER) += libvpxdec.o
63+
@@ -1035,6 +1035,7 @@ OBJS-$(CONFIG_LIBVPX_VP8_DECODER) += libvpxdec.o
6464
OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o
6565
OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o libvpx.o
6666
OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o libvpx.o
@@ -69,10 +69,10 @@ index 5a6ea59715..7a31fbcb6a 100644
6969
OBJS-$(CONFIG_LIBWEBP_ENCODER) += libwebpenc_common.o libwebpenc.o
7070
OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER) += libwebpenc_common.o libwebpenc_animencoder.o
7171
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
72-
index fa0c08d42e..7e9aca5082 100644
72+
index a5048290f7..c34ef96fb9 100644
7373
--- a/libavcodec/allcodecs.c
7474
+++ b/libavcodec/allcodecs.c
75-
@@ -734,6 +734,7 @@ extern AVCodec ff_libvpx_vp8_encoder;
75+
@@ -735,6 +735,7 @@ extern AVCodec ff_libvpx_vp8_encoder;
7676
extern AVCodec ff_libvpx_vp8_decoder;
7777
extern AVCodec ff_libvpx_vp9_encoder;
7878
extern AVCodec ff_libvpx_vp9_decoder;
@@ -97,10 +97,10 @@ index c91b2fd169..10cdb7b0d9 100644
9797
* Export the AVVideoEncParams structure through frame side data.
9898
diff --git a/libavcodec/libsvt_vp9.c b/libavcodec/libsvt_vp9.c
9999
new file mode 100644
100-
index 0000000000..dfe765e665
100+
index 0000000000..a557019c9b
101101
--- /dev/null
102102
+++ b/libavcodec/libsvt_vp9.c
103-
@@ -0,0 +1,503 @@
103+
@@ -0,0 +1,509 @@
104104
+/*
105105
+* Scalable Video Technology for VP9 encoder library plugin
106106
+*
@@ -132,7 +132,9 @@ index 0000000000..dfe765e665
132132
+#include "libavutil/opt.h"
133133
+
134134
+#include "internal.h"
135+
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(58, 93, 100)
135136
+#include "encode.h"
137+
+#endif
136138
+#include "avcodec.h"
137139
+
138140
+typedef enum eos_status {
@@ -418,8 +420,8 @@ index 0000000000..dfe765e665
418420
+ headerPtrLast.n_filled_len = 0;
419421
+ headerPtrLast.n_tick_count = 0;
420422
+ headerPtrLast.p_app_private = NULL;
421-
+ headerPtrLast.p_buffer = NULL;
422-
+ headerPtrLast.flags = EB_BUFFERFLAG_EOS;
423+
+ headerPtrLast.p_buffer = NULL;
424+
+ headerPtrLast.flags = EB_BUFFERFLAG_EOS;
423425
+
424426
+ eb_vp9_svt_enc_send_picture(svt_enc->svt_handle, &headerPtrLast);
425427
+ svt_enc->eos_flag = EOS_REACHED;
@@ -456,23 +458,24 @@ index 0000000000..dfe765e665
456458
+ SvtContext *svt_enc = avctx->priv_data;
457459
+ EbBufferHeaderType *headerPtr;
458460
+ EbErrorType svt_ret;
459-
+ AVFrame *frame = svt_enc->frame;
460461
+ AVBufferRef *ref;
461-
+ int ret;
462462
+
463463
+ if (EOS_TOTRIGGER == svt_enc->eos_flag) {
464464
+ pkt = NULL;
465465
+ return AVERROR_EOF;
466466
+ }
467467
+
468-
+ ret = ff_encode_get_frame(avctx, frame);
468+
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(58, 93, 100)
469+
+ AVFrame *frame = svt_enc->frame;
470+
+ int ret = ff_encode_get_frame(avctx, frame);
469471
+ if (ret < 0 && ret != AVERROR_EOF)
470472
+ return ret;
471473
+ if (ret == AVERROR_EOF)
472474
+ frame = NULL;
473475
+
474476
+ eb_send_frame(avctx, frame);
475477
+ av_frame_unref(svt_enc->frame);
478+
+#endif
476479
+
477480
+ svt_ret = eb_vp9_svt_get_packet(svt_enc->svt_handle, &headerPtr, svt_enc->eos_flag);
478481
+ if (svt_ret == EB_NoErrorEmptyQueue)
@@ -594,6 +597,9 @@ index 0000000000..dfe765e665
594597
+ .type = AVMEDIA_TYPE_VIDEO,
595598
+ .id = AV_CODEC_ID_VP9,
596599
+ .init = eb_enc_init,
600+
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 93, 100)
601+
+ .send_frame = eb_send_frame,
602+
+#endif
597603
+ .receive_packet = eb_receive_packet,
598604
+ .close = eb_enc_close,
599605
+ .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
@@ -605,13 +611,13 @@ index 0000000000..dfe765e665
605611
+ .wrapper_name = "libsvt_vp9",
606612
+};
607613
diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
608-
index 62193058d7..36c8e29250 100644
614+
index dc3306a56a..13c8a92268 100644
609615
--- a/libavformat/dashenc.c
610616
+++ b/libavformat/dashenc.c
611-
@@ -2267,6 +2267,48 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
617+
@@ -2270,6 +2270,48 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
612618
return ret;
613619
}
614-
620+
615621
+static int dash_write_packet_vp9(AVFormatContext *s, AVPacket *pkt)
616622
+{
617623
+ int ret;
@@ -657,7 +663,7 @@ index 62193058d7..36c8e29250 100644
657663
static int dash_write_trailer(AVFormatContext *s)
658664
{
659665
DASHContext *c = s->priv_data;
660-
@@ -2314,6 +2356,11 @@ static int dash_check_bitstream(struct AVFormatContext *s, const AVPacket *avpkt
666+
@@ -2317,6 +2359,11 @@ static int dash_check_bitstream(struct AVFormatContext *s, const AVPacket *avpkt
661667
DASHContext *c = s->priv_data;
662668
OutputStream *os = &c->streams[avpkt->stream_index];
663669
AVFormatContext *oc = os->ctx;
@@ -669,7 +675,7 @@ index 62193058d7..36c8e29250 100644
669675
if (oc->oformat->check_bitstream) {
670676
int ret;
671677
AVPacket pkt = *avpkt;
672-
@@ -2400,7 +2447,7 @@ AVOutputFormat ff_dash_muxer = {
678+
@@ -2404,7 +2451,7 @@ AVOutputFormat ff_dash_muxer = {
673679
.flags = AVFMT_GLOBALHEADER | AVFMT_NOFILE | AVFMT_TS_NEGATIVE,
674680
.init = dash_init,
675681
.write_header = dash_write_header,
@@ -685,7 +691,7 @@ index 0951f56c92..3a49097e9a 100644
685691
@@ -81,9 +81,33 @@ static int ivf_write_packet(AVFormatContext *s, AVPacket *pkt)
686692
AVIOContext *pb = s->pb;
687693
IVFEncContext *ctx = s->priv_data;
688-
694+
689695
- avio_wl32(pb, pkt->size);
690696
- avio_wl64(pb, pkt->pts);
691697
- avio_write(pb, pkt->data, pkt->size);
@@ -720,19 +726,20 @@ index 0951f56c92..3a49097e9a 100644
720726
ctx->sum_delta_pts += pkt->pts - ctx->last_pts;
721727
ctx->frame_cnt++;
722728
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
723-
index 105ed5197e..b625d405a6 100644
729+
index 233c472b8f..00e6ccc8b5 100644
724730
--- a/libavformat/matroskaenc.c
725731
+++ b/libavformat/matroskaenc.c
726-
@@ -154,6 +154,8 @@ typedef struct MatroskaMuxContext {
727-
int is_dash;
728-
int dash_track_number;
729-
int allow_raw_vfw;
732+
@@ -142,6 +142,9 @@ typedef struct MatroskaMuxContext {
733+
unsigned nb_attachments;
734+
int have_video;
735+
730736
+ int simple_block_timecode;
731737
+ int accumulated_cluster_timecode;
732-
int default_mode;
733-
734-
uint32_t segment_uid[4];
735-
@@ -2082,7 +2084,13 @@ static int mkv_write_block(AVFormatContext *s, AVIOContext *pb,
738+
+
739+
int wrote_chapters;
740+
int wrote_tags;
741+
742+
@@ -2084,7 +2087,13 @@ static int mkv_write_block(AVFormatContext *s, AVIOContext *pb,
736743
put_ebml_id(pb, blockid);
737744
put_ebml_length(pb, size + track->track_num_size + 3, 0);
738745
put_ebml_num(pb, track_number, track->track_num_size);
@@ -747,28 +754,28 @@ index 105ed5197e..b625d405a6 100644
747754
avio_w8(pb, (blockid == MATROSKA_ID_SIMPLEBLOCK && keyframe) ? (1 << 7) : 0);
748755
avio_write(pb, data + offset, size);
749756
if (data != pkt->data)
750-
@@ -2266,7 +2274,7 @@ static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt)
757+
@@ -2268,7 +2277,7 @@ static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt)
751758
return 0;
752759
}
753-
760+
754761
-static int mkv_write_packet_internal(AVFormatContext *s, const AVPacket *pkt)
755762
+static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
756763
{
757764
MatroskaMuxContext *mkv = s->priv_data;
758765
AVIOContext *pb;
759-
@@ -2277,6 +2285,8 @@ static int mkv_write_packet_internal(AVFormatContext *s, const AVPacket *pkt)
766+
@@ -2279,6 +2288,8 @@ static int mkv_write_packet_internal(AVFormatContext *s, const AVPacket *pkt)
760767
int ret;
761768
int64_t ts = track->write_dts ? pkt->dts : pkt->pts;
762769
int64_t relative_packet_pos;
763770
+ double fps = 0;
764771
+ int pts_interval = 0;
765-
772+
766773
if (ts == AV_NOPTS_VALUE) {
767774
av_log(s, AV_LOG_ERROR, "Can't write packet with unknown timestamp\n");
768-
@@ -2294,6 +2304,11 @@ static int mkv_write_packet_internal(AVFormatContext *s, const AVPacket *pkt)
775+
@@ -2296,6 +2307,11 @@ static int mkv_write_packet_internal(AVFormatContext *s, const AVPacket *pkt)
769776
}
770777
}
771-
778+
772779
+ if ((pkt->flags & AV_PKT_FLAG_SVT_VP9_EXT_ON) || (pkt->flags & AV_PKT_FLAG_SVT_VP9_EXT_OFF)) {
773780
+ fps = av_q2d(s->streams[pkt->stream_index]->avg_frame_rate);
774781
+ pts_interval = 1000 / fps;
@@ -777,9 +784,9 @@ index 105ed5197e..b625d405a6 100644
777784
if (mkv->cluster_pos == -1) {
778785
ret = start_ebml_master_crc32(&mkv->cluster_bc, mkv);
779786
if (ret < 0)
780-
@@ -2311,7 +2326,67 @@ static int mkv_write_packet_internal(AVFormatContext *s, const AVPacket *pkt)
787+
@@ -2313,7 +2329,67 @@ static int mkv_write_packet_internal(AVFormatContext *s, const AVPacket *pkt)
781788
relative_packet_pos = avio_tell(pb);
782-
789+
783790
if (par->codec_type != AVMEDIA_TYPE_SUBTITLE) {
784791
- ret = mkv_write_block(s, pb, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe);
785792
+ if (pkt->flags & AV_PKT_FLAG_SVT_VP9_EXT_ON) {
@@ -846,7 +853,7 @@ index 105ed5197e..b625d405a6 100644
846853
if (ret < 0)
847854
return ret;
848855
if (keyframe && IS_SEEKABLE(s->pb, mkv) &&
849-
@@ -2375,8 +2450,14 @@ static int mkv_write_packet(AVFormatContext *s, const AVPacket *pkt)
856+
@@ -2377,8 +2453,14 @@ static int mkv_write_packet(AVFormatContext *s, const AVPacket *pkt)
850857
if (mkv->cluster_pos != -1) {
851858
if (mkv->tracks[pkt->stream_index].write_dts)
852859
cluster_time = pkt->dts - mkv->cluster_pts;
@@ -861,11 +868,11 @@ index 105ed5197e..b625d405a6 100644
861868
+ }
862869
+
863870
cluster_time += mkv->tracks[pkt->stream_index].ts_offset;
864-
871+
865872
cluster_size = avio_tell(mkv->cluster_bc);
866-
@@ -2400,7 +2481,13 @@ static int mkv_write_packet(AVFormatContext *s, const AVPacket *pkt)
873+
@@ -2402,7 +2484,13 @@ static int mkv_write_packet(AVFormatContext *s, const AVPacket *pkt)
867874
start_new_cluster = 0;
868-
875+
869876
if (start_new_cluster) {
870877
- ret = mkv_end_cluster(s);
871878
+ if ((pkt->flags & AV_PKT_FLAG_SVT_VP9_EXT_ON) ||
@@ -878,10 +885,10 @@ index 105ed5197e..b625d405a6 100644
878885
if (ret < 0)
879886
return ret;
880887
}
881-
@@ -2737,6 +2824,10 @@ static int mkv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
888+
@@ -2739,6 +2827,10 @@ static int mkv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
882889
int ret = 1;
883890
AVStream *st = s->streams[pkt->stream_index];
884-
891+
885892
+ if ((pkt->flags & AV_PKT_FLAG_SVT_VP9_EXT_ON) ||
886893
+ (pkt->flags & AV_PKT_FLAG_SVT_VP9_EXT_OFF))
887894
+ return 0;
@@ -896,7 +903,7 @@ index 7db2e28840..a1f0b3a943 100644
896903
@@ -5853,7 +5853,43 @@ static int mov_write_single_packet(AVFormatContext *s, AVPacket *pkt)
897904
}
898905
}
899-
906+
900907
- return ff_mov_write_packet(s, pkt);
901908
+ if (pkt->flags & AV_PKT_FLAG_SVT_VP9_EXT_ON) {
902909
+ uint8_t *saved_data = pkt->data;
@@ -936,18 +943,19 @@ index 7db2e28840..a1f0b3a943 100644
936943
+
937944
+ return ret;
938945
}
939-
946+
940947
static int mov_write_subtitle_end_packet(AVFormatContext *s,
941948
@@ -7013,6 +7049,10 @@ static int mov_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
942949
int ret = 1;
943950
AVStream *st = s->streams[pkt->stream_index];
944-
951+
945952
+ if ((pkt->flags & AV_PKT_FLAG_SVT_VP9_EXT_ON) ||
946953
+ (pkt->flags & AV_PKT_FLAG_SVT_VP9_EXT_OFF))
947954
+ return 0;
948955
+
949956
if (st->codecpar->codec_id == AV_CODEC_ID_AAC) {
950957
if (pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0)
951958
ret = ff_stream_add_bitstream_filter(st, "aac_adtstoasc", NULL);
952-
--
953-
2.25.1
959+
--
960+
2.17.1
961+

0 commit comments

Comments
 (0)