ffmpeg to fix video playback speed without re-encoding?

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.

Imaginator

Posted 2019-04-28T21:24:02.453

Reputation: 23

Show the dts/pts for a few more packets. – Gyan – 2019-04-29T05:17:02.633

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 https://gist.github.com/imaginator/2332e4c70786647aaa3c9ef8de72b97d

– Imaginator – 2019-04-29T07:47:07.663

Don't add -use_wallclock_as_timestamps 1 – Gyan – 2019-04-29T07:52:05.833

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 https://gist.github.com/imaginator/5ef329cd18eb036f926e38c080ddfd49 – Imaginator – 2019-04-29T08:02:39.147

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 – 2019-04-29T08:20:38.760

Try ffmpeg -rtsp_transport tcp -i rtsp://xx -an -vcodec copy -bsf:v hevc_metadata=tick_rate=2 /tmp/out.hevc -y – Gyan – 2019-04-29T08:57:09.590

unfortunately it's still double speed. I exposed the feed - should be accessible with rtsp://test:stackexchange123@f17gw.imaginator.com:554/ISAPI/streaming/channels/101 in case that is useful – Imaginator – 2019-04-29T09:46:39.490

Added working command as answer. – Gyan – 2019-04-29T10:02:31.720

Answers

0

Use

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

Gyan

Posted 2019-04-28T21:24:02.453

Reputation: 21 016

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 – 2019-04-29T10:14:17.883

The camera is writing (in effect) a fps of 2 in the stream's internal metadata. – Gyan – 2019-04-29T10:15:28.043