Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit 89cc851

Browse files
committed
increase robustness for non-audio streams, cleanup Windows options
1 parent 80d63a7 commit 89cc851

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

PyLivestream/__init__.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ def osparam(self):
124124
self.timelimit = C.get(self.site,'timelimit',fallback=None)
125125

126126
self.videochan = C.get(sys.platform,'videochan')
127-
self.audiochan = C.get(sys.platform,'audiochan')
127+
self.audiochan = C.get(sys.platform,'audiochan', fallback=None)
128128
self.vcap = C.get(sys.platform,'vcap')
129-
self.acap = C.get(sys.platform,'acap')
129+
self.acap = C.get(sys.platform,'acap', fallback=None)
130130
self.hcam = C.get(sys.platform,'hcam')
131-
self.exe = C.get(sys.platform,'exe',fallback='ffmpeg')
131+
self.exe = getexe(C.get(sys.platform,'exe',fallback='ffmpeg'))
132132

133133

134134
self.video_kbps = C.getint(self.site, 'video_kbps', fallback=None)
@@ -175,15 +175,18 @@ def videostream(self) -> tuple:
175175

176176
def audiostream(self) -> list:
177177
"""
178+
-ac * may not be needed, took out.
178179
-ac 2 NOT -ac 1 to avoid "non monotonous DTS in output stream" errors
179180
"""
180-
if not self.audio_bps:
181+
if not self.audio_bps or not self.acap or not self.audiochan:
181182
return []
182183

183184
if not self.vidsource == 'file':
184-
return ['-f', self.acap, '-ac','2', '-i', self.audiochan]
185-
else: # file input
186-
return ['-ac','2']
185+
return ['-f', self.acap, '-i', self.audiochan]
186+
else: # file input
187+
return []
188+
# else: # file input
189+
# return ['-ac','2']
187190

188191

189192
def audiocomp(self) -> list:
@@ -193,7 +196,7 @@ def audiocomp(self) -> list:
193196
https://www.facebook.com/facebookmedia/get-started/live
194197
"""
195198

196-
if not self.audio_bps:
199+
if not self.audio_bps or not self.acap or not self.audiochan:
197200
return []
198201

199202
return ['-c:a','aac',
@@ -231,7 +234,8 @@ def screengrab(self) -> list:
231234
if sys.platform =='linux':
232235
vid1 += ['-i', ':0.0+{},{}'.format(self.origin[0], self.origin[1])]
233236
elif sys.platform =='win32':
234-
vid1 += ['-i', self.videochan]
237+
vid1 += ['-offset_x',self.origin[0],'-offset_y',self.origin[1],
238+
'-i', self.videochan,]
235239
elif sys.platform == 'darwin':
236240
pass # FIXME: verify
237241

@@ -433,9 +437,9 @@ def __init__(self, ini:Path, outfn:Path=None, clobber:bool=False):
433437
aud1 = self.audiostream()
434438
aud2 = self.audiocomp()
435439

436-
cmd = [self.exe] + vid1 + vid2 + aud1 + aud2
440+
cmd = [self.exe] + vid1 + aud1 + vid2 + aud2
437441

438-
if not outfn.suffix: # ffmpeg relies on suffix for container type, this is a fallback.
442+
if outfn and not outfn.suffix: # ffmpeg relies on suffix for container type, this is a fallback.
439443
cmd += ['-f','flv']
440444

441445
cmd += [str(outfn)]
@@ -446,13 +450,16 @@ def __init__(self, ini:Path, outfn:Path=None, clobber:bool=False):
446450
if clobber:
447451
cmd += ['-y']
448452

449-
if sys.platform == 'win32':
450-
cmd += ['-copy_ts']
453+
# if sys.platform == 'win32':
454+
# cmd += ['-copy_ts']
451455

452456
print('\n',' '.join(cmd),'\n')
453457

454458
if outfn:
455-
ret = sp.run(cmd).returncode
456-
print('FFmpeg returncode',ret)
459+
try:
460+
ret = sp.run(cmd).returncode
461+
print('FFmpeg returncode',ret)
462+
except FileNotFoundError:
463+
pass
457464
else:
458465
print('specify filename to save screen capture with audio to disk.')

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ FFmpeg References
245245

246246
Windows
247247
~~~~~~~
248+
249+
* `gdigrab <https://ffmpeg.org/ffmpeg-devices.html#gdigrab>`_
250+
251+
DirectShow didn't work for me on Windows 10, so I used gdigrab instead.
248252
* `DirectShow <https://trac.ffmpeg.org/wiki/DirectShow>`_ device selection
249253
* DirectShow `examples <https://ffmpeg.org/ffmpeg-devices.html#Examples-4>`_
250254

setup.py

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env python
22
install_requires=['numpy']
3-
tests_require=['pytest','coveralls']
3+
tests_require=['pytest','nose','coveralls']
44
from setuptools import setup,find_packages
55

66
setup(name='PyLivestream',
77
packages=find_packages(),
8-
version = '1.4.5',
8+
version = '1.4.6',
99
author='Michael Hirsch, Ph.D.',
1010
url='https://github.com/scivision/PyLivestream',
1111
description='Easy streaming using FFmpeg to YouTube Live, Periscope, Facebook Live, Twitch, ...',

stream.ini

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ timelimit:
1313

1414
# indexed by sys.platform
1515
[win32]
16-
videochan: video="UScreenCapture"
17-
audiochan: audio="Internal Microphone"
18-
vcap: dshow
16+
vcap: gdigrab
17+
videochan: desktop
18+
#vcap: dshow
19+
#videochan: video="UScreenCapture"
1920
acap: dshow
21+
#audiochan: audio="Internal Microphone"
2022
hcam: dshow
2123
[darwin]
2224
videochan: default
@@ -76,4 +78,4 @@ key: vimeo.key
7678
[file]
7779
video_kbps: 2000
7880
screencap_res: 720x420
79-
audio_bps:
81+
#audio_bps:

0 commit comments

Comments
 (0)