[Ffmpeg-devel] Re: dv video format with 32 kHz audio?

Mikko Rapeli mikko.rapeli
Mon May 29 23:29:29 CEST 2006


On Wed, Apr 26, 2006 at 09:57:19AM +0300, Mikko Rapeli wrote:
> If/when I have more questions I'll bug you again.

Ok, I've got stuck: I'm hitting the first AV_LOG_ERROR, "1 Can't process
DV frame #%d. Insufficient audio data or severe sync problem.\n" in
libavformat/dv.c/dv_assemble_frame with this patch, and the sound track
does similar crackling as it did when I tried sample rate conversions in
kino. I'm presuming that existing code does the sample rate conversions. 

Is that not the case or have I missed some other trivial thingy?

-Mikko

diff -ru ffmpegcvs-20060430/ffmpeg.c ffmpegcvs-20060430-mcf/ffmpeg.c
--- ffmpegcvs-20060430/ffmpeg.c	2006-04-30 12:45:32.000000000 +0300
+++ ffmpegcvs-20060430-mcf/ffmpeg.c	2006-05-30 00:02:39.000000000 +0300
@@ -3847,7 +3847,7 @@
         audio_bit_rate = 448000;
         audio_sample_rate = 48000;
 
-    } else if(!strncmp(arg, "dv", 2)) {
+    } else if(!strcmp(arg, "dv48")) {
 
         opt_format("dv");
 
@@ -3859,6 +3859,18 @@
         audio_sample_rate = 48000;
         audio_channels = 2;
 
+    } else if(!strcmp(arg, "dv32")) {
+
+        opt_format("dv");
+
+        opt_frame_size(norm ? "720x480" : "720x576");
+        opt_frame_pix_fmt(!strncmp(arg, "dv50", 4) ? "yuv422p" :
+                                             (norm ? "yuv411p" : "yuv420p"));
+        opt_frame_rate(frame_rates[norm]);
+
+        audio_sample_rate = 32000;
+        audio_channels = 2;
+
     } else {
         fprintf(stderr, "Unknown target: %s\n", arg);
         exit(1);
@@ -3927,7 +3939,7 @@
     { "loop_input", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "loop (current only works with images)" },
     { "loop_output", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&loop_output}, "number of times to loop output in formats that support looping (0 loops forever)", "" },
     { "v", HAS_ARG, {(void*)opt_verbose}, "control amount of logging", "verbose" },
-    { "target", HAS_ARG, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" },
+    { "target", HAS_ARG, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv48\", \"dv32\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" },
     { "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
     { "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" },
     { "async", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&audio_sync_method}, "audio sync method", "" },
diff -ru ffmpegcvs-20060430/libavformat/dv.c ffmpegcvs-20060430-mcf/libavformat/dv.c
--- ffmpegcvs-20060430/libavformat/dv.c	2006-04-30 12:45:41.000000000 +0300
+++ ffmpegcvs-20060430-mcf/libavformat/dv.c	2006-05-30 00:05:19.000000000 +0300
@@ -228,11 +228,25 @@
                    (tc.tm_hour % 10);         /* Units of hours */
           break;
     case dv_audio_source:  /* AAUX source pack */
-          buf[1] = (0 << 7) | /* locked mode       */
-                   (1 << 6) | /* reserved -- always 1 */
-                   (dv_audio_frame_size(c->sys, c->frames) -
-                    c->sys->audio_min_samples[0]);
+          /* 
+           * Where do we get i in ast[i]? Which channel 
+           * are we looking at? What if channels have different 
+           * sample rates? Cheez. Channel 0 is just a guess...
+           */
+          if (c->ast[0]->codec->sample_rate == 32000) {
+                buf[1] = (0 << 7) | /* locked mode       */
+                         (1 << 6) | /* reserved -- always 1 */
+                         (dv_audio_frame_size(c->sys, c->frames) -
+                          c->sys->audio_min_samples[2]);
                               /* # of samples      */
+          } else /* if (c->ast[0]->codec->sample_rate == 48000) */ {
+                buf[1] = (0 << 7) | /* locked mode       */
+                         (1 << 6) | /* reserved -- always 1 */
+                         (dv_audio_frame_size(c->sys, c->frames) -
+                          c->sys->audio_min_samples[0]);
+                              /* # of samples      */
+          } 
+
           buf[2] = (0 << 7) | /* multi-stereo      */
                    (0 << 5) | /* #of audio channels per block: 0 -- 1 channel */
                    (0 << 4) | /* pair bit: 0 -- one pair of channels */
@@ -241,10 +255,21 @@
                    (1 << 6) | /* multi-language flag */
                    (c->sys->dsf << 5) | /*  system: 60fields/50fields */
                    (apt << 1);/* definition: 0 -- 25Mbps, 2 -- 50Mbps */
-          buf[4] = (1 << 7) | /* emphasis: 1 -- off */
-                   (0 << 6) | /* emphasis time constant: 0 -- reserved */
-                   (0 << 3) | /* frequency: 0 -- 48Khz, 1 -- 44,1Khz, 2 -- 32Khz */
-                    0;        /* quantization: 0 -- 16bit linear, 1 -- 12bit nonlinear */
+          if (c->ast[0]->codec->sample_rate == 32000) {
+                buf[4] = (1 << 7) | /* emphasis: 1 -- off */
+                         (0 << 6) | /* emphasis time constant: 0 -- reserved */
+                         (2 << 3) | /* frequency: 0 -- 48Khz, 1 -- 44,1Khz, 2 --
+ 32Khz */
+                         0;        /* quantization: 0 -- 16bit linear, 1 -- 12bi
+t nonlinear */
+          } else /* if (c->ast[i]->codec->sample_rate == 48000 */ {
+                buf[4] = (1 << 7) | /* emphasis: 1 -- off */
+                         (0 << 6) | /* emphasis time constant: 0 -- reserved */
+                         (0 << 3) | /* frequency: 0 -- 48Khz, 1 -- 44,1Khz, 2 --
+ 32Khz */
+                         0;        /* quantization: 0 -- 16bit linear, 1 -- 12bi
+t nonlinear */
+          }
           break;
     case dv_audio_control:
           buf[1] = (0 << 6) | /* copy protection: 0 -- unrestricted */
@@ -660,7 +685,7 @@
     if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
         /* FIXME: we have to have more sensible approach than this one */
         if (c->has_video)
-            av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames);
+            av_log(st->codec, AV_LOG_ERROR, "1 Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames);
 
         dv_inject_video(c, data, *frame);
         c->has_video = 1;
@@ -691,7 +716,7 @@
             }
             /* FIXME: we have to have more sensible approach than this one */
             if (fifo_size(&c->audio_data[i], c->audio_data[i].rptr) + data_size >= 100*AVCODEC_MAX_AUDIO_FRAME_SIZE)
-                av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames);
+                av_log(st->codec, AV_LOG_ERROR, "2 Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames);
             fifo_write(&c->audio_data[i], (uint8_t *)data, data_size, &c->audio_data[i].wptr);
         }
     }
@@ -735,7 +760,9 @@
         goto bail_out;
     for (i=0; i<c->n_ast; i++) {
         if (c->ast[i] && (c->ast[i]->codec->codec_id != CODEC_ID_PCM_S16LE ||
-                          c->ast[i]->codec->sample_rate != 48000 ||
+                         ((c->ast[i]->codec->sample_rate != 48000) &&
+                          (c->ast[i]->codec->sample_rate != 44100) &&
+                          (c->ast[i]->codec->sample_rate != 32000)) ||
                           c->ast[i]->codec->channels != 2))
             goto bail_out;
     }




More information about the ffmpeg-devel mailing list