Advertisement
Guest User

question-leogsa

a guest
Nov 2nd, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.91 KB | None | 0 0
  1. ffmpeg amerge and amix filter delay
  2.  
  3. I need to take audio-streams from several IP cameras and merge them into one file, so that they would sound simaltaneousely.
  4.  
  5. I tried filter "amix": (for testing purposes I take audio-stream 2 times from the same camera. yes, I tried 2 cameras - result is the same)
  6.  
  7.  
  8. ffmpeg -i rtsp://user:pass@172.22.5.202 -i rtsp://user:pass@172.22.5.202 -map 0:a -map 1:a -filter_complex amix=inputs=2:duration=first:dropout_transition=3 -ar 22050 -vn -f flv rtmp://172.22.45.38:1935/live/stream1
  9.  
  10.  
  11. result: I say "hello". And hear in speakers the first "hello" and in 1 second I hear the second "hello". Instead of hearing two "hello"'s simaltaneousely.
  12.  
  13. and tried filter "amerge":
  14.  
  15.  
  16. ffmpeg -i rtsp://user:pass@172.22.5.202 -i rtsp://user:pass@172.22.5.202 -map 0:a -map 1:a -filter_complex amerge -ar 22050 -vn -f flv rtmp://172.22.45.38:1935/live/stream1
  17.  
  18.  
  19. result: the same as in the first example, but now I hear the first "hello" in left speaker and in 1 second I hear the second "hello" in right speaker, instead of hearing two "hello"'s in both speakers simaltaneousely.
  20.  
  21. So, the question is: how to make them sound simaltaneousely? May be you know some parameter? or some other command?
  22.  
  23. P.S. Here is ful command-line output for both variants: amix:
  24.  
  25. ffmpeg -i rtsp://admin:12345@172.22.5.202 -i rtsp://admin:12345@172.22.5.202 -map 0:a -map 1:a -filter_complex amix=inputs=2:duration=longest:dropout_transition=0 -vn -ar 22050 -f flv rtmp://172.22.45.38:1935/live/stream1 ffmpeg version N-76031-g9099079 Copyright (c) 2000-2015 the FFmpeg developers
  26. built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-16)
  27. configuration: --enable-gpl --enable-libx264 --enable-libmp3lame --enable-nonfree --enable-version3
  28. libavutil 55. 4.100 / 55. 4.100
  29. libavcodec 57. 6.100 / 57. 6.100
  30. libavformat 57. 4.100 / 57. 4.100
  31. libavdevice 57. 0.100 / 57. 0.100
  32. libavfilter 6. 11.100 / 6. 11.100
  33. libswscale 4. 0.100 / 4. 0.100
  34. libswresample 2. 0.100 / 2. 0.100
  35. libpostproc 54. 0.100 / 54. 0.100
  36. Input #0, rtsp, from 'rtsp://admin:12345@172.22.5.202':
  37. Metadata:
  38. title : Media Presentation
  39. Duration: N/A, start: 0.032000, bitrate: N/A
  40. Stream #0:0: Video: h264 (Baseline), yuv420p, 1280x720, 20 fps, 25 tbr, 90k tbn, 40 tbc
  41. Stream #0:1: Audio: adpcm_g726, 8000 Hz, mono, s16, 16 kb/s
  42. Stream #0:2: Data: none
  43. Input #1, rtsp, from 'rtsp://admin:12345@172.22.5.202':
  44. Metadata:
  45. title : Media Presentation
  46. Duration: N/A, start: 0.032000, bitrate: N/A
  47. Stream #1:0: Video: h264 (Baseline), yuv420p, 1280x720, 20 fps, 25 tbr, 90k tbn, 40 tbc
  48. Stream #1:1: Audio: adpcm_g726, 8000 Hz, mono, s16, 16 kb/s
  49. Stream #1:2: Data: none
  50. Output #0, flv, to 'rtmp://172.22.45.38:1935/live/stream1':
  51. Metadata:
  52. title : Media Presentation
  53. encoder : Lavf57.4.100
  54. Stream #0:0: Audio: mp3 (libmp3lame) ([2][0][0][0] / 0x0002), 22050 Hz, mono, fltp (default)
  55. Metadata:
  56. encoder : Lavc57.6.100 libmp3lame
  57. Stream mapping:
  58. Stream #0:1 (g726) -> amix:input0
  59. Stream #1:1 (g726) -> amix:input1
  60. amix -> Stream #0:0 (libmp3lame)
  61. Press [q] to stop, [?] for help
  62. [rtsp @ 0x2689600] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
  63. [rtsp @ 0x2727c60] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
  64. [rtsp @ 0x2689600] max delay reached. need to consume packet
  65. [NULL @ 0x268c500] RTP: missed 38 packets
  66. [rtsp @ 0x2689600] max delay reached. need to consume packet
  67. [NULL @ 0x268d460] RTP: missed 4 packets
  68. [flv @ 0x2958360] Failed to update header with correct duration.
  69. [flv @ 0x2958360] Failed to update header with correct filesize.
  70. size= 28kB time=00:00:06.18 bitrate= 36.7kbits/s
  71. video:0kB audio:24kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 16.331224%
  72.  
  73.  
  74. and amerge:
  75.  
  76. # ffmpeg -i rtsp://admin:12345@172.22.5.202 -i rtsp://admin:12345@172.22.5.202 -map 0:a -map 1:a -filter_complex amerge -vn -ar 22050 -f flv rtmp://172.22.45.38:1935/live/stream1
  77. ffmpeg version N-76031-g9099079 Copyright (c) 2000-2015 the FFmpeg developers
  78. built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-16)
  79. configuration: --enable-gpl --enable-libx264 --enable-libmp3lame --enable-nonfree --enable-version3
  80. libavutil 55. 4.100 / 55. 4.100
  81. libavcodec 57. 6.100 / 57. 6.100
  82. libavformat 57. 4.100 / 57. 4.100
  83. libavdevice 57. 0.100 / 57. 0.100
  84. libavfilter 6. 11.100 / 6. 11.100
  85. libswscale 4. 0.100 / 4. 0.100
  86. libswresample 2. 0.100 / 2. 0.100
  87. libpostproc 54. 0.100 / 54. 0.100
  88. Input #0, rtsp, from 'rtsp://admin:12345@172.22.5.202':
  89. Metadata:
  90. title : Media Presentation
  91. Duration: N/A, start: 0.064000, bitrate: N/A
  92. Stream #0:0: Video: h264 (Baseline), yuv420p, 1280x720, 20 fps, 25 tbr, 90k tbn, 40 tbc
  93. Stream #0:1: Audio: adpcm_g726, 8000 Hz, mono, s16, 16 kb/s
  94. Stream #0:2: Data: none
  95. Input #1, rtsp, from 'rtsp://admin:12345@172.22.5.202':
  96. Metadata:
  97. title : Media Presentation
  98. Duration: N/A, start: 0.032000, bitrate: N/A
  99. Stream #1:0: Video: h264 (Baseline), yuv420p, 1280x720, 20 fps, 25 tbr, 90k tbn, 40 tbc
  100. Stream #1:1: Audio: adpcm_g726, 8000 Hz, mono, s16, 16 kb/s
  101. Stream #1:2: Data: none
  102. [Parsed_amerge_0 @ 0x3069cc0] No channel layout for input 1
  103. [Parsed_amerge_0 @ 0x3069cc0] Input channel layouts overlap: output layout will be determined by the number of distinct input channels
  104. Output #0, flv, to 'rtmp://172.22.45.38:1935/live/stream1':
  105. Metadata:
  106. title : Media Presentation
  107. encoder : Lavf57.4.100
  108. Stream #0:0: Audio: mp3 (libmp3lame) ([2][0][0][0] / 0x0002), 22050 Hz, stereo, s16p (default)
  109. Metadata:
  110. encoder : Lavc57.6.100 libmp3lame
  111. Stream mapping:
  112. Stream #0:1 (g726) -> amerge:in0
  113. Stream #1:1 (g726) -> amerge:in1
  114. amerge -> Stream #0:0 (libmp3lame)
  115. Press [q] to stop, [?] for help
  116. [rtsp @ 0x2f71640] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
  117. [rtsp @ 0x300fb40] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
  118. [rtsp @ 0x2f71640] max delay reached. need to consume packet
  119. [NULL @ 0x2f744a0] RTP: missed 18 packets
  120. [flv @ 0x3058b00] Failed to update header with correct duration.
  121. [flv @ 0x3058b00] Failed to update header with correct filesize.
  122. size= 39kB time=00:00:04.54 bitrate= 70.2kbits/s
  123. video:0kB audio:36kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 8.330614%
  124.  
  125.  
  126.  
  127. Thanx.
  128.  
  129. UPDATE 30 oct 2015: I found interesting detail when connecting 2 cameras (they have different microphones and I hear the difference between them): the order of "Hello"'s from different cams depends on the ORDER OF INPUTS.
  130. with command
  131.  
  132.  
  133. ffmpeg -i rtsp://cam2 -i rtsp://cam1 -map 0:a -map 1:a -filter_complex amix=inputs=2:duration=longest:dropout_transition=0 -vn -ar 22050 -f flv rtmp://172.22.45.38:1935/live/stream1
  134.  
  135.  
  136. I hear "hello" from 1st cam and then in 1 second "hello" from 2nd cam.
  137.  
  138. with command
  139.  
  140. ffmpeg -i rtsp://cam1 -i rtsp://cam2 -map 0:a -map 1:a -filter_complex amix=inputs=2:duration=longest:dropout_transition=0 -vn -ar 22050 -f flv rtmp://172.22.45.38:1935/live/stream1
  141.  
  142. I hear "hello" from 2nd cam and then in 1 second "hello" from 1st cam.
  143.  
  144. So, As I understand - ffmpeg takes inputs not simaltaneousely, but in the order of inputs given.
  145. Question: how to tell ffmpeg to read inputs simaltaneousely?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement