[FFmpeg-user] ffmpeg recording RTSP stream with audio out of sync

Calvert, Andy Andy.Calvert at prozonesports.com
Mon Jun 27 11:07:33 CEST 2016


Hi,
I am having a problem with the video / audio sync when recording from an RTSP stream with ffmpeg.

This is the script I am using (only doing a 10 second clip for test):
-channel_layout mono -i "rtsp://172.16.210.50/RTP-Unicast_pMediaProfile4" -c:v copy -bsf:a aac_adtstoasc -y
-t 10 -movflags faststart "streamtest_high_%datetimef%.mp4"

Which seems to capture the source without any errors:

C:\STREAMTEST>c:\ffmpeg\ffmpeg -channel_layout mono -i "rtsp://172.16.210.50/RTP
-Unicast_pMediaProfile4" -c:v copy -bsf:a aac_adtstoasc -y -t 10 -movflags fasts
tart "streamtest_high_30012015_102911.mp4"
ffmpeg version N-69406-ga73c411 Copyright (c) 2000-2015 the FFmpeg developers
  built on Jan 29 2015 22:02:28 with gcc 4.9.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --
enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-lib
modplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrw
b --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinge
r --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --en
able-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis
--enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-
libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enab
le-zlib
  libavutil      54. 18.100 / 54. 18.100
  libavcodec     56. 21.101 / 56. 21.101
  libavformat    56. 19.100 / 56. 19.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5.  9.101 /  5.  9.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, rtsp, from 'rtsp://172.16.210.50/RTP-Unicast_pMediaProfile4':
  Metadata:
    title           : Session streamed by Oslo
    comment         : RTP-Unicast_pMediaProfile4
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Audio: pcm_mulaw, 8000 Hz, mono, s16, 64 kb/s
    Stream #0:1: Video: h264 (Baseline), yuv420p, 1280x720, 25 fps, 25 tbr, 90k
tbn, 50 tbc
Output #0, mp4, to 'streamtest_high_30012015_102911.mp4':
  Metadata:
    title           : Session streamed by Oslo
    comment         : RTP-Unicast_pMediaProfile4
    encoder         : Lavf56.19.100
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=2-31
, 25 fps, 25 tbr, 90k tbn, 90k tbc
    Stream #0:1: Audio: aac (libvo_aacenc) ([64][0][0][0] / 0x0040), 8000 Hz, mo
no, s16, 128 kb/s
    Metadata:
      encoder         : Lavc56.21.101 libvo_aacenc
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
  Stream #0:0 -> #0:1 (pcm_mulaw (native) -> aac (libvo_aacenc))
Press [q] to stop, [?] for help
frame=   43 fps=0.0 q=-1.0 size=     566kB time=00:00:02.58 bitrate=1795.0kbits/
frame=   56 fps= 53 q=-1.0 size=     863kB time=00:00:03.10 bitrate=2277.3kbits/
frame=   68 fps= 43 q=-1.0 size=    1138kB time=00:00:03.59 bitrate=2596.3kbits/
frame=   81 fps= 39 q=-1.0 size=    1403kB time=00:00:04.10 bitrate=2803.0kbits/
frame=   95 fps= 36 q=-1.0 size=    1646kB time=00:00:04.66 bitrate=2893.5kbits/
frame=  108 fps= 34 q=-1.0 size=    1900kB time=00:00:05.18 bitrate=3001.6kbits/
frame=  120 fps= 33 q=-1.0 size=    2159kB time=00:00:05.66 bitrate=3122.7kbits/
frame=  134 fps= 32 q=-1.0 size=    2325kB time=00:00:06.22 bitrate=3060.6kbits/
frame=  147 fps= 31 q=-1.0 size=    2583kB time=00:00:06.73 bitrate=3139.3kbits/
frame=  159 fps= 31 q=-1.0 size=    2829kB time=00:00:07.21 bitrate=3210.4kbits/
frame=  172 fps= 30 q=-1.0 size=    3163kB time=00:00:07.74 bitrate=3346.2kbits/
frame=  186 fps= 30 q=-1.0 size=    3378kB time=00:00:08.30 bitrate=3332.5kbits/
frame=  199 fps= 29 q=-1.0 size=    3598kB time=00:00:08.82 bitrate=3341.1kbits/
frame=  211 fps= 29 q=-1.0 size=    3902kB time=00:00:09.30 bitrate=3436.8kbits/
frame=  224 fps= 29 q=-1.0 size=    4181kB time=00:00:09.81 bitrate=3489.1kbits/
[mp4 @ 04dfb960] Starting second pass: moving the moov atom to the beginning of
the file
frame=  228 fps= 28 q=-1.0 Lsize=    4402kB time=00:00:10.05 bitrate=3587.7kbits
/s
video:4382kB audio:13kB subtitle:0kB other streams:0kB global headers:0kB muxing
overhead: 0.138498%

The result seems leave the video and audio out of sync in Windows Media Player (which unfortunately is the application I need to use for this), where as VLC seems to be able to cope with this and rectifies the problem.
I thought that it maybe a buffering problem, that ffmpeg is writing the audio track as soon as it receives it, which must be before the video track. I had some success with the -ss command by delaying the recording by x seconds, which seemed to work on some systems but not others.

Does anyone have any idea what is causing this, and provide any suggestions?
Many thanks in advance


More information about the ffmpeg-user mailing list