Libavcodec audio4 pas de son
Bonjour à tous,
J'ai migré récemment une application (en c) qui affiche des vignettes vidéos, elle ne tournait qu'avec d'anciennes versions de la libavcodec.
Je n'ai pas d'erreur à la compilation et les vidéos fonctionnent bien
Seulement voila je n'ai pas de son :(
Si quelqu'un à une idée ...
Avant
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
int video_decode_audio_frame( AVCodecContext *context, uint8_t *buffer, int buffer_size ) {
static AVPacket packet;
int used, data_size;
for(;;) {
while( audio_packet.size > 0 ) {
data_size = buffer_size;
// Todo depreciated //
used = avcodec_decode_audio3( context, (int16_t *)audio_buffer, &data_size,
&audio_packet);
if( used < 0 ) {
/* if error, skip frame */
audio_packet.size = 0;
break;
}
audio_packet.data += used;
audio_packet.size -= used;
if( data_size <= 0 ) {
/* No data yet, get more frames */
continue;
}
audio_clock += (double)data_size /
(double)(format_context->streams[audio_stream]->codec->sample_rate *
(2 * format_context->streams[audio_stream]->codec->channels));
/* We have data, return it and come back for more later */
return data_size;
}
if( packet.data )
av_free_packet( &packet );
if( stop ) {
audio_running = 0;
return -1;
}
if( packet_queue_get( &audio_queue, &packet, 1 ) < 0 )
return -1;
audio_packet.data = packet.data;
audio_packet.size = packet.size;
if( packet.pts != AV_NOPTS_VALUE ) {
audio_clock = packet.pts * av_q2d( format_context->streams[audio_stream]->time_base );
}
}
} |
Après
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
for(;;) {
while (audio_packet.size > 0) {
int got_frame = 0;
data_size = buffer_size;
used = avcodec_decode_audio4( context, frame, &got_frame, &packet);
if( used < 0 ) {
/* if error, skip frame */
audio_packet.size = 0;
break;
}
audio_packet.data += used;
audio_packet.size -= used;
if (got_frame) {
/* if a frame has been decoded, output it */
data_size = av_samples_get_buffer_size(NULL, context->channels,frame->nb_samples,context->sample_fmt, 1);
if( data_size < 0 ) {
/* This should not occur, checking just for paranoia */
fprintf(stderr, "Failed to calculate data size\n");
exit(1);
}
}
fprintf(stderr, "data_size %d\n", data_size);
return data_size;
}
if( packet.data )
av_free_packet( &packet );
if( stop ) {
audio_running = 0;
return -1;
}
if( packet_queue_get( &audio_queue, &packet, 1 ) < 0 )
return -1;
audio_packet.data = packet.data;
audio_packet.size = packet.size;
if( packet.pts != AV_NOPTS_VALUE ) {
audio_clock = packet.pts * av_q2d( format_context->streams[audio_stream]->time_base );
}
} |