Hi,
the attached patch should fix this bug.

-- 
Anton Khirnov
Index: shotdetect-1.0.86/src/film.cpp
===================================================================
--- shotdetect-1.0.86.orig/src/film.cpp	2014-03-01 00:39:19.000000000 +0000
+++ shotdetect-1.0.86/src/film.cpp	2014-03-01 01:02:52.009064391 +0000
@@ -145,7 +145,7 @@
     {
       this->height = int (pFormatCtx->streams[videoStream]->codec->height);
       this->width = int (pFormatCtx->streams[videoStream]->codec->width);
-      this->fps = av_q2d (pFormatCtx->streams[videoStream]->r_frame_rate);
+      this->fps = av_q2d (pFormatCtx->streams[videoStream]->avg_frame_rate);
       avcodec_string (buf, sizeof (buf), pFormatCtx->streams[videoStream]->codec, 0);
       this->codec.video = buf;
     }
@@ -478,13 +478,21 @@
 void
 film::process_audio ()
 {
+  AVFrame *frame;
   int len1;
   int len;
-  int data_size;
-  static unsigned int samples_size = 0;
+  int ret, got_output;
   int i;
   uint8_t *ptr;
 
+  /* only support s16 */
+  if (av_get_packed_sample_fmt(pCodecCtxAudio->sample_fmt) != AV_SAMPLE_FMT_S16)
+    return;
+
+  frame = av_frame_alloc();
+  if (!frame)
+    return;
+
   ptr = packet.data;
   len = packet.size;
 
@@ -492,11 +500,9 @@
   av_init_packet(&avpkt);
   while (len > 0)
     {
-      this->audio_buf = (short *) av_fast_realloc (this->audio_buf, &samples_size, FFMAX (packet.size, AVCODEC_MAX_AUDIO_FRAME_SIZE));
-      data_size = samples_size;
       avpkt.data = ptr;
       avpkt.size = len;
-      len1 = avcodec_decode_audio3 (pCodecCtxAudio, audio_buf, &data_size, &avpkt);
+      len1 = avcodec_decode_audio4 (pCodecCtxAudio, frame, &got_output, &avpkt);
 
 
       if (len1 < 0)
@@ -511,20 +517,26 @@
       len -= len1;
       ptr += len1;
 
-      if (data_size > 0)
+      if (got_output)
 	{
+	int block_align;
+	int16_t *left, *right;
+
+	if (av_sample_fmt_is_planar(pCodecCtxAudio->sample_fmt)) {
+	    left = (int16_t*)frame->data[0];
+	    right = (pCodecCtxAudio->channels > 1) ? (int16_t*)frame->data[1] : left;
+	    block_align = 1;
+	} else {
+	    left  = (int16_t*)frame->data[0];
+	    right = (pCodecCtxAudio->channels > 1) ? left + 1 : left;
+	    block_align = pCodecCtxAudio->channels;
+	}
 
-	  samples += data_size / (pCodecCtxAudio->channels * 2);
-	  for (i = 0; i < data_size; i += 2 * pCodecCtxAudio->channels)
+	  samples += frame->nb_samples;
+	  for (i = 0; i < frame->nb_samples; i++)
 	    {
-	      sample_right = *((signed short int *) (audio_buf + i));
-	      /*
-	       * If there's only 1 channel, set sample_right=sample_left
-	       */
-	      if (pCodecCtxAudio->channels >= 1)
-		sample_left = *((signed short int *) (audio_buf + i + 2));
-	      else
-		sample_left = sample_right;
+	      sample_left  = left[i * block_align];
+	      sample_right = right[i * block_align];
 
 	      /*
 	       * Extract minima and maxima
@@ -561,6 +573,7 @@
 	    }
 	}
     }
+  av_frame_free(&frame);
 }
 
 film::film()
@@ -573,7 +586,6 @@
   maxleft = MIN_INT;
   ech = 0;
   nchannel = 1;
-  audio_buf = NULL;
   this->first_img_set = false;
   this->last_img_set = false;
   this->audio_set = false;
_______________________________________________
pkg-multimedia-maintainers mailing list
pkg-multimedia-maintainers@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-multimedia-maintainers

Reply via email to