Unified · Split
| @@ -493,6 +493,45 @@ static void write_metadata(AVFormatContext *s, unsigned int ts) · 492 unmodified lines | ||
| 493 | 493 | avio_wb32(pb, flv->metadata_totalsize + 11); |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | +static void write_codec_fourcc(AVIOContext *pb, enum AVCodecID codec_id) | |
| 497 | +{ | |
| 498 | + switch (codec_id) { | |
| 499 | + case AV_CODEC_ID_AAC: | |
| 500 | + avio_write(pb, "mp4a", 4); | |
| 501 | + return; | |
| 502 | + case AV_CODEC_ID_OPUS: | |
| 503 | + avio_write(pb, "Opus", 4); | |
| 504 | + return; | |
| 505 | + case AV_CODEC_ID_FLAC: | |
| 506 | + avio_write(pb, "fLaC", 4); | |
| 507 | + return; | |
| 508 | + case AV_CODEC_ID_MP3: | |
| 509 | + avio_write(pb, ".mp3", 4); | |
| 510 | + return; | |
| 511 | + case AV_CODEC_ID_AC3: | |
| 512 | + avio_write(pb, "ac-3", 4); | |
| 513 | + return; | |
| 514 | + case AV_CODEC_ID_EAC3: | |
| 515 | + avio_write(pb, "ec-3", 4); | |
| 516 | + return; | |
| 517 | + case AV_CODEC_ID_H264: | |
| 518 | + avio_write(pb, "avc1", 4); | |
| 519 | + return; | |
| 520 | + case AV_CODEC_ID_HEVC: | |
| 521 | + avio_write(pb, "hvc1", 4); | |
| 522 | + return; | |
| 523 | + case AV_CODEC_ID_AV1: | |
| 524 | + avio_write(pb, "av01", 4); | |
| 525 | + return; | |
| 526 | + case AV_CODEC_ID_VP9: | |
| 527 | + avio_write(pb, "vp09", 4); | |
| 528 | + return; | |
| 529 | + default: | |
| 530 | + av_log(NULL, AV_LOG_ERROR, "Invalid codec FourCC write requested.\n"); | |
| 531 | + av_assert0(0); | |
| 532 | + } | |
| 533 | +} | |
| 534 | + | |
| 496 | 535 | static void flv_write_metadata_packet(AVFormatContext *s, AVCodecParameters *par, unsigned int ts, int stream_idx) |
| 497 | 536 | { |
| 498 | 537 | AVIOContext *pb = s->pb; |
| @@ -529,13 +568,8 @@ static void flv_write_metadata_packet(AVFormatContext *s, AVCodecParameters *par · 30 unmodified lines | ||
| 529 | 568 | put_timestamp(pb, ts); //ts = pkt->dts, gen |
| 530 | 569 | avio_wb24(pb, flv->reserved); |
| 531 | 570 | |
| 532 | − if (par->codec_id == AV_CODEC_ID_HEVC) { | |
| 533 | − avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeMetadata| FLV_FRAME_VIDEO_INFO_CMD); // ExVideoTagHeader mode with PacketTypeMetadata | |
| 534 | − avio_write(pb, "hvc1", 4); | |
| 535 | − } else if (par->codec_id == AV_CODEC_ID_AV1 || par->codec_id == AV_CODEC_ID_VP9) { | |
| 536 | − avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeMetadata| FLV_FRAME_VIDEO_INFO_CMD); | |
| 537 | − avio_write(pb, par->codec_id == AV_CODEC_ID_AV1 ? "av01" : "vp09", 4); | |
| 538 | − } | |
| 571 | + avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeMetadata | FLV_FRAME_VIDEO_INFO_CMD); // ExVideoTagHeader mode with PacketTypeMetadata | |
| 572 | + write_codec_fourcc(pb, par->codec_id); | |
| 539 | 573 | |
| 540 | 574 | avio_w8(pb, AMF_DATA_TYPE_STRING); |
| 541 | 575 | put_amf_string(pb, "colorInfo"); |
| @@ -704,24 +738,14 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i · 162 unmodified lines | ||
| 704 | 738 | |
| 705 | 739 | if (extended_flv) { |
| 706 | 740 | avio_w8(pb, FLV_CODECID_EX_HEADER | AudioPacketTypeSequenceStart); |
| 741 | + write_codec_fourcc(pb, par->codec_id); | |
| 707 | 742 | |
| 708 | 743 | if (par->codec_id == AV_CODEC_ID_AAC) { |
| 709 | − avio_write(pb, "mp4a", 4); | |
| 710 | 744 | flv_write_aac_header(s, par); |
| 711 | − } else if (par->codec_id == AV_CODEC_ID_OPUS) { | |
| 712 | − avio_write(pb, "Opus", 4); | |
| 745 | + } else if (par->codec_id == AV_CODEC_ID_OPUS || par->codec_id == AV_CODEC_ID_FLAC) { | |
| 713 | 746 | av_assert0(par->extradata_size); |
| 714 | 747 | avio_write(pb, par->extradata, par->extradata_size); |
| 715 | − } else if (par->codec_id == AV_CODEC_ID_FLAC) { | |
| 716 | − avio_write(pb, "fLaC", 4); | |
| 717 | − av_assert0(par->extradata_size); | |
| 718 | − avio_write(pb, par->extradata, par->extradata_size); | |
| 719 | − } else if (par->codec_id == AV_CODEC_ID_MP3) | |
| 720 | − avio_write(pb, ".mp3", 4); | |
| 721 | − else if (par->codec_id == AV_CODEC_ID_AC3) | |
| 722 | − avio_write(pb, "ac-3", 4); | |
| 723 | − else if (par->codec_id == AV_CODEC_ID_EAC3) | |
| 724 | − avio_write(pb, "ec-3", 4); | |
| 748 | + } | |
| 725 | 749 | } else if (par->codec_id == AV_CODEC_ID_AAC) { |
| 726 | 750 | avio_w8(pb, get_audio_flags(s, par)); |
| 727 | 751 | avio_w8(pb, 0); // AAC sequence header |
| @@ -744,14 +768,7 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i · 16 unmodified lines | ||
| 744 | 768 | avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeSequenceStart | FLV_FRAME_KEY); |
| 745 | 769 | } |
| 746 | 770 | |
| 747 | − if (par->codec_id == AV_CODEC_ID_H264) | |
| 748 | − avio_write(pb, "avc1", 4); | |
| 749 | − else if (par->codec_id == AV_CODEC_ID_HEVC) | |
| 750 | − avio_write(pb, "hvc1", 4); | |
| 751 | − else if (par->codec_id == AV_CODEC_ID_AV1) | |
| 752 | − avio_write(pb, "av01", 4); | |
| 753 | − else if (par->codec_id == AV_CODEC_ID_VP9) | |
| 754 | − avio_write(pb, "vp09", 4); | |
| 771 | + write_codec_fourcc(pb, par->codec_id); | |
| 755 | 772 | |
| 756 | 773 | if (track_idx) |
| 757 | 774 | avio_w8(pb, track_idx); |
| @@ -1243,14 +1260,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) · 485 unmodified lines | ||
| 1243 | 1260 | avio_w8(pb, FLV_IS_EX_HEADER | pkttype | frametype); |
| 1244 | 1261 | } |
| 1245 | 1262 | |
| 1246 | − if (par->codec_id == AV_CODEC_ID_H264) | |
| 1247 | − avio_write(pb, "avc1", 4); | |
| 1248 | − else if (par->codec_id == AV_CODEC_ID_HEVC) | |
| 1249 | − avio_write(pb, "hvc1", 4); | |
| 1250 | − else if (par->codec_id == AV_CODEC_ID_AV1) | |
| 1251 | − avio_write(pb, "av01", 4); | |
| 1252 | − else if (par->codec_id == AV_CODEC_ID_VP9) | |
| 1253 | − avio_write(pb, "vp09", 4); | |
| 1263 | + write_codec_fourcc(pb, par->codec_id); | |
| 1254 | 1264 | |
| 1255 | 1265 | if (track_idx) |
| 1256 | 1266 | avio_w8(pb, track_idx); |
| @@ -1258,19 +1268,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) · 1 unmodified line | ||
| 1258 | 1268 | avio_wb24(pb, pkt->pts - pkt->dts); |
| 1259 | 1269 | } else if (extended_audio) { |
| 1260 | 1270 | avio_w8(pb, FLV_CODECID_EX_HEADER | AudioPacketTypeCodedFrames); |
| 1261 | − | |
| 1262 | − if (par->codec_id == AV_CODEC_ID_AAC) | |
| 1263 | − avio_write(pb, "mp4a", 4); | |
| 1264 | − else if (par->codec_id == AV_CODEC_ID_OPUS) | |
| 1265 | − avio_write(pb, "Opus", 4); | |
| 1266 | − else if (par->codec_id == AV_CODEC_ID_FLAC) | |
| 1267 | − avio_write(pb, "fLaC", 4); | |
| 1268 | − else if (par->codec_id == AV_CODEC_ID_MP3) | |
| 1269 | − avio_write(pb, ".mp3", 4); | |
| 1270 | − else if (par->codec_id == AV_CODEC_ID_AC3) | |
| 1271 | − avio_write(pb, "ac-3", 4); | |
| 1272 | − else if (par->codec_id == AV_CODEC_ID_EAC3) | |
| 1273 | − avio_write(pb, "ec-3", 4); | |
| 1271 | + write_codec_fourcc(pb, par->codec_id); | |
| 1274 | 1272 | } else { |
| 1275 | 1273 | av_assert1(flags >= 0); |
| 1276 | 1274 | avio_w8(pb, flags); |