afmt = mlt_audio_float;
else if ( !strcmp( format, "f32le" ) )
afmt = mlt_audio_f32le;
+ else if ( !strcmp( format, "u8" ) )
+ afmt = mlt_audio_u8;
}
int counter = 0;
double fps = mlt_properties_get_double( properties, "fps" );
case mlt_audio_s32le: return "s32le";
case mlt_audio_float: return "float";
case mlt_audio_f32le: return "f32le";
+ case mlt_audio_u8: return "u8";
}
return "invalid";
}
case mlt_audio_s32: return samples * channels * sizeof( int32_t );
case mlt_audio_f32le:
case mlt_audio_float: return samples * channels * sizeof( float );
+ case mlt_audio_u8: return samples * channels;
}
return 0;
}
mlt_image_rgb24a, /**< 8-bit RGB with alpha channel */
mlt_image_yuv422, /**< 8-bit YUV 4:2:2 packed */
mlt_image_yuv420p, /**< 8-bit YUV 4:2:0 planar */
- mlt_image_opengl /**< suitable for OpenGL texture */
+ mlt_image_opengl /**< (deprecated) suitable for OpenGL texture */
}
mlt_image_format;
mlt_audio_s32, /**< signed 32-bit non-interleaved PCM */
mlt_audio_float, /**< 32-bit non-interleaved floating point */
mlt_audio_s32le, /**< signed 32-bit interleaved PCM */
- mlt_audio_f32le /**< 32-bit interleaved floating point */
+ mlt_audio_f32le, /**< 32-bit interleaved floating point */
+ mlt_audio_u8 /**< unsigned 8-bit interleaved PCM */
}
mlt_audio_format;
{
switch ( av_sample_fmt )
{
+ case AV_SAMPLE_FMT_U8:
+ return mlt_audio_u8;
case AV_SAMPLE_FMT_S32:
return mlt_audio_s32le;
case AV_SAMPLE_FMT_FLT:
return mlt_audio_f32le;
#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(17<<8)+0)
+ case AV_SAMPLE_FMT_U8P:
+ return mlt_audio_u8;
case AV_SAMPLE_FMT_S32P:
return mlt_audio_s32le;
case AV_SAMPLE_FMT_FLTP:
sample_fmt = AV_SAMPLE_FMT_S32;
else if ( !strcmp( format, "f32le" ) )
sample_fmt = AV_SAMPLE_FMT_FLT;
+ else if ( !strcmp( format, "u8" ) )
+ sample_fmt = AV_SAMPLE_FMT_U8;
#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(17<<8)+0)
else if ( !strcmp( format, "s32" ) )
sample_fmt = AV_SAMPLE_FMT_S32P;
{
switch (*p)
{
+ case AV_SAMPLE_FMT_U8:
case AV_SAMPLE_FMT_S16:
case AV_SAMPLE_FMT_S32:
case AV_SAMPLE_FMT_FLT:
#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(17<<8)+0)
+ case AV_SAMPLE_FMT_U8P:
case AV_SAMPLE_FMT_S16P:
case AV_SAMPLE_FMT_S32P:
case AV_SAMPLE_FMT_FLTP:
p = interleaved_to_planar( samples, channels, p, sizeof( int16_t ) );
else if ( codec->sample_fmt == AV_SAMPLE_FMT_S32P )
p = interleaved_to_planar( samples, channels, p, sizeof( int32_t ) );
+ else if ( codec->sample_fmt == AV_SAMPLE_FMT_U8P )
+ p = interleaved_to_planar( samples, channels, p, sizeof( uint8_t ) );
#endif
pkt.size = avcodec_encode_audio( codec, audio_outbuf, audio_outbuf_size, p );
#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(17<<8)+0)
- if ( codec->sample_fmt == AV_SAMPLE_FMT_FLTP
- || codec->sample_fmt == AV_SAMPLE_FMT_S16P
- || codec->sample_fmt == AV_SAMPLE_FMT_S32P )
+ if ( p != audio_buf_1 )
mlt_pool_release( p );
#endif
}
p = interleaved_to_planar( audio_input_frame_size, channels, p, sizeof( int16_t ) );
else if ( c->sample_fmt == AV_SAMPLE_FMT_S32P )
p = interleaved_to_planar( audio_input_frame_size, channels, p, sizeof( int32_t ) );
+ else if ( c->sample_fmt == AV_SAMPLE_FMT_U8P )
+ p = interleaved_to_planar( audio_input_frame_size, channels, p, sizeof( uint8_t ) );
#endif
pkt.size = avcodec_encode_audio( c, audio_outbuf, audio_outbuf_size, p );
#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(17<<8)+0)
- if ( c->sample_fmt == AV_SAMPLE_FMT_FLTP
- || c->sample_fmt == AV_SAMPLE_FMT_S16P
- || c->sample_fmt == AV_SAMPLE_FMT_S32P )
+ if ( p != audio_buf_1 )
mlt_pool_release( p );
#endif
}
switch ( sample_fmt )
{
// interleaved
+ case AV_SAMPLE_FMT_U8:
+ return mlt_audio_u8;
case AV_SAMPLE_FMT_S16:
return mlt_audio_s16;
case AV_SAMPLE_FMT_S32:
return mlt_audio_f32le;
// planar - this producer converts planar to interleaved
#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(17<<8)+0)
+ case AV_SAMPLE_FMT_U8P:
+ return mlt_audio_u8;
case AV_SAMPLE_FMT_S16P:
return mlt_audio_s16;
case AV_SAMPLE_FMT_S32P:
switch ( codec_context->sample_fmt )
{
#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(17<<8)+0)
+ case AV_SAMPLE_FMT_U8P:
case AV_SAMPLE_FMT_S16P:
case AV_SAMPLE_FMT_S32P:
case AV_SAMPLE_FMT_FLTP:
}
}
}
+ else if ( *format == mlt_audio_u8 )
+ {
+ uint8_t *p = (uint8_t*) new_buffer;
+ int i, j, k = 0;
+ for ( i = 0; i < *samples; i++ )
+ {
+ for ( j = 0; j < *channels; j++ )
+ {
+ p[ ( i * *channels ) + j ] = ((uint8_t*)(*buffer))[ ( i * channels_avail ) + k ];
+ k = ( k + 1 ) % channels_avail;
+ }
+ }
+ }
else
{
// non-interleaved - s32 or float
error = 0;
break;
}
+ case mlt_audio_u8:
+ {
+ uint8_t *buffer = mlt_pool_alloc( size );
+ uint8_t *p = buffer;
+ int16_t *q = (int16_t*) *audio;
+ int i = samples * channels + 1;
+ while ( --i )
+ *p++ = ( *q++ >> 8 ) + 128;
+ *audio = buffer;
+ error = 0;
+ break;
+ }
default:
break;
}
error = 0;
break;
}
+ case mlt_audio_u8:
+ {
+ uint8_t *buffer = mlt_pool_alloc( size );
+ uint8_t *p = buffer;
+ int32_t *q = (int32_t*) *audio;
+ int s, c;
+ for ( s = 0; s < samples; s++ )
+ for ( c = 0; c < channels; c++ )
+ *p++ = ( q[c * samples + s] >> 24 ) + 128;
+ *audio = buffer;
+ error = 0;
+ break;
+ }
default:
break;
}
error = 0;
break;
}
+ case mlt_audio_u8:
+ {
+ uint8_t *buffer = mlt_pool_alloc( size );
+ uint8_t *p = buffer;
+ float *q = (float*) *audio;
+ int s, c;
+ for ( s = 0; s < samples; s++ )
+ for ( c = 0; c < channels; c++ )
+ {
+ float f = *( q + c * samples + s );
+ f = f > 1.0 ? 1.0 : f < -1.0 ? -1.0 : f;
+ *p++ = ( 127 * f ) + 128;
+ }
+ *audio = buffer;
+ error = 0;
+ break;
+ }
default:
break;
}
error = 0;
break;
}
+ case mlt_audio_u8:
+ {
+ uint8_t *buffer = mlt_pool_alloc( size );
+ uint8_t *p = buffer;
+ int32_t *q = (int32_t*) *audio;
+ int i = samples * channels + 1;
+ while ( --i )
+ *p++ = ( *q++ >> 24 ) + 128;
+ *audio = buffer;
+ error = 0;
+ break;
+ }
default:
break;
}
error = 0;
break;
}
+ case mlt_audio_u8:
+ {
+ uint8_t *buffer = mlt_pool_alloc( size );
+ uint8_t *p = buffer;
+ float *q = (float*) *audio;
+ int i = samples * channels + 1;
+ while ( --i )
+ {
+ float f = *q++;
+ f = f > 1.0 ? 1.0 : f < -1.0 ? -1.0 : f;
+ *p++ = ( 127 * f ) + 128;
+ }
+ *audio = buffer;
+ error = 0;
+ break;
+ }
+ default:
+ break;
+ }
+ break;
+ case mlt_audio_u8:
+ switch ( requested_format )
+ {
+ case mlt_audio_s32:
+ {
+ int32_t *buffer = mlt_pool_alloc( size );
+ int32_t *p = buffer;
+ int c;
+ for ( c = 0; c < channels; c++ )
+ {
+ uint8_t *q = (uint8_t*) *audio + c;
+ int i = samples + 1;
+ while ( --i )
+ {
+ *p++ = ( (int32_t) *q - 128 ) << 24;
+ q += channels;
+ }
+ }
+ *audio = buffer;
+ error = 0;
+ break;
+ }
+ case mlt_audio_float:
+ {
+ float *buffer = mlt_pool_alloc( size );
+ float *p = buffer;
+ int c;
+ for ( c = 0; c < channels; c++ )
+ {
+ uint8_t *q = (uint8_t*) *audio + c;
+ int i = samples + 1;
+ while ( --i )
+ {
+ *p++ = ( (float) *q - 128 ) / 256.0f;
+ q += channels;
+ }
+ }
+ *audio = buffer;
+ error = 0;
+ break;
+ }
+ case mlt_audio_s16:
+ {
+ int16_t *buffer = mlt_pool_alloc( size );
+ int16_t *p = buffer;
+ uint8_t *q = (uint8_t*) *audio;
+ int i = samples * channels + 1;
+ while ( --i )
+ *p++ = ( (int16_t) *q++ - 128 ) << 8;
+ *audio = buffer;
+ error = 0;
+ break;
+ }
+ case mlt_audio_s32le:
+ {
+ int32_t *buffer = mlt_pool_alloc( size );
+ int32_t *p = buffer;
+ uint8_t *q = (uint8_t*) *audio;
+ int i = samples * channels + 1;
+ while ( --i )
+ *p++ = ( (int32_t) *q++ - 128 ) << 24;
+ *audio = buffer;
+ error = 0;
+ break;
+ }
+ case mlt_audio_f32le:
+ {
+ float *buffer = mlt_pool_alloc( size );
+ float *p = buffer;
+ uint8_t *q = (uint8_t*) *audio;
+ int i = samples * channels + 1;
+ while ( --i )
+ {
+ float f = ( (float) *q++ - 128 ) / 256.0f;
+ f = f > 1.0 ? 1.0 : f < -1.0 ? -1.0 : f;
+ *p++ = f;
+ }
+ *audio = buffer;
+ error = 0;
+ break;
+ }
default:
break;
}
if ( from != to)
switch ( *format )
{
+ case mlt_audio_u8:
+ {
+ uint8_t *f = (uint8_t*) *buffer + from;
+ uint8_t *t = (uint8_t*) *buffer + to;
+ uint8_t x;
+ int i;
+
+ if ( swap )
+ for ( i = 0; i < *samples; i++, f += *channels, t += *channels )
+ {
+ x = *t;
+ *t = *f;
+ *f = x;
+ }
+ else
+ for ( i = 0; i < *samples; i++, f += *channels, t += *channels )
+ *t = *f;
+ break;
+ }
case mlt_audio_s16:
{
int16_t *f = (int16_t*) *buffer + from;
switch ( *format )
{
+ case mlt_audio_u8:
+ {
+ uint8_t *new_buffer = mlt_pool_alloc( size );
+ for ( i = 0; i < *samples; i++ )
+ {
+ uint8_t mixdown = 0;
+ for ( j = 0; j < *channels; j++ )
+ mixdown += ((uint8_t*) *buffer)[ ( i * *channels ) + j ] / *channels;
+ for ( j = 0; j < channels_out; j++ )
+ new_buffer[ ( i * channels_out ) + j ] = mixdown;
+ }
+ *buffer = new_buffer;
+ break;
+ }
case mlt_audio_s16:
{
int16_t *new_buffer = mlt_pool_alloc( size );