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;
}
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 );
// Store selected audio and video indexes on properties
mlt_properties_set_int( properties, "audio_index", audio_index );
mlt_properties_set_int( properties, "video_index", video_index );
+
+ // Fetch the width, height and aspect ratio
+ if ( video_index != -1 )
+ {
+ AVCodecContext *codec_context = context->streams[ video_index ]->codec;
+ mlt_properties_set_int( properties, "width", codec_context->width );
+ mlt_properties_set_int( properties, "height", codec_context->height );
+ mlt_properties_set_double( properties, "aspect_ratio", av_q2d( codec_context->sample_aspect_ratio ) );
+ }
// We're going to cheat here - for a/v files, we will have two contexts (reasoning will be clear later)
if ( av == 0 && !av_bypass && audio_index != -1 && video_index != -1 )