1

What's the best way to fix incorrect timestamps on a network camera using ffmpeg?

Running the camera in h264 mode with a 1fps correctly produces duration=1.000:

ffmpeg -hide_banner -rtsp_transport tcp  -i rtsp://xxx -dump -
an -f null -                                                                                                                         

Input #0, rtsp, from 'rtsp://xxx':                                     
  Metadata:                                                                                                                          
    title           : Media Presentation                                                                                             
  Duration: N/A, start: 6.040000, bitrate: N/A                                                                                       
    Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 1280x720, 1 fps, 1 tbr, 90k tbn, 2 tbc                        
Stream mapping:                                                                                                                      
  Stream #0:0 -> #0:0 (h264 (native) -> wrapped_avframe (native))                                                                    
Press [q] to stop, [?] for help                                                                                                      
stream #0:                                                                                                                           
  keyframe=1                                                                                                                         
  duration=1.000                                                                                                                     
  dts=6.040  pts=6.040                                                                                                               
  size=86223                                                                                                                         
stream #0:                                                                                                                           
  keyframe=0                                                                                                                         
  duration=1.000                                                                                                                     
  dts=1.040  pts=1.040                                                                                                               
  size=169092                                                                                                                        
...

and when running the camera the h265 encoder incorrectly produces a duration=0.500:

ffmpeg -hide_banner -rtsp_transport tcp  -i rtsp://xxx -dump -an -
f null -

[hevc @ 0x55f93da71e40] VPS 0 does not exist
    Last message repeated 1 times                                                                                                    
Input #0, rtsp, from 'rtsp://xxx':
  Metadata:
    title           : Media Presentation
  Duration: N/A, start: 1.040000, bitrate: N/A
    Stream #0:0: Video: hevc (Main), yuv420p(tv), 1280x720, 2 fps, 1 tbr, 90k tbn, 2 tbc
[hevc @ 0x55f93da84380] VPS 0 does not exist
Stream mapping:                                                                                                                      
  Stream #0:0 -> #0:0 (hevc (native) -> wrapped_avframe (native))
Press [q] to stop, [?] for help
stream #0:
  keyframe=1
  duration=0.500
  dts=N/A  pts=N/A
  size=81210
stream #0:
  keyframe=0
  duration=0.500
  dts=1.040  pts=1.040
  size=142218
...

I am using the following to dump the feed to disk. Is there a way to override the duration=0.500 using ffmpeg and without re-encoding?

I have tried setting the -r flag to adjust the framerate, but videos still play back at double speed:

ffmpeg -use_wallclock_as_timestamps -r 1 -rtsp_transport tcp -i rtsp://xx -an -vcodec copy -f hvec -r 1 /tmp/out.ts -y

So it there a good way to change the display duration in the RTSP feed (DTS and PTS values look to be correct) before writing it out to disk? I seem to be missing something.

8
  • Show the dts/pts for a few more packets.
    – Gyan
    Apr 29, 2019 at 5:17
  • from ffprobe -analyzeduration 10000000 -unit -use_wallclock_as_timestamps 1 -hide_banner -loglevel info -show_entries packet=pts_time,duration_time,stream_index:stream=index,codec_type -rtsp_transport tcp -i rtsp://xxx we get gist.github.com/imaginator/2332e4c70786647aaa3c9ef8de72b97d
    – Imaginator
    Apr 29, 2019 at 7:47
  • Don't add -use_wallclock_as_timestamps 1
    – Gyan
    Apr 29, 2019 at 7:52
  • ffprobe -analyzeduration 10000000 -unit -hide_banner -loglevel info -show_entries packet=pts_time,duration_time,stream_index:stream=index,codec_type -rtsp_transport tcp -i rtsp://xxx > out.txt gist.github.com/imaginator/5ef329cd18eb036f926e38c080ddfd49
    – Imaginator
    Apr 29, 2019 at 8:02
  • it's worth adding that the video plays just fine in ffplay, mpv, vlc. Only when writing to disk and playing back using the same tools, does the double-speed happen.
    – Imaginator
    Apr 29, 2019 at 8:20

1 Answer 1

0

Use

ffmpeg -rtsp_transport tcp -i rtsp://xx -an -vcodec copy -bsf:v hevc_metadata=tick_rate=1 /tmp/out.hevc -y

2
  • Solves the playback speed issue nicely. Thanks @gyan. Do you know what was causing the duration of 0.5s to be created in the first place?
    – Imaginator
    Apr 29, 2019 at 10:14
  • The camera is writing (in effect) a fps of 2 in the stream's internal metadata.
    – Gyan
    Apr 29, 2019 at 10:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .