c->sample_rate = mlt_properties_get_int( properties, "frequency" );
c->channels = mlt_properties_get_int( properties, "channels" );
+ if (oc->oformat->flags & AVFMT_GLOBALHEADER)
+ c->flags |= CODEC_FLAG_GLOBAL_HEADER;
+
// Allow the user to override the audio fourcc
if ( mlt_properties_get( properties, "afourcc" ) )
{
// Get audio and append to the fifo
if ( !terminated && audio_st )
{
- samples = mlt_sample_calculator( fps, frequency, count );
+ samples = mlt_sample_calculator( fps, frequency, count ++ );
mlt_frame_get_audio( frame, &pcm, &aud_fmt, &frequency, &channels, &samples );
// Create the fifo if we don't have one
pkt.size = avcodec_encode_audio( c, audio_outbuf, audio_outbuf_size, buffer );
// Write the compressed frame in the media file
- if ( c->coded_frame )
+ if ( c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE )
pkt.pts = av_rescale_q( c->coded_frame->pts, c->time_base, audio_st->time_base );
pkt.flags |= PKT_FLAG_KEY;
pkt.stream_index= audio_st->index;
pkt.data= audio_outbuf;
- if ( av_interleaved_write_frame( oc, &pkt ) != 0)
- fprintf(stderr, "Error while writing audio frame\n");
+ if ( pkt.size )
+ if ( av_interleaved_write_frame( oc, &pkt ) != 0)
+ fprintf(stderr, "Error while writing audio frame\n");
audio_pts += c->frame_size;
}
if ( video_st->codec->pix_fmt == PIX_FMT_RGBA32 )
{
uint8_t *alpha = mlt_frame_get_alpha_mask( frame );
+ register int n;
for ( i = 0; i < height; i ++ )
{
- p = input->data[ 0 ] + i * input->linesize[ 0 ];
+ n = ( width + 7 ) / 8;
+ p = output->data[ 0 ] + i * output->linesize[ 0 ];
+
#ifndef __DARWIN__
p += 3;
#endif
- j = width;
- while( j -- )
+
+ switch( width % 8 )
{
- *p = *alpha ++;
- *p += 4;
+ case 0: do { *p = *alpha++; p += 4;
+ case 7: *p = *alpha++; p += 4;
+ case 6: *p = *alpha++; p += 4;
+ case 5: *p = *alpha++; p += 4;
+ case 4: *p = *alpha++; p += 4;
+ case 3: *p = *alpha++; p += 4;
+ case 2: *p = *alpha++; p += 4;
+ case 1: *p = *alpha++; p += 4;
+ }
+ while( --n );
}
}
}
out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size, output );
// If zero size, it means the image was buffered
- if (out_size != 0)
+ if (out_size > 0)
{
AVPacket pkt;
av_init_packet( &pkt );
- if ( c->coded_frame )
+ if ( c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE )
pkt.pts= av_rescale_q( c->coded_frame->pts, c->time_base, video_st->time_base );
if( c->coded_frame && c->coded_frame->key_frame )
pkt.flags |= PKT_FLAG_KEY;
ret = av_interleaved_write_frame(oc, &pkt);
video_pts += c->frame_size;
}
+ else
+ {
+ fprintf( stderr, "Error with video encode\n" );
+ }
}
frame_count++;
mlt_frame_close( frame );