From 1645a76f6cdd5f62c3ee8c9dc860ee034ee81899 Mon Sep 17 00:00:00 2001 From: Petru Date: Sat, 11 Nov 2017 02:58:06 -0800 Subject: [PATCH 1/3] use pulse when ffmpeg do not have alsa config enabled on some systems, for example on Fedora 26, the ffmpeg is compiled with the libalsa support disable. --- audio.py | 20 ++++++++++++++++++-- exporter.py | 2 ++ xcorder | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/audio.py b/audio.py index aaf8525..011ec1b 100644 --- a/audio.py +++ b/audio.py @@ -22,6 +22,18 @@ def __init__(self): self._devices = list() self._device = Device() + libalsa = libpulse = False + + args = 'ffmpeg -version | grep -o "libalsa\|libpulse"' + popen = subprocess.Popen(args, shell=True, + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + + for line in popen.stdout: + if "alsa" in line: + libalsa = True + elif "pulse" in line: + libpulse = True + args = 'pacmd list-sources' popen = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) @@ -34,7 +46,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 libalsa and libpulse: + api = "pulse" + device.api = api elif line.startswith('alsa.subdevice = '): device.subdevice = line.split('=', 1)[1].strip().strip('"') @@ -87,7 +102,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) # ========================================================================= diff --git a/exporter.py b/exporter.py index 1bce828..6f0c6d6 100644 --- a/exporter.py +++ b/exporter.py @@ -27,6 +27,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, @@ -66,6 +67,7 @@ def args(self): def optionArgs(self): return '-f concat ' + \ + '-safe 0 ' \ '-i {i} '.format(i=self.fileList) + \ '-codec copy ' + \ '-y ' + \ diff --git a/xcorder b/xcorder index 57a5948..aa20387 100755 --- a/xcorder +++ b/xcorder @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/bin/env python2 # ============================================================================= # Module: xcorder # Contacts: Edward Li (drawdeil@gmail.com) From 60ec754bc3c5a54c4c60215d467cfb3f3bc7111e Mon Sep 17 00:00:00 2001 From: Petru Date: Sat, 11 Nov 2017 20:30:50 -0800 Subject: [PATCH 2/3] use relative file names improvements - in order to avoid to use the safe argument with the concat one - also, use formats to check the available formats in ffmpeg this seems a better way of doing it. Also this change includes some improvements in the code style. --- audio.py | 14 ++++++++------ exporter.py | 6 ++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/audio.py b/audio.py index 011ec1b..3d1ace6 100644 --- a/audio.py +++ b/audio.py @@ -22,17 +22,19 @@ def __init__(self): self._devices = list() self._device = Device() - libalsa = libpulse = False - - args = 'ffmpeg -version | grep -o "libalsa\|libpulse"' + 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: - libalsa = True + alsa = True elif "pulse" in line: - libpulse = True + 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, @@ -47,7 +49,7 @@ def __init__(self): elif line.startswith('device.api = '): api = line.split('=', 1)[1].strip().strip('"') - if api == "alsa" and not libalsa and libpulse: + if api == "alsa" and not alsa: api = "pulse" device.api = api diff --git a/exporter.py b/exporter.py index 6f0c6d6..a142cfb 100644 --- a/exporter.py +++ b/exporter.py @@ -15,6 +15,9 @@ # ============================================================================= # CLASSES # ============================================================================= +import os + + class Exporter(object): # ========================================================================= @@ -54,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 @@ -67,7 +70,6 @@ def args(self): def optionArgs(self): return '-f concat ' + \ - '-safe 0 ' \ '-i {i} '.format(i=self.fileList) + \ '-codec copy ' + \ '-y ' + \ From e7b1e0b5da4e44729dd3b086048b63806b952361 Mon Sep 17 00:00:00 2001 From: Petru Date: Sat, 11 Nov 2017 21:00:33 -0800 Subject: [PATCH 3/3] update the requirements list, added libpulse --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 18db686..b00c90d 100644 --- a/README.md +++ b/README.md @@ -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`