* [FFmpeg-devel] [PATCH v3 1/5] avformat/mov: fix ISO/IEC 23003-5 support [not found] <20230306120211.1249250-1-quinkblack@foxmail.com> @ 2023-03-06 12:02 ` Zhao Zhili 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 2/5] avformat/isom_tags: remove ipcm from movaudio_tags Zhao Zhili ` (3 subsequent siblings) 4 siblings, 0 replies; 10+ messages in thread From: Zhao Zhili @ 2023-03-06 12:02 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili From: Zhao Zhili <zhilizhao@tencent.com> Missing floating-point formats support. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> --- libavformat/isom.h | 2 ++ libavformat/mov.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/libavformat/isom.h b/libavformat/isom.h index 5107b4eb74..4b1cd42f0f 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -418,6 +418,8 @@ static inline enum AVCodecID ff_mov_get_lpcm_codec_id(int bps, int flags) #define MOV_ISMV_TTML_TAG MKTAG('d', 'f', 'x', 'p') #define MOV_MP4_TTML_TAG MKTAG('s', 't', 'p', 'p') +#define MOV_MP4_FPCM_TAG MKTAG('f', 'p', 'c', 'm') +#define MOV_MP4_IPCM_TAG MKTAG('i', 'p', 'c', 'm') struct MP4TrackKindValueMapping { int disposition; diff --git a/libavformat/mov.c b/libavformat/mov.c index a9911c0f79..14528bdcaa 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1591,6 +1591,10 @@ static int mov_read_pcmc(MOVContext *c, AVIOContext *pb, MOVAtom atom) { int format_flags; int version, flags; + int pcm_sample_size; + AVFormatContext *fc = c->fc; + AVStream *st; + MOVStreamContext *sc; if (atom.size < 6) { av_log(c->fc, AV_LOG_ERROR, "Empty pcmC box\n"); @@ -1608,6 +1612,51 @@ static int mov_read_pcmc(MOVContext *c, AVIOContext *pb, MOVAtom atom) } format_flags = avio_r8(pb); + pcm_sample_size = avio_r8(pb); + + if (fc->nb_streams < 1) + return AVERROR_INVALIDDATA; + + st = fc->streams[fc->nb_streams - 1]; + sc = st->priv_data; + + if (sc->format == MOV_MP4_FPCM_TAG) { + switch (pcm_sample_size) { + case 32: + st->codecpar->codec_id = AV_CODEC_ID_PCM_F32BE; + break; + case 64: + st->codecpar->codec_id = AV_CODEC_ID_PCM_F64BE; + break; + default: + av_log(fc, AV_LOG_ERROR, "invalid pcm_sample_size %d for %s\n", + pcm_sample_size, + av_fourcc2str(sc->format)); + return AVERROR_INVALIDDATA; + } + } else if (sc->format == MOV_MP4_IPCM_TAG) { + switch (pcm_sample_size) { + case 16: + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE; + break; + case 24: + st->codecpar->codec_id = AV_CODEC_ID_PCM_S24BE; + break; + case 32: + st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE; + break; + default: + av_log(fc, AV_LOG_ERROR, "invalid pcm_sample_size %d for %s\n", + pcm_sample_size, + av_fourcc2str(sc->format)); + return AVERROR_INVALIDDATA; + } + } else { + av_log(fc, AV_LOG_ERROR, "'pcmC' with invalid sample entry '%s'\n", + av_fourcc2str(sc->format)); + return AVERROR_INVALIDDATA; + } + if (format_flags & 1) // indicates little-endian format. If not present, big-endian format is used set_last_stream_little_endian(c->fc); -- 2.25.1 _______________________________________________ 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH v3 2/5] avformat/isom_tags: remove ipcm from movaudio_tags [not found] <20230306120211.1249250-1-quinkblack@foxmail.com> 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 1/5] avformat/mov: fix ISO/IEC 23003-5 support Zhao Zhili @ 2023-03-06 12:02 ` Zhao Zhili 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 3/5] avformat/mov: parse ISO-14496-12 ChannelLayout Zhao Zhili ` (2 subsequent siblings) 4 siblings, 0 replies; 10+ messages in thread From: Zhao Zhili @ 2023-03-06 12:02 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili From: Zhao Zhili <zhilizhao@tencent.com> ipcm is defined by ISO/IEC 23003-5, not defined by quicktime. After adding ISO/IEC 23003-5 support, we don't need it for ticket #9219. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> --- libavformat/isom_tags.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavformat/isom_tags.c b/libavformat/isom_tags.c index e2b80405cc..86c7272525 100644 --- a/libavformat/isom_tags.c +++ b/libavformat/isom_tags.c @@ -321,8 +321,6 @@ const AVCodecTag ff_codec_movaudio_tags[] = { { AV_CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, { AV_CODEC_ID_PCM_S16BE, MKTAG('l', 'p', 'c', 'm') }, { AV_CODEC_ID_PCM_S16LE, MKTAG('l', 'p', 'c', 'm') }, - { AV_CODEC_ID_PCM_S16BE, MKTAG('i', 'p', 'c', 'm') }, - { AV_CODEC_ID_PCM_S16LE, MKTAG('i', 'p', 'c', 'm') }, { AV_CODEC_ID_PCM_S24BE, MKTAG('i', 'n', '2', '4') }, { AV_CODEC_ID_PCM_S24LE, MKTAG('i', 'n', '2', '4') }, { AV_CODEC_ID_PCM_S32BE, MKTAG('i', 'n', '3', '2') }, -- 2.25.1 _______________________________________________ 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH v3 3/5] avformat/mov: parse ISO-14496-12 ChannelLayout [not found] <20230306120211.1249250-1-quinkblack@foxmail.com> 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 1/5] avformat/mov: fix ISO/IEC 23003-5 support Zhao Zhili 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 2/5] avformat/isom_tags: remove ipcm from movaudio_tags Zhao Zhili @ 2023-03-06 12:02 ` Zhao Zhili 2023-03-06 12:26 ` Tomas Härdin 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 4/5] avformat/movenc: add PCM in mp4 support Zhao Zhili 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 5/5] fate/mov: add PCM in mp4 test Zhao Zhili 4 siblings, 1 reply; 10+ messages in thread From: Zhao Zhili @ 2023-03-06 12:02 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili From: Zhao Zhili <zhilizhao@tencent.com> Only support chnl version 0 now. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> --- libavformat/mov.c | 85 +++++++++++- libavformat/mov_chan.c | 296 +++++++++++++++++++++++++++++++++++++++++ libavformat/mov_chan.h | 26 ++++ 3 files changed, 406 insertions(+), 1 deletion(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 14528bdcaa..057fd872b1 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -940,6 +940,88 @@ static int mov_read_chan(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; } +static int mov_read_chnl(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + int64_t end = av_sat_add64(avio_tell(pb), atom.size); + int stream_structure; + int version, flags; + int ret = 0; + AVStream *st; + + if (c->fc->nb_streams < 1) + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + + version = avio_r8(pb); + flags = avio_rb24(pb); + if (version != 0 || flags != 0) { + av_log(c->fc, AV_LOG_ERROR, + "Unsupported 'chnl' box with version %d, flags: %#x", + version, flags); + return AVERROR_INVALIDDATA; + } + + stream_structure = avio_r8(pb); + + // stream carries channels + if (stream_structure & 1) { + int layout = avio_r8(pb); + + av_log(c->fc, AV_LOG_TRACE, "'chnl' layout %d\n", layout); + if (!layout) { + uint8_t *positions = av_malloc(st->codecpar->ch_layout.nb_channels); + + if (!positions) + return AVERROR(ENOMEM); + for (int i = 0; i < st->codecpar->ch_layout.nb_channels; i++) { + int speaker_pos = avio_r8(pb); + + av_log(c->fc, AV_LOG_TRACE, "speaker_position %d\n", speaker_pos); + if (speaker_pos == 126) { // explicit position + avpriv_request_sample(c->fc, "explicit position"); + av_freep(&positions); + return AVERROR_PATCHWELCOME; + } else { + positions[i] = speaker_pos; + } + } + + ret = ff_mov_get_layout_from_channel_positions(positions, + st->codecpar->ch_layout.nb_channels, + &st->codecpar->ch_layout); + av_freep(&positions); + if (ret) { + av_log(c->fc, AV_LOG_ERROR, + "get channel layout from speaker positions failed, %s\n", + av_err2str(ret)); + return ret; + } + } else { + uint64_t omitted_channel_map = avio_rb64(pb); + + if (omitted_channel_map) { + avpriv_request_sample(c->fc, "omitted_channel_map 0x%" PRIx64 " != 0", + omitted_channel_map); + return AVERROR_PATCHWELCOME; + } + ff_mov_get_channel_layout_from_config(layout, &st->codecpar->ch_layout); + } + } + + // stream carries objects + if (stream_structure & 2) { + int obj_count = avio_r8(pb); + av_log(c->fc, AV_LOG_TRACE, "'chnl' with object_count %d\n", obj_count); + } + + if (avio_tell(pb) != end) { + av_log(c->fc, AV_LOG_WARNING, "skip %" PRId64 " bytes of unknown data inside chnl\n", + end - avio_tell(pb)); + avio_seek(pb, end, SEEK_SET); + } + return ret; +} + static int mov_read_wfex(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; @@ -7817,7 +7899,8 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('w','i','d','e'), mov_read_wide }, /* place holder */ { MKTAG('w','f','e','x'), mov_read_wfex }, { MKTAG('c','m','o','v'), mov_read_cmov }, -{ MKTAG('c','h','a','n'), mov_read_chan }, /* channel layout */ +{ MKTAG('c','h','a','n'), mov_read_chan }, /* channel layout from quicktime */ +{ MKTAG('c','h','n','l'), mov_read_chnl }, /* channel layout from ISO-14496-12 */ { MKTAG('d','v','c','1'), mov_read_dvc1 }, { MKTAG('s','g','p','d'), mov_read_sgpd }, { MKTAG('s','b','g','p'), mov_read_sbgp }, diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index f66bf0df7f..df17976e59 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -551,3 +551,299 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, return 0; } + +/* ISO/IEC 23001-8, 8.2 */ +static const AVChannelLayout iso_channel_configuration[] = { + // 0: any setup + {}, + + // 1: centre front + AV_CHANNEL_LAYOUT_MONO, + + // 2: left front, right front + AV_CHANNEL_LAYOUT_STEREO, + + // 3: centre front, left front, right front + AV_CHANNEL_LAYOUT_SURROUND, + + // 4: centre front, left front, right front, rear centre + AV_CHANNEL_LAYOUT_4POINT0, + + // 5: centre front, left front, right front, left surround, right surround + AV_CHANNEL_LAYOUT_5POINT0, + + // 6: 5 + LFE + AV_CHANNEL_LAYOUT_5POINT1, + + // 7: centre front, left front centre, right front centre, + // left front, right front, left surround, right surround, LFE + AV_CHANNEL_LAYOUT_7POINT1_WIDE, + + // 8: channel1, channel2 + AV_CHANNEL_LAYOUT_STEREO_DOWNMIX, + + // 9: left front, right front, rear centre + AV_CHANNEL_LAYOUT_2_1, + + // 10: left front, right front, left surround, right surround + AV_CHANNEL_LAYOUT_2_2, + + // 11: centre front, left front, right front, left surround, right surround, rear centre, LFE + AV_CHANNEL_LAYOUT_6POINT1, + + // 12: centre front, left front, right front + // left surround, right surround + // rear surround left, rear surround right + // LFE + AV_CHANNEL_LAYOUT_7POINT1, + + // 13: + AV_CHANNEL_LAYOUT_22POINT2, + + // 14: + AV_CHANNEL_LAYOUT_7POINT1_TOP_BACK, + + // TODO: 15 - 20 +}; + +/* ISO/IEC 23001-8, table 8 */ +static const enum AVChannel iso_channel_position[] = { + // 0: left front + AV_CHAN_FRONT_LEFT, + + // 1: right front + AV_CHAN_FRONT_RIGHT, + + // 2: centre front + AV_CHAN_FRONT_CENTER, + + // 3: low frequence enhancement + AV_CHAN_LOW_FREQUENCY, + + // 4: left surround + // TODO + AV_CHAN_NONE, + + // 5: right surround + // TODO + AV_CHAN_NONE, + + // 6: left front centre + AV_CHAN_FRONT_LEFT_OF_CENTER, + + // 7: right front centre + AV_CHAN_FRONT_RIGHT_OF_CENTER, + + // 8: rear surround left + AV_CHAN_BACK_LEFT, + + // 9: rear surround right + AV_CHAN_BACK_RIGHT, + + // 10: rear centre + AV_CHAN_BACK_CENTER, + + // 11: left surround direct + AV_CHAN_SURROUND_DIRECT_LEFT, + + // 12: right surround direct + AV_CHAN_SURROUND_DIRECT_RIGHT, + + // 13: left side surround + AV_CHAN_SIDE_LEFT, + + // 14: right side surround + AV_CHAN_SIDE_RIGHT, + + // 15: left wide front + AV_CHAN_WIDE_LEFT, + + // 16: right wide front + AV_CHAN_WIDE_RIGHT, + + // 17: left front vertical height + AV_CHAN_TOP_FRONT_LEFT, + + // 18: right front vertical height + AV_CHAN_TOP_FRONT_RIGHT, + + // 19: centre front vertical height + AV_CHAN_TOP_FRONT_CENTER, + + // 20: left surround vertical height rear + AV_CHAN_TOP_BACK_LEFT, + + // 21: right surround vertical height rear + AV_CHAN_TOP_BACK_RIGHT, + + // 22: centre vertical height rear + AV_CHAN_TOP_BACK_CENTER, + + // 23: left vertical height side surround + AV_CHAN_TOP_SIDE_LEFT, + + // 24: right vertical height side surround + AV_CHAN_TOP_SIDE_RIGHT, + + // 25: top centre surround + AV_CHAN_TOP_CENTER, + + // 26: low frequency enhancement 2 + AV_CHAN_LOW_FREQUENCY_2, + + // 27: left front vertical bottom + AV_CHAN_BOTTOM_FRONT_LEFT, + + // 28: right front vertical bottom + AV_CHAN_BOTTOM_FRONT_RIGHT, + + // 29: centre front vertical bottom + AV_CHAN_BOTTOM_FRONT_CENTER, + + // 30: left vertical height surround + // TODO + AV_CHAN_NONE, + + // 31: right vertical height surround + // TODO + AV_CHAN_NONE, + + // 32, 33, 34, 35, reserved + AV_CHAN_NONE, + AV_CHAN_NONE, + AV_CHAN_NONE, + AV_CHAN_NONE, + + // 36: low frequency enhancement 3 + AV_CHAN_NONE, + + // 37: left edge of screen + AV_CHAN_NONE, + // 38: right edge of screen + AV_CHAN_NONE, + // 39: half-way between centre of screen and left edge of screen + AV_CHAN_NONE, + // 40: half-way between centre of screen and right edge of screen + AV_CHAN_NONE, + + // 41: left back surround + AV_CHAN_NONE, + + // 42: right back surround + AV_CHAN_NONE, + + // 43 - 125: reserved + // 126: explicit position + // 127: unknown /undefined +}; + +int ff_mov_get_channel_config_from_layout(const AVChannelLayout *layout, int *config) +{ + // Set default value which means any setup in 23001-8 + *config = 0; + for (int i = 0; i < FF_ARRAY_ELEMS(iso_channel_configuration); i++) { + if (!av_channel_layout_compare(layout, iso_channel_configuration + i)) { + *config = i; + break; + } + } + + return 0; +} + +int ff_mov_get_channel_layout_from_config(int config, AVChannelLayout *layout) +{ + if (config > 0 && config < FF_ARRAY_ELEMS(iso_channel_configuration)) { + av_channel_layout_copy(layout, &iso_channel_configuration[config]); + return 0; + } + + return -1; +} + +int ff_mov_get_channel_positions_from_layout(const AVChannelLayout *layout, + uint8_t *position, int position_num) +{ + enum AVChannel channel; + + if (position_num < layout->nb_channels) + return AVERROR(EINVAL); + + for (int i = 0; i < layout->nb_channels; i++) { + position[i] = 127; + channel = av_channel_layout_channel_from_index(layout, i); + if (channel == AV_CHAN_NONE) + return AVERROR(EINVAL); + + for (int j = 0; j < FF_ARRAY_ELEMS(iso_channel_position); j++) { + if (iso_channel_position[j] == channel) { + position[i] = j; + break; + } + } + if (position[i] == 127) + return AVERROR(EINVAL); + } + + return 0; +} + +int ff_mov_get_layout_from_channel_positions(const uint8_t *position, int position_num, + AVChannelLayout *layout) +{ + int ret; + enum AVChannel channel; + + av_channel_layout_uninit(layout); + + if (position_num <= 63) { + layout->order = AV_CHANNEL_ORDER_NATIVE; + layout->nb_channels = position_num; + for (int i = 0; i < position_num; i++) { + if (position[i] >= FF_ARRAY_ELEMS(iso_channel_position)) { + ret = AVERROR_PATCHWELCOME; + goto error; + } + + channel = iso_channel_position[position[i]]; + // unsupported layout + if (channel == AV_CHAN_NONE) { + ret = AVERROR_PATCHWELCOME; + goto error; + } + + layout->u.mask |= 1ULL << channel; + } + } else { + layout->order = AV_CHANNEL_ORDER_CUSTOM; + layout->nb_channels = position_num; + layout->u.map = av_calloc(position_num, sizeof(*layout->u.map)); + if (!layout->u.map) { + ret = AVERROR(ENOMEM); + goto error; + } + + for (int i = 0; i < position_num; i++) { + if (position[i] >= FF_ARRAY_ELEMS(iso_channel_position)) { + ret = AVERROR_PATCHWELCOME; + goto error; + } + + channel = iso_channel_position[position[i]]; + // unsupported layout + if (channel == AV_CHAN_NONE) { + ret = AVERROR_PATCHWELCOME; + goto error; + } + + layout->u.map[i].id = channel; + } + } + + + return 0; + +error: + av_channel_layout_uninit(layout); + return ret; +} diff --git a/libavformat/mov_chan.h b/libavformat/mov_chan.h index 93d9878798..8c807798ab 100644 --- a/libavformat/mov_chan.h +++ b/libavformat/mov_chan.h @@ -163,4 +163,30 @@ int ff_mov_get_channel_layout_tag(const AVCodecParameters *par, int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, int64_t size); +/** + * Get ISO/IEC 23001-8 ChannelConfiguration from AVChannelLayout. + * + */ +int ff_mov_get_channel_config_from_layout(const AVChannelLayout *layout, int *config); + +/** + * Get AVChannelLayout from ISO/IEC 23001-8 ChannelConfiguration. + * + * @return 0 for success, -1 for doesn't match, layout is untouched on failure + */ + +int ff_mov_get_channel_layout_from_config(int config, AVChannelLayout *layout); + +/** + * Get ISO/IEC 23001-8 OutputChannelPosition from AVChannelLayout. + */ +int ff_mov_get_channel_positions_from_layout(const AVChannelLayout *layout, + uint8_t *position, int position_num); + +/** + * Get AVChannelLayout from ISO/IEC 23001-8 OutputChannelPosition. + */ +int ff_mov_get_layout_from_channel_positions(const uint8_t *position, int position_num, + AVChannelLayout *layout); + #endif /* AVFORMAT_MOV_CHAN_H */ -- 2.25.1 _______________________________________________ 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 3/5] avformat/mov: parse ISO-14496-12 ChannelLayout 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 3/5] avformat/mov: parse ISO-14496-12 ChannelLayout Zhao Zhili @ 2023-03-06 12:26 ` Tomas Härdin 2023-03-07 2:27 ` "zhilizhao(赵志立)" 0 siblings, 1 reply; 10+ messages in thread From: Tomas Härdin @ 2023-03-06 12:26 UTC (permalink / raw) To: FFmpeg development discussions and patches > +int ff_mov_get_channel_config_from_layout(const AVChannelLayout > *layout, int *config) > +{ > + // Set default value which means any setup in 23001-8 > + *config = 0; > + for (int i = 0; i < FF_ARRAY_ELEMS(iso_channel_configuration); > i++) { > + if (!av_channel_layout_compare(layout, > iso_channel_configuration + i)) { > + *config = i; > + break; > + } > + } > + > + return 0; Is always returning 0 intended? If so then what is the point? ff_mov_get_channel_positions_from_layout() returns non-zero on error.. /Tomas _______________________________________________ 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 3/5] avformat/mov: parse ISO-14496-12 ChannelLayout 2023-03-06 12:26 ` Tomas Härdin @ 2023-03-07 2:27 ` "zhilizhao(赵志立)" 0 siblings, 0 replies; 10+ messages in thread From: "zhilizhao(赵志立)" @ 2023-03-07 2:27 UTC (permalink / raw) To: FFmpeg development discussions and patches > On Mar 6, 2023, at 20:26, Tomas Härdin <git@haerdin.se> wrote: > >> +int ff_mov_get_channel_config_from_layout(const AVChannelLayout >> *layout, int *config) >> +{ >> + // Set default value which means any setup in 23001-8 >> + *config = 0; >> + for (int i = 0; i < FF_ARRAY_ELEMS(iso_channel_configuration); >> i++) { >> + if (!av_channel_layout_compare(layout, >> iso_channel_configuration + i)) { >> + *config = i; >> + break; >> + } >> + } >> + >> + return 0; > > Is always returning 0 intended? If so then what is the point? > ff_mov_get_channel_positions_from_layout() returns non-zero on error.. As the comments says, ChannelConfiguration 0 means “any setup”. If no iso_channel_configuration item match layout, *config get 0 as a valid value. Current implementation of the function doesn’t fail, but it might in future. > > /Tomas > > _______________________________________________ > 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". _______________________________________________ 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH v3 4/5] avformat/movenc: add PCM in mp4 support [not found] <20230306120211.1249250-1-quinkblack@foxmail.com> ` (2 preceding siblings ...) 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 3/5] avformat/mov: parse ISO-14496-12 ChannelLayout Zhao Zhili @ 2023-03-06 12:02 ` Zhao Zhili 2023-03-06 12:28 ` Tomas Härdin 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 5/5] fate/mov: add PCM in mp4 test Zhao Zhili 4 siblings, 1 reply; 10+ messages in thread From: Zhao Zhili @ 2023-03-06 12:02 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili From: Zhao Zhili <zhilizhao@tencent.com> It's defined by ISO/IEC 23003-5. Fixes ticket #10185 Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> --- libavformat/movenc.c | 84 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index c4fcb5f8b1..2ec575c954 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -1179,6 +1179,68 @@ static int mov_write_btrt_tag(AVIOContext *pb, MOVTrack *track) return update_size(pb, pos); } +static int mov_write_chnl_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) +{ + int64_t pos = avio_tell(pb); + int config = 0; + int ret; + uint8_t *speaker_pos = NULL; + const AVChannelLayout *layout = &track->par->ch_layout; + + ret = ff_mov_get_channel_config_from_layout(layout, &config); + if (ret || !config) { + config = 0; + speaker_pos = av_malloc(layout->nb_channels); + ret = ff_mov_get_channel_positions_from_layout(layout, + speaker_pos, layout->nb_channels); + if (ret) { + char buf[128] = {}; + + av_freep(&speaker_pos); + av_channel_layout_describe(layout, buf, sizeof(buf)); + av_log(s, AV_LOG_ERROR, "unsupported channel layout %s\n", buf); + return ret; + } + } + + avio_wb32(pb, 0); /* size */ + ffio_wfourcc(pb, "chnl"); + avio_wb32(pb, 0); /* version & flags */ + + avio_w8(pb, 1); /* stream_structure */ + avio_w8(pb, config); + if (config) { + avio_wb64(pb, 0); + } else { + for (int i = 0; i < layout->nb_channels; i++) + avio_w8(pb, speaker_pos[i]); + av_freep(&speaker_pos); + } + + return update_size(pb, pos); +} + +static int mov_write_pcmc_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) +{ + int64_t pos = avio_tell(pb); + int format_flags; + + avio_wb32(pb, 0); /* size */ + ffio_wfourcc(pb, "pcmC"); + avio_wb32(pb, 0); /* version & flags */ + + /* 0x01: indicates little-endian format */ + format_flags = (track->par->codec_id == AV_CODEC_ID_PCM_F32LE || + track->par->codec_id == AV_CODEC_ID_PCM_F64LE || + track->par->codec_id == AV_CODEC_ID_PCM_S16LE || + track->par->codec_id == AV_CODEC_ID_PCM_S24LE || + track->par->codec_id == AV_CODEC_ID_PCM_S32LE); + avio_w8(pb, format_flags); + avio_w8(pb, track->par->bits_per_raw_sample); + + return update_size(pb, pos); +} + static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track) { int64_t pos = avio_tell(pb); @@ -1305,7 +1367,13 @@ static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex ret = mov_write_dops_tag(s, pb, track); else if (track->par->codec_id == AV_CODEC_ID_TRUEHD) ret = mov_write_dmlp_tag(s, pb, track); - else if (track->vos_len > 0) + else if (tag == MOV_MP4_IPCM_TAG || tag == MOV_MP4_FPCM_TAG) { + if (track->par->ch_layout.nb_channels > 1) + ret = mov_write_chnl_tag(s, pb, track); + if (ret < 0) + return ret; + ret = mov_write_pcmc_tag(s, pb, track); + } else if (track->vos_len > 0) ret = mov_write_glbl_tag(pb, track); if (ret < 0) @@ -7744,6 +7812,20 @@ static const AVCodecTag codec_mp4_tags[] = { { AV_CODEC_ID_MPEGH_3D_AUDIO, MKTAG('m', 'h', 'm', '1') }, { AV_CODEC_ID_TTML, MOV_MP4_TTML_TAG }, { AV_CODEC_ID_TTML, MOV_ISMV_TTML_TAG }, + + /* ISO/IEC 23003-5 integer formats */ + { AV_CODEC_ID_PCM_S16BE, MOV_MP4_IPCM_TAG }, + { AV_CODEC_ID_PCM_S16LE, MOV_MP4_IPCM_TAG }, + { AV_CODEC_ID_PCM_S24BE, MOV_MP4_IPCM_TAG }, + { AV_CODEC_ID_PCM_S24LE, MOV_MP4_IPCM_TAG }, + { AV_CODEC_ID_PCM_S32BE, MOV_MP4_IPCM_TAG }, + { AV_CODEC_ID_PCM_S32LE, MOV_MP4_IPCM_TAG }, + /* ISO/IEC 23003-5 floating-point formats */ + { AV_CODEC_ID_PCM_F32BE, MOV_MP4_FPCM_TAG }, + { AV_CODEC_ID_PCM_F32LE, MOV_MP4_FPCM_TAG }, + { AV_CODEC_ID_PCM_F64BE, MOV_MP4_FPCM_TAG }, + { AV_CODEC_ID_PCM_F64LE, MOV_MP4_FPCM_TAG }, + { AV_CODEC_ID_NONE, 0 }, }; #if CONFIG_MP4_MUXER || CONFIG_PSP_MUXER -- 2.25.1 _______________________________________________ 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 4/5] avformat/movenc: add PCM in mp4 support 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 4/5] avformat/movenc: add PCM in mp4 support Zhao Zhili @ 2023-03-06 12:28 ` Tomas Härdin 2023-03-07 2:30 ` "zhilizhao(赵志立)" 0 siblings, 1 reply; 10+ messages in thread From: Tomas Härdin @ 2023-03-06 12:28 UTC (permalink / raw) To: FFmpeg development discussions and patches > +static int mov_write_chnl_tag(AVFormatContext *s, AVIOContext *pb, > MOVTrack *track) > +{ > + int64_t pos = avio_tell(pb); > + int config = 0; > + int ret; > + uint8_t *speaker_pos = NULL; > + const AVChannelLayout *layout = &track->par->ch_layout; > + > + ret = ff_mov_get_channel_config_from_layout(layout, &config); > + if (ret || !config) { ret is always 0.. /Tomas _______________________________________________ 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 4/5] avformat/movenc: add PCM in mp4 support 2023-03-06 12:28 ` Tomas Härdin @ 2023-03-07 2:30 ` "zhilizhao(赵志立)" 2023-03-07 13:55 ` Tomas Härdin 0 siblings, 1 reply; 10+ messages in thread From: "zhilizhao(赵志立)" @ 2023-03-07 2:30 UTC (permalink / raw) To: FFmpeg development discussions and patches > On Mar 6, 2023, at 20:28, Tomas Härdin <git@haerdin.se> wrote: > >> +static int mov_write_chnl_tag(AVFormatContext *s, AVIOContext *pb, >> MOVTrack *track) >> +{ >> + int64_t pos = avio_tell(pb); >> + int config = 0; >> + int ret; >> + uint8_t *speaker_pos = NULL; >> + const AVChannelLayout *layout = &track->par->ch_layout; >> + >> + ret = ff_mov_get_channel_config_from_layout(layout, &config); >> + if (ret || !config) { > > ret is always 0.. That implementation details. It’s robust for caller to not depending on that. > > > /Tomas > > _______________________________________________ > 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". _______________________________________________ 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 4/5] avformat/movenc: add PCM in mp4 support 2023-03-07 2:30 ` "zhilizhao(赵志立)" @ 2023-03-07 13:55 ` Tomas Härdin 0 siblings, 0 replies; 10+ messages in thread From: Tomas Härdin @ 2023-03-07 13:55 UTC (permalink / raw) To: FFmpeg development discussions and patches tis 2023-03-07 klockan 10:30 +0800 skrev zhilizhao(赵志立): > > > > On Mar 6, 2023, at 20:28, Tomas Härdin <git@haerdin.se> wrote: > > > > > +static int mov_write_chnl_tag(AVFormatContext *s, AVIOContext > > > *pb, > > > MOVTrack *track) > > > +{ > > > + int64_t pos = avio_tell(pb); > > > + int config = 0; > > > + int ret; > > > + uint8_t *speaker_pos = NULL; > > > + const AVChannelLayout *layout = &track->par->ch_layout; > > > + > > > + ret = ff_mov_get_channel_config_from_layout(layout, > > > &config); > > > + if (ret || !config) { > > > > ret is always 0.. > > That implementation details. It’s robust for caller to not depending > on that. Fair enough /Tomas _______________________________________________ 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH v3 5/5] fate/mov: add PCM in mp4 test [not found] <20230306120211.1249250-1-quinkblack@foxmail.com> ` (3 preceding siblings ...) 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 4/5] avformat/movenc: add PCM in mp4 support Zhao Zhili @ 2023-03-06 12:02 ` Zhao Zhili 4 siblings, 0 replies; 10+ messages in thread From: Zhao Zhili @ 2023-03-06 12:02 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili From: Zhao Zhili <zhilizhao@tencent.com> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> --- tests/fate/mov.mak | 12 ++++++++++++ tests/filtergraphs/mov-mp4-pcm | 5 +++++ tests/ref/fate/mov-mp4-pcm | 27 +++++++++++++++++++++++++++ tests/ref/fate/mov-mp4-pcm-float | 7 +++++++ 4 files changed, 51 insertions(+) create mode 100644 tests/filtergraphs/mov-mp4-pcm create mode 100644 tests/ref/fate/mov-mp4-pcm create mode 100644 tests/ref/fate/mov-mp4-pcm-float diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak index 8a7218a215..d795445691 100644 --- a/tests/fate/mov.mak +++ b/tests/fate/mov.mak @@ -165,6 +165,18 @@ FATE_MOV_FFMPEG-$(call TRANSCODE, PCM_S16LE, MOV, WAV_DEMUXER PAN_FILTER) \ fate-mov-channel-description: tests/data/asynth-44100-1.wav tests/data/filtergraphs/mov-channel-description fate-mov-channel-description: CMD = transcode wav $(TARGET_PATH)/tests/data/asynth-44100-1.wav mov "-filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/mov-channel-description -map [outFL] -map [outFR] -map [outFC] -map [outLFE] -map [outBL] -map [outBR] -map [outDL] -map [outDR] -c:a pcm_s16le" "-map 0 -c copy -frames:a 0" +# Test PCM in mp4 and channel layout +FATE_MOV_FFMPEG-$(call TRANSCODE, PCM_S16LE, MOV, WAV_DEMUXER PAN_FILTER) \ + += fate-mov-mp4-pcm +fate-mov-mp4-pcm: tests/data/asynth-44100-1.wav tests/data/filtergraphs/mov-mp4-pcm +fate-mov-mp4-pcm: CMD = transcode wav $(TARGET_PATH)/tests/data/asynth-44100-1.wav mp4 "-filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/mov-mp4-pcm -map [mono] -map [stereo] -map [2.1] -map [5.1] -map [7.1] -c:a pcm_s16le" "-map 0 -c copy -frames:a 0" + +# Test floating sample format PCM in mp4 and unusual channel layout +FATE_MOV_FFMPEG-$(call TRANSCODE, PCM_S16LE, MOV, WAV_DEMUXER PAN_FILTER) \ + += fate-mov-mp4-pcm-float +fate-mov-mp4-pcm-float: tests/data/asynth-44100-1.wav +fate-mov-mp4-pcm-float: CMD = transcode wav $(TARGET_PATH)/tests/data/asynth-44100-1.wav mp4 "-af aresample,pan=FL+LFE+BR|c0=c0|c1=c0|c2=c0 -c:a pcm_f32le" "-map 0 -c copy -frames:a 0" + FATE_FFMPEG += $(FATE_MOV_FFMPEG-yes) fate-mov: $(FATE_MOV) $(FATE_MOV_FFMPEG-yes) $(FATE_MOV_FFPROBE) $(FATE_MOV_FASTSTART) $(FATE_MOV_FFMPEG_FFPROBE-yes) diff --git a/tests/filtergraphs/mov-mp4-pcm b/tests/filtergraphs/mov-mp4-pcm new file mode 100644 index 0000000000..7fa25a2c3c --- /dev/null +++ b/tests/filtergraphs/mov-mp4-pcm @@ -0,0 +1,5 @@ +[0:a:0]pan=mono|c0=c0[mono]; +[0:a:0]pan=stereo|c0=c0|c1=c0[stereo]; +[0:a:0]pan=2.1|c0=c0|c1=c0|c2=c0[2.1]; +[0:a:0]pan=5.1|c0=c0|c1=c0|c2=c0|c3=c0|c4=c0|c5=c0[5.1]; +[0:a:0]pan=7.1|c0=c0|c1=c0|c2=c0|c3=c0|c4=c0|c5=c0|c6=c0|c7=c0[7.1]; diff --git a/tests/ref/fate/mov-mp4-pcm b/tests/ref/fate/mov-mp4-pcm new file mode 100644 index 0000000000..b34f5e59e1 --- /dev/null +++ b/tests/ref/fate/mov-mp4-pcm @@ -0,0 +1,27 @@ +1573ecbd24a65a6ec23ef08a861614b3 *tests/data/fate/mov-mp4-pcm.mp4 +10589277 tests/data/fate/mov-mp4-pcm.mp4 +#tb 0: 1/44100 +#media_type 0: audio +#codec_id 0: pcm_s16le +#sample_rate 0: 44100 +#channel_layout_name 0: mono +#tb 1: 1/44100 +#media_type 1: audio +#codec_id 1: pcm_s16le +#sample_rate 1: 44100 +#channel_layout_name 1: stereo +#tb 2: 1/44100 +#media_type 2: audio +#codec_id 2: pcm_s16le +#sample_rate 2: 44100 +#channel_layout_name 2: 2.1 +#tb 3: 1/44100 +#media_type 3: audio +#codec_id 3: pcm_s16le +#sample_rate 3: 44100 +#channel_layout_name 3: 5.1 +#tb 4: 1/44100 +#media_type 4: audio +#codec_id 4: pcm_s16le +#sample_rate 4: 44100 +#channel_layout_name 4: 7.1 diff --git a/tests/ref/fate/mov-mp4-pcm-float b/tests/ref/fate/mov-mp4-pcm-float new file mode 100644 index 0000000000..851b79090c --- /dev/null +++ b/tests/ref/fate/mov-mp4-pcm-float @@ -0,0 +1,7 @@ +691a76a847e0f3720c09cca341971f19 *tests/data/fate/mov-mp4-pcm-float.mp4 +3175929 tests/data/fate/mov-mp4-pcm-float.mp4 +#tb 0: 1/44100 +#media_type 0: audio +#codec_id 0: pcm_f32le +#sample_rate 0: 44100 +#channel_layout_name 0: 3 channels (FL+LFE+BR) -- 2.25.1 _______________________________________________ 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". ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-03-07 13:55 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <20230306120211.1249250-1-quinkblack@foxmail.com> 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 1/5] avformat/mov: fix ISO/IEC 23003-5 support Zhao Zhili 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 2/5] avformat/isom_tags: remove ipcm from movaudio_tags Zhao Zhili 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 3/5] avformat/mov: parse ISO-14496-12 ChannelLayout Zhao Zhili 2023-03-06 12:26 ` Tomas Härdin 2023-03-07 2:27 ` "zhilizhao(赵志立)" 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 4/5] avformat/movenc: add PCM in mp4 support Zhao Zhili 2023-03-06 12:28 ` Tomas Härdin 2023-03-07 2:30 ` "zhilizhao(赵志立)" 2023-03-07 13:55 ` Tomas Härdin 2023-03-06 12:02 ` [FFmpeg-devel] [PATCH v3 5/5] fate/mov: add PCM in mp4 test Zhao Zhili
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git