[Libav-user] asf (.wmv) muxer problem : duration is not good !
Stephane Debusne
stephane.debusne at gmail.com
Sat Sep 29 10:38:54 CEST 2012
Le 29/09/2012 10:03, Carl Eugen Hoyos a écrit :
> Stephane Debusne <stephane.debusne at ...> writes:
>
>> but after writing the trailer, if i close and reopen the file, the
>> duration read by avlibs is 14805. not 12800...
>> However, the movie plays well and it plays only for 12.8 seconds.
> Isn't the duration value simply wrong on reopening?
> Or is that also not reproducible with the file created
> with ffmpeg (the application)?
>
Hi Carl,
The problem seems to be not reproductible with the ffmpeg.exe
application... That's why I think I do something wrong.
(Not like the fps value displayed in the windows explorer, which is
wrong either with the ffmepg.exe app, but that's an other problem)
What I basically do is something like that :
I clear every time frame->pts to AV_NOPTS_VALUE to let the encoder deal
with that, because i had some weird things with asf files if I wrote
->pts value.... I think this is due to time_base that is different in
asf files...
for video :
// decode video frame
ret = avcodec_decode_video2(input_video_dec_ctx, frame,
got_frame, &input_video_pkt);
if (ret < 0)
{
return ret;
}
if (*got_frame)
{
m_nVideoFrames++;
m_VideoPosition += input_video_dec_ctx->time_base.num /
(double) input_video_dec_ctx->time_base.den;
// ok now encode image into output format
av_init_packet(&output_pkt);
output_pkt.data = NULL; // packet data will be allocated by
the encoder
output_pkt.size = 0;
frame->pict_type = AV_PICTURE_TYPE_NONE;
frame->format = output_video_enc_ctx->pix_fmt;
frame->pts = AV_NOPTS_VALUE;
ret =
avcodec_encode_video2(output_video_enc_ctx,&output_pkt,frame,&got_output);
if (got_output)
{
output_pkt.stream_index = output_video_stream->index;
// Write the compressed frame to the media file.
av_interleaved_write_frame(output_fmt_ctx, &output_pkt);
av_free_packet(&output_pkt);
}
}
and for audio, it is quite the same thing...
then i've got a while loop like this :
while (ffmpeg_muxer.read_video_packet() >= 0)
{
ffmpeg_muxer.decode_encode_video_packet(&got_frame, 0, pParam);
ffmpeg_muxer.free_video_packet();
if (bAudio)
{
while (ffmpeg_muxer.GetAudioPosition() <=
ffmpeg_muxer.GetVideoPosition())
{
if (ffmpeg_muxer.read_audio_packet() >= 0)
{
ffmpeg_muxer.decode_audio_packet(&got_audio_frame, 0);
ffmpeg_muxer.free_audio_packet();
}
else
{
// flush audio
ffmpeg_muxer.flush_audio(&got_audio_frame);
bAudio = FALSE;
break;
}
}
}
}
At the end of this while loop, I wrote the correct number of frames
(audio and video). The length of the two streams are correct.... but
when the trailer is written, the output file is not good.... very very
strange...
Thanks again for any help
More information about the Libav-user
mailing list