[FFmpeg-devel] [PATCH v3 16/16] avformat/flvenc: prevent writing legacy codecs into extended video tracks

Timo Rothenpieler timo at rothenpieler.org
Fri Dec 20 02:43:53 EET 2024


---
 libavformat/flvenc.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 09a930fb1a..f3f32dc433 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -970,6 +970,15 @@ static int flv_init(struct AVFormatContext *s)
 
         switch (par->codec_type) {
         case AVMEDIA_TYPE_VIDEO:
+            if (video_ctr &&
+                par->codec_id != AV_CODEC_ID_VP8 &&
+                par->codec_id != AV_CODEC_ID_VP9 &&
+                par->codec_id != AV_CODEC_ID_AV1 &&
+                par->codec_id != AV_CODEC_ID_H264 &&
+                par->codec_id != AV_CODEC_ID_HEVC) {
+                av_log(s, AV_LOG_ERROR, "Unsupported multi-track video codec.\n");
+                return AVERROR(EINVAL);
+            }
             if (s->streams[i]->avg_frame_rate.den &&
                 s->streams[i]->avg_frame_rate.num) {
                 flv->framerate = av_q2d(s->streams[i]->avg_frame_rate);
@@ -1012,7 +1021,7 @@ static int flv_init(struct AVFormatContext *s)
                 par->codec_id != AV_CODEC_ID_FLAC &&
                 par->codec_id != AV_CODEC_ID_AC3 &&
                 par->codec_id != AV_CODEC_ID_EAC3) {
-                av_log(s, AV_LOG_ERROR, "Unsupported multi-track codec.\n");
+                av_log(s, AV_LOG_ERROR, "Unsupported multi-track audio codec.\n");
                 return AVERROR(EINVAL);
             }
             flv->track_idx_map[i] = audio_ctr++;
@@ -1390,6 +1399,10 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
             write_codec_fourcc(pb, par->codec_id);
             if (track_idx)
                 avio_w8(pb, track_idx);
+        } else if (track_idx) {
+            av_log(s, AV_LOG_ERROR, "Attempted to write legacy codec into extended flv track.\n");
+            ret = AVERROR(EINVAL);
+            goto fail;
         } else {
             av_assert1(flags >= 0);
             avio_w8(pb, flags);
-- 
2.45.2



More information about the ffmpeg-devel mailing list