[Ffmpeg-devel] process an audio stream and find some attributes...
Patrick Fischer
patrick_fischer
Mon Jun 27 22:40:58 CEST 2005
I have written an Class to process an mpeg stream(audio/video).
I want to identify the avg loudness of the AudioStream.
By the way I have one class for video and one for audio.
My AudioStream Class has the ability to detect the rigth stream id and
codec.
<http://dict.leo.org/se?lp=ende&p=/Mn4k.&search=ability>But I have two
Problems:
-First I don't know how to handel the audio data. (find the avgloudness)
-Second I want to detect changes of the codec.
In some streams the codec can change. (mono->sterio->dts->...)
I think it is not a practical idea to make an av_find_stream_info(...)
at every Frame. <http://dict.leo.org/se?lp=ende&p=/Mn4k.&search=idea>
attached you find my hole class.
Here are some importend Parts...
I hope you can help me.....
Patrick
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
uint8_t *outbuf;
outbuf = (uint8_t*)malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
int out_size,len;
while( !found && av_read_frame(pFormatCtx, &packet)>=0 ) {
// Is this a packet from the audio stream?
if(packet.stream_index==audioStream) {
// Decode Audio frame
len = avcodec_decode_audio(pCodecCtx, (short *)outbuf,
&out_size,
packet.data, packet.size);
if (len < 0) {
fprintf(stderr, "Error while decoding\n");
exit(1);
}
if (out_size > 0) {
found = 1;
currentFrameNumber++;
av_free_packet(&packet);
}
}
// Free the packet that was allocated by av_read_frame
av_free_packet(&packet);
}
int avg =0;
for(int c=0; c<out_size; c++){
avg += outbuf[c]*outbuf[c] / currentFrameNumber;
}
//you can return the data or an avg value
sAudioFrame frame;
// frame.data = outbuf;
// frame.datasize = out_size;
frame.codec = pCodecCtx->codec_id;
frame.number = pCodecCtx->frame_number;
frame.avgloudness = avg;
if (!found )
frame.number = -1;
log->logdevelop("Avgloudness = %d",avg);
<http://dict.leo.org/se?lp=ende&p=/Mn4k.&search=identify>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: audiostream.cpp
Type: text/x-c++src
Size: 3304 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20050627/e54fb5be/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: audiostream.h
Type: text/x-chdr
Size: 746 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20050627/e54fb5be/attachment.h>
More information about the ffmpeg-devel
mailing list