Skip to content

Commit 85bb6f3

Browse files
committed
Auto push on 2024-05-05 17:05
1 parent 5129c7f commit 85bb6f3

File tree

13 files changed

+975
-23
lines changed

13 files changed

+975
-23
lines changed

samples/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ if (OS STREQUAL "darwin")
1515
add_subdirectory(${OS}/demux_mp4_file)
1616

1717
add_subdirectory(${OS}/enc_aac_adts_file)
18-
add_subdirectory(${OS}/enc_mp3_file)
19-
2018
add_subdirectory(${OS}/enc_avc_file)
19+
add_subdirectory(${OS}/enc_mp3_file)
2120
add_subdirectory(${OS}/enc_preset_file)
2221

2322
add_subdirectory(${OS}/info_metadata_file)
@@ -37,9 +36,8 @@ if(OS STREQUAL "linux")
3736
add_subdirectory(${OS}/demux_mp4_file)
3837

3938
add_subdirectory(${OS}/enc_aac_adts_file)
40-
add_subdirectory(${OS}/enc_mp3_file)
41-
4239
add_subdirectory(${OS}/enc_avc_file)
40+
add_subdirectory(${OS}/enc_mp3_file)
4341
add_subdirectory(${OS}/enc_preset_file)
4442

4543
add_subdirectory(${OS}/info_metadata_file)
@@ -60,6 +58,7 @@ if(OS STREQUAL "windows")
6058

6159
add_subdirectory(${OS}/enc_aac_adts_file)
6260
add_subdirectory(${OS}/enc_avc_file)
61+
add_subdirectory(${OS}/enc_mp3_file)
6362
add_subdirectory(${OS}/enc_preset_file)
6463

6564
add_subdirectory(${OS}/info_metadata_file)

samples/darwin/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,6 @@ Encode WAV file to AAC file in Audio Data Transport Stream (ADTS) format.
8686

8787
See [enc_aac_adts_file](./enc_aac_adts_file) for details.
8888

89-
### MP3
90-
91-
> MPEG-1 Layer 3 Audio
92-
93-
#### enc_mp3_file
94-
95-
Encode WAV file to MP3 file.
96-
97-
See [enc_mp3_file](./enc_mp3_file) for details.
98-
9989
### AVC / H.264
10090

10191
> Advanced Video Coding
@@ -106,6 +96,16 @@ Convert a raw YUV video file to a compressed AVC / H.264 video file.
10696

10797
See [enc_avc_file](./enc_avc_file) for details.
10898

99+
### MP3
100+
101+
> MPEG-1 Layer 3 Audio
102+
103+
#### enc_mp3_file
104+
105+
Encode WAV file to MP3 file.
106+
107+
See [enc_mp3_file](./enc_mp3_file) for details.
108+
109109
### Other
110110

111111
#### enc_preset_file

samples/linux/README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ Encode WAV file to AAC file in Audio Data Transport Stream (ADTS) format.
8686

8787
See [enc_aac_adts_file](./enc_aac_adts_file) for details.
8888

89+
### AVC / H.264
90+
91+
> Advanced Video Coding
92+
93+
#### enc_avc_file
94+
95+
Encode a raw YUV video file into a compressed AVC / H.264 video file.
96+
97+
See [enc_avc_file](./enc_avc_file) for details.
98+
8999
### MP3
90100

91101
> MPEG-1 Layer 3 Audio
@@ -96,15 +106,6 @@ Encode WAV file to MP3 file.
96106

97107
See [enc_mp3_file](./enc_mp3_file) for details.
98108

99-
### AVC / H.264
100-
101-
> Advanced Video Coding
102-
103-
#### enc_avc_file
104-
105-
Encode a raw YUV video file into a compressed AVC / H.264 video file.
106-
107-
See [enc_avc_file](./enc_avc_file) for details.
108109

109110
### Other
110111

samples/windows/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ Convert a raw YUV video file to a compressed H.264 video file.
9696

9797
See [enc_avc_file](./enc_avc_file) for details.
9898

99+
### MP3
100+
101+
> MPEG-1 Layer 3 Audio
102+
103+
#### enc_mp3_file
104+
105+
Encode WAV file to MP3 file.
106+
107+
See [enc_mp3_file](./enc_mp3_file) for details.
108+
109+
99110
### Other
100111

101112
#### enc_preset_file
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(enc_mp3_file)
4+
set (target enc_mp3_file)
5+
6+
add_executable(${target})
7+
8+
# Operating System
9+
string(TOLOWER ${CMAKE_SYSTEM_NAME} OS)
10+
11+
# output
12+
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../../../bin/${PLATFORM})
13+
14+
if (CMAKE_GENERATOR MATCHES "Visual Studio.*20.*")
15+
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../../../bin)
16+
endif()
17+
18+
# debug definitions
19+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
20+
target_compile_definitions(${target} PUBLIC _DEBUG)
21+
endif()
22+
23+
# release definitions
24+
if (CMAKE_BUILD_TYPE STREQUAL "Release")
25+
target_compile_definitions(${target} PUBLIC NDEBUG)
26+
endif()
27+
28+
# Windows
29+
if(OS STREQUAL "windows")
30+
# add /MTd or /MT compiler option
31+
set_property(TARGET ${target} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
32+
33+
# enable C++ 17 standard features
34+
target_compile_features(${target} PRIVATE cxx_std_17)
35+
36+
# assume extern "C" functions do not throw.
37+
# see: https://docs.microsoft.com/en-us/cpp/build/reference/eh-exception-handling-model?view=vs-2019
38+
target_compile_options(${target} PRIVATE /EHsc)
39+
40+
# common definitions
41+
target_compile_definitions(${target} PRIVATE UNICODE _UNICODE)
42+
43+
# x64 compile options
44+
if (PLATFORM STREQUAL "x64")
45+
target_compile_definitions(${target} PRIVATE WIN64)
46+
endif()
47+
48+
# x86 compile options
49+
if (PLATFORM STREQUAL "x86")
50+
target_compile_definitions(${target} PRIVATE WIN32)
51+
endif()
52+
53+
# debug compile options
54+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
55+
target_compile_options(${target} PRIVATE /Zi /Od)
56+
endif()
57+
58+
# release compile options
59+
if (CMAKE_BUILD_TYPE STREQUAL "Release")
60+
target_compile_options(${target} PRIVATE /O2)
61+
endif()
62+
endif()
63+
64+
# include dirs
65+
target_include_directories(${target}
66+
PUBLIC
67+
../../../sdk/include
68+
)
69+
70+
# sources
71+
file(GLOB source "./*.cpp")
72+
73+
target_sources(${target}
74+
PRIVATE
75+
${source}
76+
)
77+
78+
# lib dirs
79+
target_link_directories(${target}
80+
PRIVATE
81+
# avblocks
82+
${PROJECT_SOURCE_DIR}/../../../sdk/lib/${PLATFORM}
83+
)
84+
85+
# libs
86+
if(OS STREQUAL "windows")
87+
target_link_libraries(
88+
${target}
89+
90+
# primo-avblocks
91+
AVBlocks64.dll
92+
93+
# os
94+
Shlwapi
95+
)
96+
endif()
97+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## enc_mp3_file
2+
3+
How to encode WAV file to MP3 file.
4+
5+
### Command Line
6+
7+
```powershell
8+
enc_mp3_file --input <wav file> --output <mp3 file>
9+
```
10+
11+
### Examples
12+
13+
List options:
14+
15+
```powershell
16+
./bin/x64/enc_mp3_file --help
17+
Usage: enc_mp3_file --input <wav file> --output <mp3 file>
18+
-h, --help
19+
-i, --input input WAV file
20+
-o, --output output MP3 file
21+
```
22+
23+
Encode the input file `./assets/aud/equinox-48KHz.wav` into output file `./output/enc_mp3_file/equinox-48KHz.mp3`:
24+
25+
```powershell
26+
mkdir -Force -Path ./output/enc_mp3_file
27+
28+
./bin/x64/enc_mp3_file `
29+
--input ./assets/aud/equinox-48KHz.wav `
30+
--output ./output/enc_mp3_file/equinox-48KHz.mp3
31+
```
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2016 Primo Software. All Rights Reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license
5+
* that can be found in the LICENSE file in the root of the source
6+
* tree.
7+
*/
8+
9+
#include "stdafx.h"
10+
#include "util.h"
11+
#include "options.h"
12+
13+
using namespace primo::codecs;
14+
using namespace primo::avblocks;
15+
using namespace std;
16+
17+
primo::ref<MediaSocket> createOutputSocket(Options& opt)
18+
{
19+
auto socket = primo::make_ref(Library::createMediaSocket());
20+
socket->setFile(opt.outputFile.c_str());
21+
socket->setStreamType(StreamType::MPEG_Audio);
22+
socket->setStreamSubType(StreamSubType::MPEG_Audio_Layer3);
23+
24+
auto pin = primo::make_ref(Library::createMediaPin());
25+
socket->pins()->add(pin.get());
26+
27+
auto asi = primo::make_ref(Library::createAudioStreamInfo());
28+
pin->setStreamInfo(asi.get());
29+
30+
asi->setStreamType(StreamType::MPEG_Audio);
31+
asi->setStreamSubType(StreamSubType::MPEG_Audio_Layer3);
32+
33+
// Change the encoding bitrate with the following line. The default bitrate is 128000. You can set it to 192000, 256000, etc.
34+
// asi->setBitrate(192000);
35+
36+
// Change the sampling rate and the number of the channels, e.g. Mono, 44.1 Khz
37+
// asi->setChannels(1);
38+
// asi->setSampleRate(44100);
39+
40+
// Change the stereo mode, e.g. Joint Stereo
41+
// pin->params()->addInt(Param::Encoder::Audio::MPEG1::StereoMode, StereoMode::Joint);
42+
43+
return socket;
44+
}
45+
46+
bool encode(Options& opt)
47+
{
48+
primo::ref<MediaSocket> inSocket(Library::createMediaSocket());
49+
inSocket->setFile(opt.inputFile.c_str());
50+
51+
// create output socket
52+
auto outSocket = createOutputSocket(opt);
53+
54+
// create transcoder
55+
auto transcoder = primo::make_ref(Library::createTranscoder());
56+
transcoder->setAllowDemoMode(TRUE);
57+
transcoder->inputs()->add(inSocket.get());
58+
transcoder->outputs()->add(outSocket.get());
59+
60+
// transcoder will fail if output exists (by design)
61+
deleteFile(opt.outputFile.c_str());
62+
63+
if (!transcoder->open())
64+
{
65+
printError(L"Transcoder open", transcoder->error());
66+
return false;
67+
}
68+
69+
if (!transcoder->run())
70+
{
71+
printError(L"Transcoder run", transcoder->error());
72+
return false;
73+
}
74+
75+
transcoder->close();
76+
77+
return true;
78+
}
79+
80+
int wmain(int argc, wchar_t* argv[])
81+
{
82+
Options opt;
83+
84+
switch(prepareOptions( opt, argc, argv))
85+
{
86+
case Command: return 0;
87+
case Error: return 1;
88+
}
89+
90+
Library::initialize();
91+
92+
bool result = encode(opt);
93+
94+
Library::shutdown();
95+
96+
return result ? 0 : 1;
97+
}

0 commit comments

Comments
 (0)