[FFmpeg-devel] [PATCH] ADPCM IMA AMV encoder (try 1)
Benjamin Larsson
banan
Mon Oct 8 12:01:07 CEST 2007
Hi.
Vladimir Voroshilov wrote:
> 2007/10/6, Vladimir Voroshilov <voroshil at gmail.com>:
>
>> Hi, All
>>
>> Since no reply was got in "Devel question : how to calculate
>> frame_size in audio encoder (adpcm_encode_init) "' thread, i want (as
>> suggested by Vitor) show you current version of ADPCM IMA AMV encoder
>> in amv-codec-tools project.
>>
>> Due to fake codec tag (it uses PCM's 0x01 code) this codec can not be
>> easily used outside AMV container.
>>
>> Number of 16-bit audio samples per audio frame and audio frame size are
>> calculated by folmulas below:
>>
>> samples_per_frame=audio_sample_rate/video_frame_rate
>> audio_frame_size=(samples_per_frame/2)+8
>>
>> Current code sets frame_size to 0 inside adpcm_encode_init.
>> frame_size receives real value at the end of avi_write_header:
>>
>> ============CUT=================
>> /*
>> HACK!!!
>> Set correct frame_size for audio stream
>> */
>> if(s->nb_streams > 1 && s->streams[1]->codec->codec_type ==
>> CODEC_TYPE_AUDIO) {
>> s->streams[1]->codec->frame_size=av_rescale(
>> s->streams[1]->codec->sample_rate,
>> s->streams[0]->codec->time_base.num,
>> s->streams[0]->codec->time_base.den);
>> }
>> ===========CUT==================
>>
>> I want to know how much attached patch is ugly/hackish and receive
>> emproovement sugesstions.
>>
>
> Attached patch adpcm2.diff is updated version with trellis quantization.
>
>
>> P.S. current code does not rearrange extra samples yet (i,e for
>> arate=22050 and fps=16 real audio rate will be 16*(22050/16)=22048,
>> proprietary encodec puts this two extra samples in last 16th frame). I
>> will be happy to recevie good solution for extra samples.
>>
>
> Attached patch adpcm_samplerate_compensation.diff adds simple
> sompensation: putting all extra samples into last frame of the second.
>
>
>
> ------------------------------------------------------------------------
>
>
> --- ffmpeg.orig/libavcodec/adpcm.c 2007-10-04 22:21:14.000000000 +0700
> +++ ffmpeg/libavcodec/adpcm.c 2007-10-07 13:10:50.000000000 +0700
> @@ -146,6 +146,7 @@
> int channel; /* for stereo MOVs, decode left, then decode right, then tell it's decoded */
> ADPCMChannelStatus status[2];
> short sample_buffer[32]; /* hold left samples while waiting for right samples */
> + int extra_samples_count; //number of samples to put into next frame
>
Maybe name this extra_amv_samples instead. And can you submit doxygen
comments for adpcm_compress_trellis() ?
MvH
Benjamin Larsson
More information about the ffmpeg-devel
mailing list