Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Compression Techniques Sound drift when streaming

  • Sound drift when streaming

    Posted by Nadav Talmor on January 8, 2017 at 9:08 am

    Hello

    I am streaming rtmp with ffmpeg from a camera source that delivers 50fps frame rate to a matrox capture card.

    until recently I have been using “vMix” in order to capture the video and release it via dshow to ffmpeg.
    among other things, the “vMix” was taking the frame rate and changing it to 25fps before reaching to ffmpeg.

    due to some circumstances, I tried to avoid using “vMix” and start capturing the video straight to ffmpeg from the card. in order to deal with the frame rate, I have added the command -r 25 to the ffmpeg command.

    from this point on the sound has gotten out of sync while the audio was coming first.

    In order to deal with that I add the commands “-async” and “-itsoffset” which corrected the initial sync issues.

    The problem is that with time (the stream is 24/7) the sound is drifting further away from video to the point that after 20 hours it has a 2 sec delay, when audio is coming before video.

    This is my current command:

    ffmpeg.exe -async 2 -report -rtbufsize 256M -f dshow -i "video=Matrox A/V Input" -itsoffset 0.250 -f dshow -i "audio=Matrox A/V Input" -codec:v libx264 -r 25 -tune fastdecode -tune zerolatency -s:v 1280x720 -pix_fmt:v yuv420p -threads 4 -bufsize:v 1000k -g:v 50 -preset:v ultrafast -profile:v Main -level:v 3.0 -b:v 2500k -maxrate:v 2700k -flush_packets 1 -codec:a libfaac -b:a 64k -strict -2 -map 0:v -map 1:a -rtmp_flashver "FMLE/3.0 (compatible; vMix/15.0.0.74)" -f flv rtmp url -codec:v libx264 -s:v 854x480 -pix_fmt:v yuv420p -threads 0 -bufsize:v 500k -g:v 24 -bf 2 -preset:v veryfast -profile:v Main -level:v 3.1 -b:v 500k -minrate:v 500k -maxrate:v 500k -codec:a libfaac -b:a 64k -strict -2 -map 0:v -map 1:a -rtmp_flashver "FMLE/3.0 (compatible; vMix/15.0.0.74)" -f segment -strftime 1 -segment_list out.list -segment_time 60 -segment_wrap 24 -segment_time_delta 0.02 E:\Share\Video\out_%%d-%%m-%%y_%%H-%%M-%%S.mp4

    the report looks like this:


    ffmpeg started on 2017-01-02 at 12:48:29
    Report written to "E:\Share\LivePBT\Logs\test\1.12\ffmpeg_NadavTest2_out_20170102-124829.log"
    Command line:
    "c:\\LivePBT\\Streaming\\test\\NadavTest2\\ffmpegNadavTest2.exe" -async 2 -report -rtbufsize 256M -f dshow -i "video=Matrox A/V Input" -itsoffset 0.250 -f dshow -i "audio=Matrox A/V Input" -codec:v libx264 -r 25 -tune fastdecode -tune zerolatency -s:v 1280x720 -pix_fmt:v yuv420p -threads 4 -bufsize:v 1000k -g:v 50 -preset:v ultrafast -profile:v Main -level:v 3.0 -b:v 2500k -maxrate:v 2700k -flush_packets 1 -codec:a libfaac -b:a 64k -strict -2 -map 0:v -map 1:a -rtmp_flashver "FMLE/3.0 (compatible; vMix/15.0.0.74)" -f flv rtmp url -codec:v libx264 -s:v 854x480 -pix_fmt:v yuv420p -threads 0 -bufsize:v 500k -g:v 24 -bf 2 -preset:v veryfast -profile:v Main -level:v 3.1 -b:v 500k -minrate:v 500k -maxrate:v 500k -codec:a libfaac -b:a 64k -strict -2 -map 0:v -map 1:a -rtmp_flashver "FMLE/3.0 (compatible; vMix/15.0.0.74)" -f segment -strftime 1 -segment_list out.list -segment_time 60 -segment_wrap 24 -segment_time_delta 0.02 "E:\\Share\\Video\\out_%d-%m-%y_%H-%M-%S.mp4"
    ffmpeg version 2.5.git Copyright (c) 2000-2015 the FFmpeg developers
    built on Jan 8 2015 02:08:21 with Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
    configuration: --enable-gpl --enable-version3 --enable-libx264 --toolchain=msvc --enable-zlib --enable-libfaac --enable-nonfree
    libavutil 54. 16.100 / 54. 16.100
    libavcodec 56. 19.100 / 56. 19.100
    libavformat 56. 18.100 / 56. 18.100
    libavdevice 56. 3.100 / 56. 3.100
    libavfilter 5. 6.100 / 5. 6.100
    libswscale 3. 1.101 / 3. 1.101
    libswresample 1. 1.100 / 1. 1.100
    libpostproc 53. 3.100 / 53. 3.100
    Input #0, dshow, from 'video=Matrox A/V Input':
    Duration: N/A, start: 525121.924000, bitrate: N/A
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1280x720, 50 tbr, 10000k tbn, 50 tbc
    Guessed Channel Layout for Input Stream #1.0 : stereo
    Input #1, dshow, from 'audio=Matrox A/V Input':
    Duration: N/A, start: 525121.937000, bitrate: 1411 kb/s
    Stream #1:0: Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s
    [tcp @ 004DF360] TCP Buffer has been set to 1048576 bytes
    -async is forwarded to lavfi similarly to -af aresample=async=2:min_hard_comp=0.100000:first_pts=0.
    -async is forwarded to lavfi similarly to -af aresample=async=2:min_hard_comp=0.100000:first_pts=0.
    [libx264 @ 004D5F40] frame MB size (80x45) > level limit (1620)
    [libx264 @ 004D5F40] MB rate (90000) > level limit (40500)
    [libx264 @ 004D5F40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
    [libx264 @ 004D5F40] profile Constrained Baseline, level 3.0
    [libx264 @ 004D5F40] 264 - core 144 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 -urll - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=4 lookahead_threads=4 sliced_threads=1 slices=4 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=50 keyint_min=5 scenecut=0 intra_refresh=0 rc_lookahead=0 rc=abr mbtree=0 bitrate=2500 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=2700 vbv_bufsize=1000 nal_hrd=none filler=0 ip_ratio=1.40 aq=0
    [libx264 @ 004D6F60] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
    [libx264 @ 004D6F60] profile Main, level 3.1
    [libx264 @ 004D6F60] 264 - core 144 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - url - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=12 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=2 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=24 keyint_min=2 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=cbr mbtree=1 bitrate=500 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=500 vbv_bufsize=500 nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00
    Output #0, flv, to 'url:
    Metadata:
    encoder : Lavf56.18.100
    Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 1280x720, q=-1--1, 2500 kb/s, 25 fps, 1k tbn, 25 tbc
    Metadata:
    encoder : Lavc56.19.100 libx264
    Stream #0:1: Audio: aac (libfaac) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, s16, 64 kb/s
    Metadata:
    encoder : Lavc56.19.100 libfaac
    Output #1, segment, to 'E:\Share\Video\out_%d-%m-%y_%H-%M-%S.mp4':
    Metadata:
    encoder : Lavf56.18.100
    Stream #1:0: Video: h264 (libx264), yuv420p, 854x480, q=-1--1, 500 kb/s, 50 fps, 12800 tbn, 50 tbc
    Metadata:
    encoder : Lavc56.19.100 libx264
    Stream #1:1: Audio: aac (libfaac), 44100 Hz, stereo, s16, 64 kb/s
    Metadata:
    encoder : Lavc56.19.100 libfaac
    Stream mapping:
    Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
    Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (libfaac))
    Stream #0:0 -> #1:0 (rawvideo (native) -> h264 (libx264))
    Stream #1:0 -> #1:1 (pcm_s16le (native) -> aac (libfaac))
    Press [q] to stop, [?] for help

    The capture card is Matrox Mojito max and the pc is HP Z440 with windows 7.

    What did I do wrong, or, what else can I try?

    Thank you

    Gabriel Balaich replied 8 years, 3 months ago 3 Members · 5 Replies
  • 5 Replies
  • Reuben Martin

    April 9, 2017 at 3:39 am

    What is the source of the audio? I find it odd that the sample rate that ffmpeg is getting from the source is at 44100. That would suggest that the audio is not embedded in the camera video source. If that’s the case you may be suffering from clock drift due to separate audio / video devices running off of separate clocks.

  • Nadav Talmor

    April 9, 2017 at 8:53 am

    Hi Reuben Martin

    Thanks for your reply.

    The sound comes from a mic connected to a mixer/preamp that is connected back to the camera before capture card.

    From the SDI capture card the sound does not drift, but only after encoding the stream.

    BR,

  • Reuben Martin

    April 10, 2017 at 1:56 am

    Where then is the audio getting re-sampled to 44100? Embedded SDI audio is at 48k.

  • Nadav Talmor

    May 15, 2017 at 12:03 pm

    By a preamp mixer.

  • Gabriel Balaich

    March 26, 2018 at 10:36 pm

    Sorry to revive a dead thread but I was wondering if you ever made any progress with this issue?

    I am having the same problem using ffmpeg and have narrowed it down to the use of segmentation, without segmentation there is no a/v drift. But I’d really like to use segmentation…

    You are the only other person online I’ve seen with this issue.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy