Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Multimedia
Kdenlive
Commits
ac43da1c
Commit
ac43da1c
authored
Apr 17, 2019
by
Jean-Baptiste Mardelle
Browse files
Fix AppImage audio recording (switch from wav to flac)
parent
6dd5e215
Pipeline
#2509
passed with stage
in 20 minutes and 10 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/capture/mediacapture.cpp
View file @
ac43da1c
...
...
@@ -37,6 +37,9 @@ MediaCapture::MediaCapture(QObject *parent)
{
m_probe
=
std
::
make_unique
<
QAudioProbe
>
(
this
);
connect
(
m_probe
.
get
(),
&
QAudioProbe
::
audioBufferProbed
,
this
,
&
MediaCapture
::
processBuffer
);
m_resetTimer
.
setInterval
(
5000
);
m_resetTimer
.
setSingleShot
(
true
);
connect
(
&
m_resetTimer
,
&
QTimer
::
timeout
,
this
,
&
MediaCapture
::
resetIfUnused
);
}
MediaCapture
::~
MediaCapture
()
=
default
;
...
...
@@ -46,13 +49,29 @@ void MediaCapture::displayErrorMessage()
qDebug
()
<<
" !!!!!!!!!!!!!!!! ERROR : QMediarecorder - Capture failed"
;
}
void
MediaCapture
::
resetIfUnused
()
{
QMutexLocker
lk
(
&
m_recMutex
);
qDebug
()
<<
"// CLEARING REC MANAGER"
;
if
(
m_audioRecorder
&&
m_audioRecorder
->
state
()
==
QMediaRecorder
::
StoppedState
)
{
m_audioRecorder
.
reset
();
}
}
void
MediaCapture
::
recordAudio
(
bool
record
)
{
QMutexLocker
lk
(
&
m_recMutex
);
if
(
!
m_audioRecorder
)
{
m_audioRecorder
=
std
::
make_unique
<
QAudioRecorder
>
(
this
);
m_probe
->
setSource
(
m_audioRecorder
.
get
());
connect
(
m_audioRecorder
.
get
(),
&
QAudioRecorder
::
stateChanged
,
[
&
]
(
QMediaRecorder
::
State
state
)
{
m_recordState
=
state
;
if
(
m_recordState
==
QMediaRecorder
::
StoppedState
)
{
m_resetTimer
.
start
();
m_levels
.
clear
();
emit
levelsChanged
();
pCore
->
finalizeRecording
(
getCaptureOutputLocation
().
toLocalFile
());
}
emit
recordStateChanged
();
});
}
...
...
@@ -61,24 +80,21 @@ void MediaCapture::recordAudio(bool record)
setAudioCaptureDevice
();
m_audioRecorder
->
setAudioInput
(
m_audioDevice
);
setCaptureOutputLocation
();
m_audioRecorder
->
setOutputLocation
(
m_path
);
setAudioVolume
();
m_audioRecorder
->
setVolume
(
m_volume
);
//qDebug()<<"START AREC: "<<m_path<<"\n; CODECS: "<<m_audioRecorder->supportedAudioCodecs();
connect
(
m_audioRecorder
.
get
(),
SIGNAL
(
error
(
QMediaRecorder
::
Error
)),
this
,
SLOT
(
displayErrorMessage
()));
QAudioEncoderSettings
audioSettings
;
audioSettings
.
setCodec
(
"audio/x-flac"
);
audioSettings
.
setBitRate
(
48000
);
// Bit rate is set to 48,0000
QString
container
=
"audio/x-wav"
;
m_audioRecorder
->
setEncodingSettings
(
audioSettings
,
QVideoEncoderSettings
(),
container
);
audioSettings
.
setChannelCount
(
2
);
m_audioRecorder
->
setEncodingSettings
(
audioSettings
);
m_audioRecorder
->
setOutputLocation
(
m_path
);
m_audioRecorder
->
record
();
}
else
if
(
m_audioRecorder
->
state
()
!=
QMediaRecorder
::
PausedState
)
{
m_audioRecorder
->
stop
();
m_audioRecorder
.
reset
();
m_levels
.
clear
();
emit
levelsChanged
();
m_recordState
=
QMediaRecorder
::
StoppedState
;
emit
recordStateChanged
();
}
else
{
m_audioRecorder
->
record
();
}
...
...
@@ -127,7 +143,7 @@ void MediaCapture::setCaptureOutputLocation()
if
(
m_videoRecorder
.
get
()
!=
nullptr
)
{
extension
=
QStringLiteral
(
".mpeg"
);
}
else
if
(
m_audioRecorder
.
get
()
!=
nullptr
)
{
extension
=
QStringLiteral
(
".
wav
"
);
extension
=
QStringLiteral
(
".
flac
"
);
}
QString
path
=
captureFolder
.
absoluteFilePath
(
"capture0000"
+
extension
);
...
...
src/capture/mediacapture.h
View file @
ac43da1c
...
...
@@ -31,6 +31,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QStringList>
#include <QUrl>
#include <QVideoEncoderSettings>
#include <QTimer>
#include <QMutex>
#include <memory>
class
QAudioRecorder
;
...
...
@@ -78,13 +80,17 @@ private:
QUrl
m_path
;
QVector
<
qreal
>
m_levels
;
int
m_recordState
;
QTimer
m_resetTimer
;
QMutex
m_recMutex
;
private
slots
:
void
processBuffer
(
const
QAudioBuffer
&
buffer
);
void
resetIfUnused
();
signals:
void
levelsChanged
();
void
recordStateChanged
();
void
recordDone
();
};
#endif
src/core.cpp
View file @
ac43da1c
...
...
@@ -695,14 +695,13 @@ void Core::startMediaCapture(bool checkAudio, bool checkVideo)
m_mediaCaptureFile
=
m_capture
->
getCaptureOutputLocation
();
}
const
QString
Core
::
stopMediaCapture
(
bool
checkAudio
,
bool
checkVideo
)
void
Core
::
stopMediaCapture
(
bool
checkAudio
,
bool
checkVideo
)
{
if
(
checkAudio
&&
checkVideo
)
{
m_capture
->
recordVideo
(
false
);
}
else
if
(
checkAudio
)
{
m_capture
->
recordAudio
(
false
);
}
return
m_capture
->
getCaptureOutputLocation
().
toLocalFile
();
}
QStringList
Core
::
getAudioCaptureDevices
()
...
...
src/core.h
View file @
ac43da1c
...
...
@@ -183,7 +183,7 @@ public:
int
getTimelinePosition
()
const
;
/** @brief Handles audio and video capture **/
void
startMediaCapture
(
bool
,
bool
);
const
QString
stopMediaCapture
(
bool
,
bool
);
void
stopMediaCapture
(
bool
,
bool
);
QStringList
getAudioCaptureDevices
();
int
getMediaCaptureState
();
bool
isMediaCapturing
();
...
...
@@ -231,6 +231,7 @@ signals:
void
updateLibraryPath
();
/** @brief Call config dialog on a selected page / tab */
void
showConfigDialog
(
int
,
int
);
void
finalizeRecording
(
const
QString
&
captureFile
);
};
#endif
src/timeline2/view/qml/AudioLevels.qml
View file @
ac43da1c
...
...
@@ -8,7 +8,7 @@ Item {
property
int
recState
:
audiorec
.
recordState
width
:
parent
.
width
implicitHeight
:
root
.
baseUnit
*
1.5
onRecStateChanged
:
{
if
(
recState
==
1
)
{
// Recording
...
...
@@ -19,9 +19,7 @@ Item {
}
else
{
recbutton
.
color
=
'
darkred
'
}
}
RowLayout
{
spacing
:
2
Layout.fillWidth
:
true
...
...
src/timeline2/view/timelinecontroller.cpp
View file @
ac43da1c
...
...
@@ -77,6 +77,7 @@ TimelineController::TimelineController(QObject *parent)
connect
(
m_disablePreview
,
&
QAction
::
triggered
,
this
,
&
TimelineController
::
disablePreview
);
connect
(
this
,
&
TimelineController
::
selectionChanged
,
this
,
&
TimelineController
::
updateClipActions
);
m_disablePreview
->
setEnabled
(
false
);
connect
(
pCore
.
get
(),
&
Core
::
finalizeRecording
,
this
,
&
TimelineController
::
finishRecording
);
}
TimelineController
::~
TimelineController
()
...
...
@@ -2323,6 +2324,7 @@ void TimelineController::switchRecording(int trackId)
return
;
}
m_recordStart
.
first
=
timelinePosition
();
m_recordTrack
=
trackId
;
int
maximumSpace
=
m_model
->
getTrackById_const
(
trackId
)
->
getBlankEnd
(
m_recordStart
.
first
);
if
(
maximumSpace
==
INT_MAX
)
{
m_recordStart
.
second
=
0
;
...
...
@@ -2339,30 +2341,37 @@ void TimelineController::switchRecording(int trackId)
pCore
->
startMediaCapture
(
true
,
false
);
pCore
->
monitorManager
()
->
slotPlay
();
}
else
{
QString
recordedFile
=
pCore
->
stopMediaCapture
(
true
,
false
);
pCore
->
stopMediaCapture
(
true
,
false
);
pCore
->
monitorManager
()
->
slotPause
();
if
(
recordedFile
.
isEmpty
())
{
}
}
void
TimelineController
::
finishRecording
(
const
QString
&
recordedFile
)
{
if
(
recordedFile
.
isEmpty
())
{
return
;
}
Fun
undo
=
[]()
{
return
true
;
};
Fun
redo
=
[]()
{
return
true
;
};
std
::
function
<
void
(
const
QString
&
)
>
callBack
=
[
this
](
const
QString
&
binId
)
{
int
id
=
-
1
;
if
(
m_recordTrack
==
-
1
)
{
return
;
}
Fun
undo
=
[]()
{
return
true
;
};
Fun
redo
=
[]()
{
return
true
;
};
std
::
function
<
void
(
const
QString
&
)
>
callBack
=
[
this
,
trackId
](
const
QString
&
binId
)
{
int
id
=
-
1
;
qDebug
()
<<
"callback "
<<
binId
<<
" "
<<
trackId
<<
", MAXIMUM SPACE: "
<<
m_recordStart
.
second
;
bool
res
=
false
;
if
(
m_recordStart
.
second
>
0
)
{
// Limited space on track
QString
binClipId
=
QString
(
"%1/%2/%3"
).
arg
(
binId
).
arg
(
0
).
arg
(
m_recordStart
.
second
-
1
);
res
=
m_model
->
requestClipInsertion
(
binClipId
,
trackId
,
m_recordStart
.
first
,
id
,
true
,
true
,
false
);
}
else
{
res
=
m_model
->
requestClipInsertion
(
binId
,
trackId
,
m_recordStart
.
first
,
id
,
true
,
true
,
false
);
}
};
QString
binId
=
ClipCreator
::
createClipFromFile
(
recordedFile
,
pCore
->
projectItemModel
()
->
getRootFolder
()
->
clipId
(),
pCore
->
projectItemModel
(),
undo
,
redo
,
callBack
);
if
(
binId
!=
QStringLiteral
(
"-1"
))
{
pCore
->
pushUndo
(
undo
,
redo
,
i18n
(
"Record audio"
));
qDebug
()
<<
"callback "
<<
binId
<<
" "
<<
m_recordTrack
<<
", MAXIMUM SPACE: "
<<
m_recordStart
.
second
;
bool
res
=
false
;
if
(
m_recordStart
.
second
>
0
)
{
// Limited space on track
QString
binClipId
=
QString
(
"%1/%2/%3"
).
arg
(
binId
).
arg
(
0
).
arg
(
m_recordStart
.
second
-
1
);
res
=
m_model
->
requestClipInsertion
(
binClipId
,
m_recordTrack
,
m_recordStart
.
first
,
id
,
true
,
true
,
false
);
}
else
{
res
=
m_model
->
requestClipInsertion
(
binId
,
m_recordTrack
,
m_recordStart
.
first
,
id
,
true
,
true
,
false
);
}
};
QString
binId
=
ClipCreator
::
createClipFromFile
(
recordedFile
,
pCore
->
projectItemModel
()
->
getRootFolder
()
->
clipId
(),
pCore
->
projectItemModel
(),
undo
,
redo
,
callBack
);
if
(
binId
!=
QStringLiteral
(
"-1"
))
{
pCore
->
pushUndo
(
undo
,
redo
,
i18n
(
"Record audio"
));
}
}
src/timeline2/view/timelinecontroller.h
View file @
ac43da1c
...
...
@@ -116,6 +116,9 @@ public:
/* @brief Show/hide audio record controls on a track
*/
Q_INVOKABLE
void
switchRecording
(
int
trackId
);
/* @brief Add recorded file to timeline
*/
void
finishRecording
(
const
QString
&
recordedFile
);
/* @brief Open Kdenlive's config diablog on a defined page and tab
*/
Q_INVOKABLE
void
showConfig
(
int
page
,
int
tab
);
...
...
@@ -482,6 +485,7 @@ private:
int
m_activeTrack
;
int
m_audioRef
;
QPair
<
int
,
int
>
m_recordStart
;
int
m_recordTrack
;
QPoint
m_zone
;
double
m_scale
;
static
int
m_duration
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment