Skip to content

switch to pulse format if alsa format not available #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ X Window Recording Tool

ffmpeg configuration
--------------------
The ffmpeg configuration requires the following for xcorder to work properly:
> --extra-libs=-lasound
> --enable-x11grab
The ffmpeg build configuration requires the following for xcorder to work properly:
> `--extra-libs=-lasound` or `--enable-libpulse`

and

> `--enable-x11grab`
22 changes: 20 additions & 2 deletions audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ def __init__(self):
self._devices = list()
self._device = Device()

args = 'ffmpeg -formats -v 0'
popen = subprocess.Popen(args, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

alsa = pulse = False
for line in popen.stdout:
if "alsa" in line:
alsa = True
elif "pulse" in line:
pulse = True

if not alsa and not pulse:
raise Exception("available ffmpeg installation have not lasound or libpulse enabled")

args = 'pacmd list-sources'
popen = subprocess.Popen(args, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Expand All @@ -34,7 +48,10 @@ def __init__(self):
device.name = line.split(':', 1)[1].strip()

elif line.startswith('device.api = '):
device.api = line.split('=', 1)[1].strip().strip('"')
api = line.split('=', 1)[1].strip().strip('"')
if api == "alsa" and not alsa:
api = "pulse"
device.api = api

elif line.startswith('alsa.subdevice = '):
device.subdevice = line.split('=', 1)[1].strip().strip('"')
Expand Down Expand Up @@ -87,7 +104,8 @@ def __init__(self, name=None, api=None, subdevice=None, card=None,
# =========================================================================
@property
def source(self):

if self.api == "pulse":
return '{deviceName}'.format(deviceName=self.name[1:-1])
return 'plughw:{c},{s}'.format(c=self.card, s=self.subdevice)

# =========================================================================
Expand Down
6 changes: 5 additions & 1 deletion exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# =============================================================================
# CLASSES
# =============================================================================
import os


class Exporter(object):

# =========================================================================
Expand All @@ -27,6 +30,7 @@ def __init__(self, workDir=None, exportFile=None):
# =========================================================================
def start(self):

print self.args
self.makeFileList()
if not self._proc:
self._proc = subprocess.Popen(self.args, shell=True,
Expand All @@ -53,7 +57,7 @@ def makeFileList(self):

with open(self.fileList, 'w') as fileList:
for segmentFile in segmentFiles:
fileList.write("file '{f}'\n".format(f=segmentFile))
fileList.write("file '{f}'\n".format(f=os.path.basename(segmentFile)))

# =========================================================================
@property
Expand Down
2 changes: 1 addition & 1 deletion xcorder
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/bin/env python2
# =============================================================================
# Module: xcorder
# Contacts: Edward Li ([email protected])
Expand Down