LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-20-2013, 06:47 AM   #1
earthw0rmjim
Member
 
Registered: Sep 2011
Distribution: Debian testing
Posts: 62

Rep: Reputation: 12
ffmpeg audio/video sync issues


Hey guys!

I'm streaming to twitch.tv using the following code:
Code:
INRES="1920x1080" # input resolution
OUTRES="864x486"
FPS="30" # target FPS
QUAL="fast"  # x264 preset
STREAM_KEY="$1"
URL="rtmp://live.justin.tv/app/$STREAM_KEY"

ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i :0.0 \
    -f alsa -ac 2 -i pulse -vcodec libx264 -pix_fmt yuv420p -crf 30 -preset "$QUAL" -s "$OUTRES" \
    -acodec libmp3lame -ar 44100 -threads 0 \
    -f flv "$URL"
The problem is the audio is out of sync right from the start (sound comes after the video).
I can fix it temporarily using the -itsoffset option of ffmpeg, but after a while it just goes out of sync again.
Tried writing to an mkv file instead of the stream URL, the problem still appeared.

Log:
Code:
$ stream
ffmpeg version 2.0 Copyright (c) 2000-2013 the FFmpeg developers
  built on Oct 20 2013 08:30:53 with gcc 4.8 (Debian 4.8.1-10)
  configuration: --enable-gpl --enable-libpulse --enable-libx264 --enable-libmp3lame --enable-nonfree --enable-x11grab
  libavutil      52. 47.101 / 52. 47.101
  libavcodec     55. 37.102 / 55. 37.102
  libavformat    55. 19.103 / 55. 19.103
  libavdevice    55.  4.100 / 55.  4.100
  libavfilter     3. 88.102 /  3. 88.102
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
[x11grab @ 0x233f3e0] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 1920 height: 1080
[x11grab @ 0x233f3e0] shared memory extension found
Input #0, x11grab, from ':0.0':
  Duration: N/A, start: 1382268991.129668, bitrate: 1990656 kb/s
    Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1920x1080, 1990656 kb/s, 30 tbr, 1000k tbn, 30 tbc
Guessed Channel Layout for  Input Stream #1.0 : stereo
Input #1, alsa, from 'pulse':
  Duration: N/A, start: 1382268990.754322, bitrate: 1536 kb/s
    Stream #1:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
[swscaler @ 0x2321040] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 0x2372da0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x2372da0] profile High, level 3.1
[libx264 @ 0x2372da0] 264 - core 133 r2339 585324f - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=1 ref=2 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=6 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=30 rc=crf mbtree=1 crf=30.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'rtmp://live.justin.tv/app/live_50378913_TW6NMKbySlLiywXK5Aykr5s74sUNV1':
  Metadata:
    encoder         : Lavf55.19.103
    Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 864x486, q=-1--1, 1k tbn, 30 tbc
    Stream #0:1: Audio: mp3 (libmp3lame) ([2][0][0][0] / 0x0002), 44100 Hz, stereo, s16p
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> libx264)
  Stream #1:0 -> #0:1 (pcm_s16le -> libmp3lame)
Press [q] to stop, [?] for help
frame=   45 fps=0.0 q=36.0 size=       3kB time=00:00:00.10 bitrate= 270.9kbits/
frame=   49 fps= 37 q=36.0 size=      30kB time=00:00:00.23 bitrate=1056.1kbits/
frame=   55 fps= 30 q=36.0 size=      48kB time=00:00:00.43 bitrate= 905.1kbits/
frame=   59 fps= 25 q=36.0 size=      85kB time=00:00:00.56 bitrate=1235.1kbits/
frame=   72 fps= 25 q=36.0 size=     116kB time=00:00:01.00 bitrate= 948.0kbits/
.
.
.
Is there a way to fix this?
I'd appreciate any advice, thanks in advance!

edit:
Tried to use aac instead of libmp3lame. At the start of the stream the audio actually came before the video, after a while they were in sync and then it started to come after the video. So it progressively worsened. Same thing happens with libmp3lame, only difference is that using libmp3lame the sound always comes after the video, never before it.

edit2:
Fixed it by removing the -r input option. Figured out (from ffmpeg documentation) it generates timestamps as if frame rate were constant.

Last edited by earthw0rmjim; 10-21-2013 at 11:57 AM.
 
Old 11-03-2013, 04:42 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by earthw0rmjim View Post
edit2:
Fixed it by removing the -r input option. Figured out (from ffmpeg documentation) it generates timestamps as if frame rate were constant.
Thanks for posting your solution.
 
Old 12-03-2013, 08:30 PM   #3
Kranium31
LQ Newbie
 
Registered: Dec 2013
Posts: 2

Rep: Reputation: Disabled
I'm glad you posted this. I've been looking for a way to solve my sync issues on jtv.

Thank you.
 
Old 12-04-2013, 07:20 AM   #4
Kranium31
LQ Newbie
 
Registered: Dec 2013
Posts: 2

Rep: Reputation: Disabled
The sound went out again over night. Any ideas?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
FFMPEG video is out of sync dermetfan Linux - Software 19 09-19-2013 06:05 PM
ffmpeg mixing audio/video - trying to end vid after video stream completes joejoe99 Linux - Software 2 06-21-2012 11:44 PM
ffmpeg and mencoder slice mp4 video audio out of sync lindylex Linux - Software 5 01-10-2010 03:26 AM
Audio completely out of sync with video playback. (FFmpeg/Xine/VLC) 12.2/2.6.27.7-smp camphor Slackware 9 02-17-2009 01:20 AM
i want to sync my video using ffmpeg Jeon, Chang-Min Linux - Software 0 11-17-2005 03:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration