[FFmpeg-devel] [RFC] QT IMA ADPCM encoder
Kostya
kostya.shishkov
Sun Feb 24 12:14:50 CET 2008
$subj
Since I've overlooked something, output .aifc and .movs
are playable only under QuickTime :S.
-------------- next part --------------
Index: libavcodec/utils.c
===================================================================
--- libavcodec/utils.c (revision 11803)
+++ libavcodec/utils.c (working copy)
@@ -1305,6 +1305,7 @@
return 3;
case CODEC_ID_ADPCM_SBPRO_4:
case CODEC_ID_ADPCM_CT:
+ case CODEC_ID_ADPCM_IMA_QT:
return 4;
case CODEC_ID_PCM_ALAW:
case CODEC_ID_PCM_MULAW:
Index: libavcodec/allcodecs.c
===================================================================
--- libavcodec/allcodecs.c (revision 11803)
+++ libavcodec/allcodecs.c (working copy)
@@ -249,7 +249,7 @@
REGISTER_DECODER (ADPCM_IMA_DK4, adpcm_ima_dk4);
REGISTER_DECODER (ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs);
REGISTER_DECODER (ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead);
- REGISTER_DECODER (ADPCM_IMA_QT, adpcm_ima_qt);
+ REGISTER_ENCDEC (ADPCM_IMA_QT, adpcm_ima_qt);
REGISTER_DECODER (ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg);
REGISTER_ENCDEC (ADPCM_IMA_WAV, adpcm_ima_wav);
REGISTER_DECODER (ADPCM_IMA_WS, adpcm_ima_ws);
Index: libavcodec/adpcm.c
===================================================================
--- libavcodec/adpcm.c (revision 11803)
+++ libavcodec/adpcm.c (working copy)
@@ -165,6 +165,10 @@
avctx->block_align = BLKSIZE;
/* seems frame_size isn't taken into account... have to buffer the samples :-( */
break;
+ case CODEC_ID_ADPCM_IMA_QT:
+ avctx->frame_size = 64;
+ avctx->block_align = 34 * avctx->channels;
+ break;
case CODEC_ID_ADPCM_MS:
avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; /* each 16 bits sample gives one nibble */
/* and we have 7 bytes per channel overhead */
@@ -295,7 +299,7 @@
nodes[0]->step = c->step_index;
nodes[0]->sample1 = c->sample1;
nodes[0]->sample2 = c->sample2;
- if((version == CODEC_ID_ADPCM_IMA_WAV) || (version == CODEC_ID_ADPCM_SWF))
+ if((version == CODEC_ID_ADPCM_IMA_WAV) || (version == CODEC_ID_ADPCM_IMA_QT) || (version == CODEC_ID_ADPCM_SWF))
nodes[0]->sample1 = c->prev_sample;
if(version == CODEC_ID_ADPCM_MS)
nodes[0]->step = c->idelta;
@@ -366,7 +370,7 @@
next_##NAME:;
STORE_NODE(ms, FFMAX(16, (AdaptationTable[nibble] * step) >> 8));
}
- } else if((version == CODEC_ID_ADPCM_IMA_WAV)|| (version == CODEC_ID_ADPCM_SWF)) {
+ } else if((version == CODEC_ID_ADPCM_IMA_WAV)|| (version == CODEC_ID_ADPCM_IMA_QT)|| (version == CODEC_ID_ADPCM_SWF)) {
#define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\
const int predictor = nodes[j]->sample1;\
const int div = (sample - predictor) * 4 / STEP_TABLE;\
@@ -509,6 +513,30 @@
samples += 8 * avctx->channels;
}
break;
+ case CODEC_ID_ADPCM_IMA_QT:
+ {
+ int ch, i;
+ PutBitContext pb;
+ init_put_bits(&pb, dst, buf_size*8);
+
+ //Init the encoder state
+ for(ch=0; ch<avctx->channels; ch++){
+ c->status[ch].prev_sample &= ~0x7F;
+ put_bits(&pb, 9, c->status[ch].prev_sample >> 7);
+ put_bits(&pb, 7, c->status[ch].step_index);
+ if(avctx->trellis > 0) {
+ uint8_t buf[64];
+ adpcm_compress_trellis(avctx, samples+ch, buf, &c->status[ch], 64);
+ for(i=0; i<64; i++)
+ put_bits(&pb, 4, buf[i]);
+ } else
+ for (i=0; i<64; i++)
+ put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[ch], samples[avctx->channels*i+ch]));
+ }
+
+ dst += put_bits_count(&pb)>>3;
+ break;
+ }
case CODEC_ID_ADPCM_SWF:
{
int i;
@@ -1588,7 +1616,7 @@
ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs);
ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead);
-ADPCM_DECODER(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
+ADPCM_CODEC (CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
ADPCM_DECODER(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg);
ADPCM_CODEC (CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws);
Index: libavformat/aiff.c
===================================================================
--- libavformat/aiff.c (revision 11803)
+++ libavformat/aiff.c (working copy)
@@ -37,6 +37,7 @@
{ CODEC_ID_GSM, MKTAG('G','S','M',' ') },
{ CODEC_ID_ADPCM_G726, MKTAG('G','7','2','6') },
{ CODEC_ID_PCM_S16LE, MKTAG('s','o','w','t') },
+ { CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') },
{ 0, 0 },
};
More information about the ffmpeg-devel
mailing list