diff mbox series

[FFmpeg-devel] Add enhanced rtmp codec vp8 to flv format

Message ID CAHQq8Q+oJEBayg0J95r2qqQ3vXRvpRb7VgBaYWmfYDWUY9E_rQ@mail.gmail.com
State New
Headers show
Series [FFmpeg-devel] Add enhanced rtmp codec vp8 to flv format | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch

Commit Message

Mondain Aug. 5, 2024, 2:01 p.m. UTC
Fixes: Reading and writing of VP8 media in FLV files, to match
existing enhanced codecs

Signed-off-by: Paul Gregoire <mondain@gmail.com>
---
 libavformat/flvdec.c | 12 +++++++++--
 libavformat/flvenc.c | 51 +++++++++++++++++++++++++++++---------------
 2 files changed, 44 insertions(+), 19 deletions(-)

         side_data = av_packet_side_data_get(par->coded_side_data,
par->nb_coded_side_data,
                                             AV_PKT_DATA_CONTENT_LIGHT_LEVEL);
@@ -519,12 +520,18 @@ static void
flv_write_metadata_packet(AVFormatContext *s, AVCodecParameters *par
         put_timestamp(pb, ts); //ts = pkt->dts, gen
         avio_wb24(pb, flv->reserved);

-        if (par->codec_id == AV_CODEC_ID_HEVC) {
-            avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeMetadata|
FLV_FRAME_VIDEO_INFO_CMD); // ExVideoTagHeader mode with
PacketTypeMetadata
+        if (par->codec_id == AV_CODEC_ID_VP8) {
+            avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeMetadata |
FLV_FRAME_VIDEO_INFO_CMD); // ExVideoTagHeader mode with
PacketTypeMetadata
+            avio_write(pb, "vp08", 4);
+        } else if (par->codec_id == AV_CODEC_ID_VP9) {
+            avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeMetadata |
FLV_FRAME_VIDEO_INFO_CMD);
+            avio_write(pb, "vp09", 4);
+        } else if (par->codec_id == AV_CODEC_ID_HEVC) {
+            avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeMetadata |
FLV_FRAME_VIDEO_INFO_CMD);
             avio_write(pb, "hvc1", 4);
-        } else if (par->codec_id == AV_CODEC_ID_AV1 || par->codec_id
== AV_CODEC_ID_VP9) {
-            avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeMetadata|
FLV_FRAME_VIDEO_INFO_CMD);
-            avio_write(pb, par->codec_id == AV_CODEC_ID_AV1 ? "av01"
: "vp09", 4);
+        } else if (par->codec_id == AV_CODEC_ID_AV1) {
+            avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeMetadata |
FLV_FRAME_VIDEO_INFO_CMD);
+            avio_write(pb, "av01", 4);
         }

         avio_w8(pb, AMF_DATA_TYPE_STRING);
@@ -639,7 +646,8 @@ static void
flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i

     if (par->codec_id == AV_CODEC_ID_AAC || par->codec_id == AV_CODEC_ID_H264
             || par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id ==
AV_CODEC_ID_HEVC
-            || par->codec_id == AV_CODEC_ID_AV1 || par->codec_id ==
AV_CODEC_ID_VP9) {
+            || par->codec_id == AV_CODEC_ID_AV1 || par->codec_id ==
AV_CODEC_ID_VP9
+            || par->codec_id == AV_CODEC_ID_VP8) {
         int64_t pos;
         avio_w8(pb,
                 par->codec_type == AVMEDIA_TYPE_VIDEO ?
@@ -682,23 +690,28 @@ static void
flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i
             }
             avio_write(pb, par->extradata, par->extradata_size);
         } else {
-            if (par->codec_id == AV_CODEC_ID_HEVC) {
+            if (par->codec_id == AV_CODEC_ID_VP8) {
                 avio_w8(pb, FLV_IS_EX_HEADER |
PacketTypeSequenceStart | FLV_FRAME_KEY); // ExVideoTagHeader mode
with PacketTypeSequenceStart
+                avio_write(pb, "vp08", 4);
+            } else if (par->codec_id == AV_CODEC_ID_VP9) {
+                avio_w8(pb, FLV_IS_EX_HEADER |
PacketTypeSequenceStart | FLV_FRAME_KEY);
+                avio_write(pb, "vp09", 4);
+            } else if (par->codec_id == AV_CODEC_ID_HEVC) {
+                avio_w8(pb, FLV_IS_EX_HEADER |
PacketTypeSequenceStart | FLV_FRAME_KEY);
                 avio_write(pb, "hvc1", 4);
-            } else if (par->codec_id == AV_CODEC_ID_AV1 ||
par->codec_id == AV_CODEC_ID_VP9) {
+            } else if (par->codec_id == AV_CODEC_ID_AV1) {
                 avio_w8(pb, FLV_IS_EX_HEADER |
PacketTypeSequenceStart | FLV_FRAME_KEY);
-                avio_write(pb, par->codec_id == AV_CODEC_ID_AV1 ?
"av01" : "vp09", 4);
+                avio_write(pb, "av01", 4);
             } else {
                 avio_w8(pb, par->codec_tag | FLV_FRAME_KEY); // flags
                 avio_w8(pb, 0); // AVC sequence header
                 avio_wb24(pb, 0); // composition time
             }
-
             if (par->codec_id == AV_CODEC_ID_HEVC)
                 ff_isom_write_hvcc(pb, par->extradata, par->extradata_size, 0);
             else if (par->codec_id == AV_CODEC_ID_AV1)
                 ff_isom_write_av1c(pb, par->extradata, par->extradata_size, 1);
-            else if (par->codec_id == AV_CODEC_ID_VP9)
+            else if (par->codec_id == AV_CODEC_ID_VP9 ||
par->codec_id == AV_CODEC_ID_VP8)
                 ff_isom_write_vpcc(s, pb, par->extradata,
par->extradata_size, par);
             else
                 ff_isom_write_avcc(pb, par->extradata, par->extradata_size);
@@ -1001,7 +1014,7 @@ static int flv_write_packet(AVFormatContext *s,
AVPacket *pkt)
         flags_size = 2;
     else if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id ==
AV_CODEC_ID_MPEG4 ||
              par->codec_id == AV_CODEC_ID_HEVC || par->codec_id ==
AV_CODEC_ID_AV1 ||
-             par->codec_id == AV_CODEC_ID_VP9)
+             par->codec_id == AV_CODEC_ID_VP9 || par->codec_id ==
AV_CODEC_ID_VP8)
         flags_size = 5;
     else
         flags_size = 1;
@@ -1011,7 +1024,8 @@ static int flv_write_packet(AVFormatContext *s,
AVPacket *pkt)

     if (par->codec_id == AV_CODEC_ID_AAC || par->codec_id == AV_CODEC_ID_H264
             || par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id ==
AV_CODEC_ID_HEVC
-            || par->codec_id == AV_CODEC_ID_AV1 || par->codec_id ==
AV_CODEC_ID_VP9) {
+            || par->codec_id == AV_CODEC_ID_AV1 || par->codec_id ==
AV_CODEC_ID_VP9
+            || par->codec_id == AV_CODEC_ID_VP8) {
         size_t side_size;
         uint8_t *side = av_packet_get_side_data(pkt,
AV_PKT_DATA_NEW_EXTRADATA, &side_size);
         if (side && side_size > 0 && (side_size !=
par->extradata_size || memcmp(side, par->extradata, side_size))) {
@@ -1034,7 +1048,7 @@ static int flv_write_packet(AVFormatContext *s,
AVPacket *pkt)
     }
     if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id ==
AV_CODEC_ID_MPEG4 ||
         par->codec_id == AV_CODEC_ID_HEVC ||  par->codec_id ==
AV_CODEC_ID_AV1 ||
-        par->codec_id == AV_CODEC_ID_VP9) {
+        par->codec_id == AV_CODEC_ID_VP9 || par->codec_id == AV_CODEC_ID_VP8) {
         if (pkt->pts == AV_NOPTS_VALUE) {
             av_log(s, AV_LOG_ERROR, "Packet is missing PTS\n");
             return AVERROR(EINVAL);
@@ -1150,9 +1164,12 @@ static int flv_write_packet(AVFormatContext *s,
AVPacket *pkt)
             avio_write(pb, "hvc1", 4);
             if (pkttype == PacketTypeCodedFrames)
                 avio_wb24(pb, pkt->pts - pkt->dts);
-        } else if (par->codec_id == AV_CODEC_ID_AV1 || par->codec_id
== AV_CODEC_ID_VP9) {
+        } else if (par->codec_id == AV_CODEC_ID_AV1) {
+            avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeCodedFrames | frametype);
+            avio_write(pb, "av01", 4);
+        } else if (par->codec_id == AV_CODEC_ID_VP9 || par->codec_id
== AV_CODEC_ID_VP8) {
             avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeCodedFrames | frametype);
-            avio_write(pb, par->codec_id == AV_CODEC_ID_AV1 ? "av01"
: "vp09", 4);
+            avio_write(pb, par->codec_id == AV_CODEC_ID_VP8 ? "vp08"
: "vp09", 4);
         } else {
             avio_w8(pb, flags);
         }

Comments

Timo Rothenpieler Aug. 5, 2024, 7:55 p.m. UTC | #1
On 05.08.2024 16:01, Mondain wrote:
> Fixes: Reading and writing of VP8 media in FLV files, to match
> existing enhanced codecs

This will be part of the already finished enhanced rtmp v2 patch set, 
but the spec needs to be out of alpha first.
VP8 is in fact missing, since I didn't think anyone would care about it 
specifically.
If you like, send it as PR to 
https://github.com/BtbN/FFmpeg/blob/enhanced-flv
Mondain Aug. 6, 2024, 4:29 p.m. UTC | #2
Just a curiosity thing; why would the spec need to be out of alpha, yet the
other codecs are already in ffmpeg? Just no preference for VP8 itself,
while its still in-spec for tech like WebRTC? Again, just seems odd that
I've run into this type of messaging before.

Best Regards,
Paul

On Mon, Aug 5, 2024 at 12:55 PM Timo Rothenpieler <timo@rothenpieler.org>
wrote:

> On 05.08.2024 16:01, Mondain wrote:
> > Fixes: Reading and writing of VP8 media in FLV files, to match
> > existing enhanced codecs
>
> This will be part of the already finished enhanced rtmp v2 patch set,
> but the spec needs to be out of alpha first.
> VP8 is in fact missing, since I didn't think anyone would care about it
> specifically.
> If you like, send it as PR to
> https://github.com/BtbN/FFmpeg/blob/enhanced-flv
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
Mondain Aug. 6, 2024, 4:37 p.m. UTC | #3
Timo, I've created the PR here: https://github.com/BtbN/FFmpeg/pull/2

On Tue, Aug 6, 2024 at 9:29 AM Mondain <mondain@gmail.com> wrote:

> Just a curiosity thing; why would the spec need to be out of alpha, yet
> the other codecs are already in ffmpeg? Just no preference for VP8 itself,
> while its still in-spec for tech like WebRTC? Again, just seems odd that
> I've run into this type of messaging before.
>
> Best Regards,
> Paul
>
> On Mon, Aug 5, 2024 at 12:55 PM Timo Rothenpieler <timo@rothenpieler.org>
> wrote:
>
>> On 05.08.2024 16:01, Mondain wrote:
>> > Fixes: Reading and writing of VP8 media in FLV files, to match
>> > existing enhanced codecs
>>
>> This will be part of the already finished enhanced rtmp v2 patch set,
>> but the spec needs to be out of alpha first.
>> VP8 is in fact missing, since I didn't think anyone would care about it
>> specifically.
>> If you like, send it as PR to
>> https://github.com/BtbN/FFmpeg/blob/enhanced-flv
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>>
>
>
> --
>
> <https://about.me/mondain?promo=email_sig&utm_source=product&utm_medium=email_sig&utm_campaign=edit_panel&utm_content=thumb>
> Paul Gregoire
> about.me/mondain
> <https://about.me/mondain?promo=email_sig&utm_source=product&utm_medium=email_sig&utm_campaign=edit_panel&utm_content=thumb>
>
Timo Rothenpieler Aug. 6, 2024, 4:39 p.m. UTC | #4
On 06.08.2024 18:29, Mondain wrote:
> Just a curiosity thing; why would the spec need to be out of alpha, yet the
> other codecs are already in ffmpeg? Just no preference for VP8 itself,
> while its still in-spec for tech like WebRTC? Again, just seems odd that
> I've run into this type of messaging before.

Cause it can still change, though it seems unlikely at this point.
Only v1 stuff is merged yet, since it's not in alpha anymore.
Mondain Aug. 6, 2024, 5:17 p.m. UTC | #5
Ok, sounds good; I'll get this rebased; one small patch is gonna take
longer than expected.

On Tue, Aug 6, 2024 at 9:39 AM Timo Rothenpieler <timo@rothenpieler.org> wrote:
>
> On 06.08.2024 18:29, Mondain wrote:
> > Just a curiosity thing; why would the spec need to be out of alpha, yet the
> > other codecs are already in ffmpeg? Just no preference for VP8 itself,
> > while its still in-spec for tech like WebRTC? Again, just seems odd that
> > I've run into this type of messaging before.
>
> Cause it can still change, though it seems unlikely at this point.
> Only v1 stuff is merged yet, since it's not in alpha anymore.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index 22a9b9e4a7..2383682a63 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -340,6 +340,8 @@  static int flv_same_video_codec(AVCodecParameters
*vpar, uint32_t flv_codecid)
         return vpar->codec_id == AV_CODEC_ID_AV1;
     case MKBETAG('v', 'p', '0', '9'):
         return vpar->codec_id == AV_CODEC_ID_VP9;
+    case MKBETAG('v', 'p', '0', '8'):
+        return vpar->codec_id == AV_CODEC_ID_VP8;
     case FLV_CODECID_H263:
         return vpar->codec_id == AV_CODEC_ID_FLV1;
     case FLV_CODECID_SCREEN:
@@ -378,6 +380,10 @@  static int flv_set_video_codec(AVFormatContext
*s, AVStream *vstream,
         par->codec_id = AV_CODEC_ID_VP9;
         vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
         break;
+    case MKBETAG('v', 'p', '0', '8'):
+        par->codec_id = AV_CODEC_ID_VP8;
+        vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
+        break;
     case FLV_CODECID_H263:
         par->codec_id = AV_CODEC_ID_FLV1;
         break;
@@ -1443,7 +1449,8 @@  retry_duration:
         st->codecpar->codec_id == AV_CODEC_ID_MPEG4 ||
         st->codecpar->codec_id == AV_CODEC_ID_HEVC ||
         st->codecpar->codec_id == AV_CODEC_ID_AV1 ||
-        st->codecpar->codec_id == AV_CODEC_ID_VP9) {
+        st->codecpar->codec_id == AV_CODEC_ID_VP9 ||
+        st->codecpar->codec_id == AV_CODEC_ID_VP8) {
         int type = 0;
         if (enhanced_flv && stream_type == FLV_STREAM_TYPE_VIDEO) {
             type = flags & 0x0F;
@@ -1481,7 +1488,8 @@  retry_duration:
         }
         if (type == 0 && (!st->codecpar->extradata ||
st->codecpar->codec_id == AV_CODEC_ID_AAC ||
             st->codecpar->codec_id == AV_CODEC_ID_H264 ||
st->codecpar->codec_id == AV_CODEC_ID_HEVC ||
-            st->codecpar->codec_id == AV_CODEC_ID_AV1 ||
st->codecpar->codec_id == AV_CODEC_ID_VP9)) {
+            st->codecpar->codec_id == AV_CODEC_ID_AV1 ||
st->codecpar->codec_id == AV_CODEC_ID_VP9 ||
+            st->codecpar->codec_id == AV_CODEC_ID_VP8)) {
             AVDictionaryEntry *t;

             if (st->codecpar->extradata) {
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index f34df61c0e..32678e3136 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -54,6 +54,7 @@  static const AVCodecTag flv_video_codec_ids[] = {
     { AV_CODEC_ID_H264,     FLV_CODECID_H264 },
     { AV_CODEC_ID_HEVC,     MKBETAG('h', 'v', 'c', '1') },
     { AV_CODEC_ID_AV1,      MKBETAG('a', 'v', '0', '1') },
+    { AV_CODEC_ID_VP8,      MKBETAG('v', 'p', '0', '8') },
     { AV_CODEC_ID_VP9,      MKBETAG('v', 'p', '0', '9') },
     { AV_CODEC_ID_NONE,     0 }
 };
@@ -497,7 +498,7 @@  static void
flv_write_metadata_packet(AVFormatContext *s, AVCodecParameters *par

     if (flv->metadata_pkt_written) return;
     if (par->codec_id == AV_CODEC_ID_HEVC || par->codec_id ==
AV_CODEC_ID_AV1 ||
-        par->codec_id == AV_CODEC_ID_VP9) {
+        par->codec_id == AV_CODEC_ID_VP8 || par->codec_id == AV_CODEC_ID_VP9) {
         int flags_size = 5;