1

I am using LibAV for muxing real time audio and video. For this question I am referring to output.c file from LibAV examples. If I record 250 frames at 25 fps using AV_CODEC_ID_MPEG4 then the output video file will be exactly 10 seconds long. But if I use AV_CODEC_ID_H264 for 250 frames at 25 fps then the output video file will be 8.86 seconds long approximately.

I have a working code that uses PortAudio and LibAV for real time muxing. Currently I am using MPEG-4 but the quality of video is inferior to H264. If its possible I'd rather use H264.

My question is : How can I force H264 to record 10 seconds of video for 250 frames at 25 fps?

Thanks.

zindarod
  • 6,328
  • 3
  • 30
  • 58

1 Answers1

0

For encoding instead of muxing it is better to look at avcodec.c example and specfically at this part where delayed frames are returned from encoder. This part is absent in output.c example.

nobody555
  • 2,239
  • 18
  • 18
  • The avcodec.c calculates delay after certain frames has been written. My code writes frames in real time, the number of frames and the duration of the video is not predefined. – zindarod Mar 12 '15 at 07:36
  • No. It is not about calculating delay but about flushing these delayed frames by sending NULL-frames to encode while you still got output from this. If you wouldn't do this when actual frames ended (no matter was that real time or not) than you can loss for around 40 frames. Other way around you can configure libx264 to use zerolatency tuning which will remove all this buffering at the cost of the quality/compression. – nobody555 Mar 12 '15 at 21:03
  • So when frames stop coming from camera then I execute a loop to give NULL frames to the encoder? I am sorry I haven't grasped the real concept behind the encoding process in LibAV. – zindarod Mar 13 '15 at 13:23
  • Also in avcodec.c when I specify the video codec as `AV_CODEC_ID_H264` and container as MP4 then the encoded video does not play in any media player. – zindarod Mar 13 '15 at 14:30