Mjpeg recording with FFMPEG preserving time information

14,732

Solution 1

I know this is an old question, however, this worked for me as an option to ffmpeg: -use_wallclock_as_timestamps 1

Solution 2

I had a similar problem and the -re option resolved it for me. This tells ffmpeg to act as a frame grabber would act.

Share:
14,732

Related videos on Youtube

Muhammad Adeel Zahid
Author by

Muhammad Adeel Zahid

Updated on September 18, 2022

Comments

  • Muhammad Adeel Zahid
    Muhammad Adeel Zahid over 1 year

    I am recording the MJPEG video from an IP camera and saving it to a file but the problem is that file's duration is way smaller than the actual recording time. Its around 9 seconds video for 2 minutes recording. I tried following commands in order

    ffmpeg -f mjpeg -r 8 -i http://c-cam.uchicago.edu/mjpg/video.mjpg -vcodec mpeg4 -b 1000000 -r 8 video_file.avi 
    

    Then I omitted the most of the flags and tried like this

    ffmpeg -f mjpeg -i http://c-cam.uchicago.edu/mjpg/video.mjpg video_file.avi
    

    But the problem is that the duration of recorded file is 9 seconds where as the actual recording time is around 2 minutes. I finally tried setpts filter that is supposed to insert the timestamps. The command is as follows

    ffmpeg -f mjpeg -i http://c-cam.uchicago.edu/mjpg/video.mjpg -vf "setpts=1*PTS" video_file.avi
    

    But result was still the same. Recording time was way more than video duration.

    • akira
      akira over 11 years
      are you missing images / frames from the final video (eg, the file is "just to short for my gut feeling")? is it just the "display of the presentational timestamps (pts)" that annoyes you?
    • Muhammad Adeel Zahid
      Muhammad Adeel Zahid over 11 years
      I don't know exactly if frames are dropped. I think they are because video is recorded from internet source. The actual thing that worries me is that I record video for 2 minutes and final video plays back just for 9 seconds. I think it has to do something with frame rate. Say, ffmpeg sets the frame rate to 10 frames/second and it receives 100 frames over two minutes but, it would just play it for 10 seconds. That's my understanding of the problem!
  • Ярослав Рахматуллин
    Ярослав Рахматуллин about 11 years
    Answering old questions is totally acceptable. Would you care to elaborate on what the effect of that option is? The relevant parts of the manual page could be included, for example.
  • Jann
    Jann about 11 years
    This forces FFMPEG (a hack really) to use the recording SYSTEM's timestamp instead of trying to compute the time of the movie depending on the number of fps it detects. FPS detection is notoriously inaccurate, for instance -- as FFMPEG freely admits when it gives this error: Estimating duration from bitrate, this may be inaccurate. This also enables the -t flag (duration) to be realtime as well, instead of also being dependent on the fps calculation.