[FFmpeg-devel] [PATCH 3/3] apng: Add a basic APNG muxer
Donny Yang
work at kota.moe
Wed Apr 1 15:17:50 CEST 2015
On 1 April 2015 at 23:28, Michael Niedermayer <michaelni at gmx.at> wrote:
> On Wed, Apr 01, 2015 at 12:07:46PM +0000, Donny Yang wrote:
> > On 1 April 2015 at 22:57, Paul B Mahol <onemda at gmail.com> wrote:
> >
> > > On 4/1/15, Donny Yang <work at kota.moe> wrote:
> > > > On 1 April 2015 at 17:03, Paul B Mahol <onemda at gmail.com> wrote:
> > > >
> > > >> Dana 31. 3. 2015. 22:59 osoba "Donny Yang" <work at kota.moe>
> napisala je:
> > > >> > +#include <zlib.h>
> > > >>
> > > >> This is missing dependency on zlib in configure.
> > > >>
> > > > Fixed
> > > >
> > > >
> > >
> > > But this is more appropriate for APNG encoder. APNG muxer seems to not
> > > use zlib at all.
> > >
> > It's used for it's crc32 functions for editing/creating chunks.
>
> please use libavutil/crc*
>
I applied the following patch to my code, but ffmpeg's functions seem to be
producing the wrong crc32 value.
For example:
$ crc32 <(printf "acTL\x00\x00\x00\x14\x00\x00\x00\x00")
1c2df152
While a `av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0,
"acTL\x00\x00\x00\x14\x00\x00\x00\x00", 12)` returns 0xf6f7ccdd.
(using AV_CRC_32_IEEE_LE also produces an incorrect checksum)
What am I doing wrong?
diff --git a/libavformat/apngenc.c b/libavformat/apngenc.c
index 0e9af89..c53eee4 100644
--- a/libavformat/apngenc.c
+++ b/libavformat/apngenc.c
@@ -21,11 +21,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
-#include <zlib.h>
-
#include "avformat.h"
#include "internal.h"
#include "libavutil/avassert.h"
+#include "libavutil/crc.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
@@ -58,16 +57,18 @@ static uint8_t *apng_find_chunk(uint32_t tag, uint8_t
*buf, size_t length)
static void apng_write_chunk(AVIOContext *io_context, uint32_t tag,
uint8_t *buf, size_t length)
{
- uint32_t crc;
+ const AVCRC *crc_table = av_crc_get_table(AV_CRC_32_IEEE);
+ uint32_t crc = 0;
uint8_t tagbuf[4];
+ av_assert0(crc_table);
+
avio_wb32(io_context, length);
- crc = crc32(0, Z_NULL, 0);
AV_WB32(tagbuf, tag);
- crc = crc32(crc, tagbuf, 4);
+ crc = av_crc(crc_table, crc, tagbuf, 4);
avio_wb32(io_context, tag);
if (length > 0) {
- crc = crc32(crc, buf, length);
+ crc = av_crc(crc_table, crc, buf, length);
avio_write(io_context, buf, length);
}
avio_wb32(io_context, crc);
@@ -180,7 +181,7 @@ static void flush_packet(AVFormatContext
*format_context, AVPacket *packet)
// Update frame control header with new delay
AV_WB16(existing_fcTL_chunk + 20, delay.num);
AV_WB16(existing_fcTL_chunk + 22, delay.den);
- AV_WB32(existing_fcTL_chunk + 26, crc32(crc32(0, Z_NULL,
0), existing_fcTL_chunk - 4, 26 + 4));
+ AV_WB32(existing_fcTL_chunk + 26,
av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, existing_fcTL_chunk - 4, 26 +
4));
}
apng->prev_delay = delay;
}
More information about the ffmpeg-devel
mailing list