Commit 7196b12b authored by Marton Balint's avatar Marton Balint

avformat/daudenc: force 2000 sample packet size with a bsf

The samples I found all have 2000 sample packets, and by forcing the packet
size with a bsf we could automagically make muxing work for packets containing
more than 3640 samples.
Signed-off-by: 's avatarMarton Balint <cus@passwd.hu>
parent 9eebeea4
...@@ -3518,6 +3518,7 @@ caf_demuxer_select="iso_media" ...@@ -3518,6 +3518,7 @@ caf_demuxer_select="iso_media"
caf_muxer_select="iso_media" caf_muxer_select="iso_media"
dash_muxer_select="mp4_muxer" dash_muxer_select="mp4_muxer"
dash_demuxer_deps="libxml2" dash_demuxer_deps="libxml2"
daud_muxer_select="pcm_rechunk_bsf"
dirac_demuxer_select="dirac_parser" dirac_demuxer_select="dirac_parser"
dts_demuxer_select="dca_parser" dts_demuxer_select="dca_parser"
dtshd_demuxer_select="dca_parser" dtshd_demuxer_select="dca_parser"
......
...@@ -1397,23 +1397,17 @@ D-Cinema audio muxer. ...@@ -1397,23 +1397,17 @@ D-Cinema audio muxer.
It accepts a single 6-channels audio stream resampled at 96000 Hz It accepts a single 6-channels audio stream resampled at 96000 Hz
encoded with the @samp{pcm_24daud} codec. encoded with the @samp{pcm_24daud} codec.
In addition, each muxed packet size must not be greater than 65535 bytes.
@subsection Example @subsection Example
Use @command{ffmpeg} to mux input audio to a @samp{5.1} channel layout Use @command{ffmpeg} to mux input audio to a @samp{5.1} channel layout
resampled at 96000Hz: resampled at 96000Hz:
@example @example
ffmpeg -i INPUT -af aresample=96000,pan=5.1,asetnsamples=3640 slow.302 ffmpeg -i INPUT -af aresample=96000,pan=5.1 slow.302
@end example
The @samp{asetnsamples} filter is used to reduce the number of samples
of each audio packet, with a size computed according to the formula:
@example
65535 / (@var{channels} * @var{encoded_sample_size}) = 655535 / (6 * 3) = 3640
@end example @end example
The @var{encoded_sample_size} = 3 factor is due to sample size of the For ffmpeg versions before 7.0 you might have to use the @samp{asetnsamples}
@samp{pcm_24daud} encoder. filter to limit the muxed packet size, because this format does not support
muxing packets larger than 65535 bytes (3640 samples). For newer ffmpeg
versions audio is automatically packetized to 36000 byte (2000 sample) packets.
@section dv @section dv
DV (Digital Video) muxer. DV (Digital Video) muxer.
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
static int daud_init(struct AVFormatContext *s) static int daud_init(struct AVFormatContext *s)
{ {
AVCodecParameters *par = s->streams[0]->codecpar; AVCodecParameters *par = s->streams[0]->codecpar;
int ret;
if (par->ch_layout.nb_channels != 6) { if (par->ch_layout.nb_channels != 6) {
av_log(s, AV_LOG_ERROR, av_log(s, AV_LOG_ERROR,
...@@ -40,17 +41,15 @@ static int daud_init(struct AVFormatContext *s) ...@@ -40,17 +41,15 @@ static int daud_init(struct AVFormatContext *s)
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
ret = ff_stream_add_bitstream_filter(s->streams[0], "pcm_rechunk", "n=2000:pad=0");
if (ret < 0)
return ret;
return 0; return 0;
} }
static int daud_write_packet(struct AVFormatContext *s, AVPacket *pkt) static int daud_write_packet(struct AVFormatContext *s, AVPacket *pkt)
{ {
if (pkt->size > 65535) {
av_log(s, AV_LOG_ERROR,
"Packet size %d too large for s302m, must be <= 65535.\n",
pkt->size);
return AVERROR_INVALIDDATA;
}
avio_wb16(s->pb, pkt->size); avio_wb16(s->pb, pkt->size);
avio_wb16(s->pb, 0x8010); // unknown avio_wb16(s->pb, 0x8010); // unknown
avio_write(s->pb, pkt->data, pkt->size); avio_write(s->pb, pkt->data, pkt->size);
......
...@@ -7,23 +7,14 @@ ...@@ -7,23 +7,14 @@
#sample_rate 0: 96000 #sample_rate 0: 96000
#channel_layout_name 0: 5.1(side) #channel_layout_name 0: 5.1(side)
#stream#, dts, pts, duration, size, hash #stream#, dts, pts, duration, size, hash
0, 0, 0, 1024, 12288, 848250bf0a20e324f60151629134ebd5 0, 0, 0, 2000, 24000, f7b7be0b72225eeaa98ec0b2ea7ad34d
0, 1024, 1024, 1024, 12288, cd3c42240d163a7e8835aeda9538f881 0, 2000, 2000, 2000, 24000, c2d1d19b65f9ec1f7415bce5f2fbac8e
0, 2048, 2048, 1024, 12288, f213a268e7ab62b53a4a4acb9b303dfb 0, 4000, 4000, 2000, 24000, 461979d3566bc69cd4d1911ed1559191
0, 3072, 3072, 1024, 12288, 14d4f3289b057394abc995bfea58912a 0, 6000, 6000, 2000, 24000, 8fe028dc7a9e5512b6c24d33cf76c4f6
0, 4096, 4096, 1024, 12288, a69453c3f0c23abfacb49b15aedc432a 0, 8000, 8000, 2000, 24000, 8f7be8b0e562cc56110ee5de6b97bec3
0, 5120, 5120, 1024, 12288, 6578b4a89b1fa4c8897b1376974b685d 0, 10000, 10000, 2000, 24000, 53f053a72010471bd1a150af0873ec4a
0, 6144, 6144, 1024, 12288, 4893b62addf1bea4c03c173f173aa082 0, 12000, 12000, 2000, 24000, adcfe7407ec384f65f384cfd85793963
0, 7168, 7168, 1024, 12288, 992b70ea94c339dfda2d3514ac56c4a9 0, 14000, 14000, 2000, 24000, 4c541973df0e37a77eca16022d4d316c
0, 8192, 8192, 1024, 12288, 543f85139b77d30f8a46fd22d63e3ec7 0, 16000, 16000, 2000, 24000, 362d410570c821384e3ba30a03cdc907
0, 9216, 9216, 1024, 12288, f52f825a2fe71f66786d5cd08487e271 0, 18000, 18000, 2000, 24000, 00643563149102a4834841217a85d284
0, 10240, 10240, 1024, 12288, 50ac352cd73a803f52bfd393e610f83b 0, 20000, 20000, 480, 5760, 7401d92e7105169bef3deb34e53e9605
0, 11264, 11264, 1024, 12288, e9475a9a8794b9b0b912b855bc05001f
0, 12288, 12288, 1024, 12288, bf205474f44a381583b1f077ab8a9d0c
0, 13312, 13312, 1024, 12288, f5655b1da90d808c7e05b4bda02233ca
0, 14336, 14336, 1024, 12288, f8493bb74a270b50706cace85549c317
0, 15360, 15360, 1024, 12288, c299fbbdcae68c97bca63210f6a1f7da
0, 16384, 16384, 1024, 12288, 2f263932e3d4c419853e3369d70ef8d9
0, 17408, 17408, 1024, 12288, 09862736b8a1a1ce5c8d23814fb054cd
0, 18432, 18432, 1024, 12288, a99506638c5a3d84d3fa46ee2ba6c5ad
0, 19456, 19456, 1024, 12288, ab6f04f68cfbf2c9a89e9641604b3a50
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment