Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
audiowmark
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
audiowmark
Commits
3fdf6d21
Commit
3fdf6d21
authored
Jul 09, 2020
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HLS: Add bit-rate detection in hls-prepare to preserve original quality.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
060947ec
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
3 deletions
+42
-3
hls.cc
src/hls.cc
+42
-3
No files found.
src/hls.cc
View file @
3fdf6d21
...
...
@@ -18,6 +18,10 @@
#include <string>
#include <regex>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "utils.hh"
#include "mpegts.hh"
#include "sfinputstream.hh"
...
...
@@ -161,9 +165,31 @@ hls_add (const string& infile, const string& outfile, const string& bits)
return
0
;
}
Error
bit_rate_from_m3u8
(
const
string
&
m3u8
,
const
WavData
&
wav_data
,
int
&
bit_rate
)
{
FILE
*
tmp_file
=
tmpfile
();
ScopedFile
tmp_file_s
(
tmp_file
);
string
tmp_file_name
=
string_printf
(
"/dev/fd/%d"
,
fileno
(
tmp_file
));
Error
err
=
xsystem
(
string_printf
(
"ffmpeg -y -i %s -c:a copy -f adts %s"
,
m3u8
.
c_str
(),
tmp_file_name
.
c_str
()));
if
(
err
)
return
err
;
struct
stat
stat_buf
;
if
(
stat
(
tmp_file_name
.
c_str
(),
&
stat_buf
)
!=
0
)
{
return
Error
(
string_printf
(
"failed to stat temporary aac file: %s"
,
strerror
(
errno
)));
}
double
seconds
=
double
(
wav_data
.
n_frames
())
/
wav_data
.
sample_rate
();
bit_rate
=
stat_buf
.
st_size
/
seconds
*
8
;
return
Error
::
Code
::
NONE
;
}
int
hls_prepare
(
const
string
&
in_dir
,
const
string
&
out_dir
,
const
string
&
filename
,
const
string
&
audio_master
)
{
string
in_name
=
in_dir
+
"/"
+
filename
;
FILE
*
in_file
=
fopen
(
in_name
.
c_str
(),
"r"
);
ScopedFile
in_file_s
(
in_file
);
...
...
@@ -191,9 +217,22 @@ hls_prepare (const string& in_dir, const string& out_dir, const string& filename
error
(
"audiowmark: failed to load audio master: %s
\n
"
,
audio_master
.
c_str
());
return
1
;
}
const
int
bit_rate
=
Params
::
hls_bit_rate
;
info
(
"AAC Bitrate: %d
\n
"
,
bit_rate
);
int
bit_rate
=
0
;
if
(
!
Params
::
hls_bit_rate
)
{
err
=
bit_rate_from_m3u8
(
in_dir
+
"/"
+
filename
,
audio_master_data
,
bit_rate
);
if
(
err
)
{
error
(
"audiowmark: bit-rate detection failed: %s
\n
"
,
err
.
message
());
return
1
;
}
info
(
"AAC Bitrate: %d (detected)
\n
"
,
bit_rate
);
}
else
{
bit_rate
=
Params
::
hls_bit_rate
;
info
(
"AAC Bitrate: %d
\n
"
,
bit_rate
);
}
struct
Segment
{
...
...
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