Skip to content

Commit 932ed75

Browse files
committed
Auto push on 2022-08-01 14:16:44
1 parent b56b105 commit 932ed75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+5762
-26
lines changed

.vscode/c_cpp_properties.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
"cppStandard": "c++17",
1515
"intelliSenseMode": "clang-x64",
1616
"configurationProvider": "ms-vscode.cmake-tools"
17+
},
18+
{
19+
"name": "Linux",
20+
"includePath": [
21+
"${workspaceFolder}/sdk/include"
22+
],
23+
"defines": [],
24+
"cStandard": "c11",
25+
"cppStandard": "c++17",
26+
"compilerPath": "/usr/bin/gcc",
27+
"intelliSenseMode": "linux-gcc-x64",
28+
"configurationProvider": "ms-vscode.cmake-tools"
1729
}
1830
],
1931
"version": 4

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
"functional": "cpp",
2424
"iomanip": "cpp",
2525
"iosfwd": "cpp",
26-
"sstream": "cpp"
26+
"sstream": "cpp",
27+
"map": "cpp",
28+
"vector": "cpp",
29+
"xstring": "cpp",
30+
"fstream": "cpp"
2731
},
2832
"editor.tokenColorCustomizations": {
2933
"textMateRules": [

samples/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,37 @@ if (OS STREQUAL "darwin")
1111
add_subdirectory(${OS}/dec_aac_adts_file)
1212
add_subdirectory(${OS}/dec_avc_au)
1313
add_subdirectory(${OS}/dec_avc_file)
14+
15+
add_subdirectory(${OS}/demux_mp4_file)
16+
1417
add_subdirectory(${OS}/enc_aac_adts_file)
1518
add_subdirectory(${OS}/enc_avc_file)
19+
20+
add_subdirectory(${OS}/mux_mp4_file)
1621
endif()
1722

1823
if(OS STREQUAL "linux")
1924
add_subdirectory(${OS}/dec_aac_adts_file)
2025
add_subdirectory(${OS}/dec_avc_au)
2126
add_subdirectory(${OS}/dec_avc_file)
27+
28+
add_subdirectory(${OS}/demux_mp4_file)
29+
2230
add_subdirectory(${OS}/enc_aac_adts_file)
2331
add_subdirectory(${OS}/enc_avc_file)
32+
33+
add_subdirectory(${OS}/mux_mp4_file)
2434
endif()
2535

2636
if(OS STREQUAL "windows")
2737
add_subdirectory(${OS}/dec_aac_adts_file)
2838
add_subdirectory(${OS}/dec_avc_au)
2939
add_subdirectory(${OS}/dec_avc_file)
40+
41+
add_subdirectory(${OS}/demux_mp4_file)
42+
3043
add_subdirectory(${OS}/enc_aac_adts_file)
3144
add_subdirectory(${OS}/enc_avc_file)
45+
46+
add_subdirectory(${OS}/mux_mp4_file)
3247
endif()

samples/darwin/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
# Samples
1+
# Samples - C++ / macOS
2+
3+
## Demuxing
4+
5+
### MP4 (MPEG-4 Part 14 / MPEG-4 Part 1)
6+
7+
#### demux_mp4_file
8+
9+
Extract the first audio and video elementary stream from an MP4 container and save each stream into a separate MP4 file.
10+
11+
See [demux_mp4_file](./demux_mp4_file) for details.
212

313
## Decoding
414

@@ -41,3 +51,13 @@ See [enc_aac_adts_file](./enc_aac_adts_file) for details.
4151
Convert a raw YUV video file to a compressed AVC / H.264 video file.
4252

4353
See [enc_avc_file](./enc_avc_file) for details.
54+
55+
## Muxing
56+
57+
### MP4 (MPEG-4 Part 1)
58+
59+
## mux_mp4_file
60+
61+
Multiplex two single-stream MP4 files containing AAC (audio) and H.264 (video) streams into an MP4 (container) file.
62+
63+
See [mux_mp4_file](./demux_mp4_file) for details.

samples/darwin/dec_aac_adts_file/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Decode AAC file in Audio Data Transport Stream (ADTS) format and save output to
1212

1313
List options:
1414

15-
```powershell
15+
```sh
1616
./bin/x64/dec_aac_adts_file --help
1717

1818
dec_aac_adts_file --input <aac file> --output <wav file>
@@ -23,7 +23,7 @@ dec_aac_adts_file --input <aac file> --output <wav file>
2323

2424
The following example encode input file `..\assets\aud\Hydrate-Kenny_Beltrey.adts.aac` into output file `Hydrate-Kenny_Beltrey.wav`:
2525

26-
```powershell
26+
```sh
2727
mkdir -p ./output/dec_aac_adts_file
2828

2929
./bin/x64/dec_aac_adts_file \
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(demux_mp4_file)
4+
set (target demux_mp4_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 STREQUAL "Xcode")
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+
# macOS
29+
if(OS STREQUAL "darwin")
30+
# common compile options
31+
target_compile_options(${target} PRIVATE -std=c++17 -stdlib=libc++)
32+
33+
# x64 compile options
34+
if (PLATFORM STREQUAL "x64")
35+
target_compile_options(${target} PRIVATE -m64 -fPIC)
36+
endif()
37+
38+
# x86 compile options
39+
if (PLATFORM STREQUAL "x86")
40+
target_compile_options(${target} PRIVATE -m32)
41+
endif()
42+
43+
# debug compile options
44+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
45+
target_compile_options(${target} PRIVATE -g)
46+
endif()
47+
48+
# release compile options
49+
if (CMAKE_BUILD_TYPE STREQUAL "Release")
50+
target_compile_options(${target} PRIVATE -Os)
51+
endif()
52+
endif()
53+
54+
# include dirs
55+
target_include_directories(${target}
56+
PUBLIC
57+
../../../sdk/include
58+
)
59+
60+
# sources
61+
file(GLOB source "./*.cpp" "./*.mm")
62+
63+
target_sources(${target}
64+
PRIVATE
65+
${source}
66+
)
67+
68+
# lib dirs
69+
target_link_directories(${target}
70+
PRIVATE
71+
# avblocks
72+
${PROJECT_SOURCE_DIR}/../../../sdk/lib/${PLATFORM}
73+
)
74+
75+
# libs
76+
if (OS STREQUAL "darwin")
77+
target_link_libraries(
78+
${target}
79+
80+
# primo-avblocks
81+
libAVBlocks.dylib
82+
83+
# os
84+
"-framework CoreFoundation"
85+
"-framework AppKit"
86+
)
87+
endif()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## demux_mp4_file
2+
3+
Extract the first audio and video elementary stream from an MP4 container and save each stream into a separate MP4 file.
4+
5+
### Command Line
6+
7+
```sh
8+
demux_mp4_file --input <input_mp4_file> --output <output_mp4_file_name_without_extension>
9+
```
10+
11+
### Examples
12+
13+
List options:
14+
15+
```sh
16+
./bin/x64/demux_mp4_file --help
17+
Usage: demux_mp4_file -i <input_mp4_file> -o <output_mp4_file_name_without_extension>
18+
-h, --help
19+
-i, --input Input mp4 file.
20+
-o, --output Output mp4 filename (without extension).
21+
```
22+
23+
Extract the audio and video elementary streams from the input file `./assets/mov/big_buck_bunny_trailer.mp4` into output files named `big_buck_bunny_trailer.vid.mp4` and `big_buck_bunny_trailer.aud.mp4`:
24+
25+
```sh
26+
mkdir -p ./output/demux_mp4_file
27+
28+
./bin/x64/demux_mp4_file \
29+
--input ./assets/mov/big_buck_bunny_trailer.mp4 \
30+
--output ./output/demux_mp4_file/big_buck_bunny_trailer
31+
```
32+
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#include <primo/avblocks/AVBlocks.h>
2+
3+
#include <primo/platform/Reference++.h>
4+
#include <primo/platform/ErrorFacility.h>
5+
#include <primo/platform/UString.h>
6+
7+
#include "util.h"
8+
#include "options.h"
9+
10+
#include <cstdio>
11+
#include <iostream>
12+
#include <iomanip>
13+
#include <fstream>
14+
#include <string>
15+
16+
#include <memory.h>
17+
18+
using namespace primo::codecs;
19+
using namespace primo::avblocks;
20+
using namespace std;
21+
22+
primo::ref<Transcoder> configureTranscoder(Options& opt)
23+
{
24+
primo::ref<MediaInfo> info(Library::createMediaInfo());
25+
info->inputs()->at(0)->setFile(primo::ustring(opt.inputFile));
26+
27+
if (!info->open())
28+
{
29+
printError("MediaInfo open", info->error());
30+
return primo::ref<Transcoder>();
31+
}
32+
33+
primo::ref<MediaSocket> inSocket(Library::createMediaSocket(info.get()));
34+
35+
info->close();
36+
37+
primo::ref<Transcoder> transcoder(Library::createTranscoder());
38+
transcoder->setAllowDemoMode(true);
39+
40+
transcoder->inputs()->add(inSocket.get());
41+
42+
bool audio = false;
43+
bool video = false;
44+
45+
for (int i = 0; i < inSocket->pins()->count(); ++i)
46+
{
47+
string fileName;
48+
if (inSocket->pins()->at(i)->streamInfo()->mediaType() == MediaType::Audio && !audio)
49+
{
50+
audio = true;
51+
fileName = opt.outputFile + ".aud.mp4";
52+
}
53+
else if (inSocket->pins()->at(i)->streamInfo()->mediaType() == MediaType::Video && !video)
54+
{
55+
video = true;
56+
fileName = opt.outputFile + ".vid.mp4";
57+
}
58+
else
59+
{
60+
inSocket->pins()->at(i)->setConnection(PinConnection::Disabled);
61+
continue;
62+
}
63+
64+
cout << "Output file: " << fileName << endl;
65+
deleteFile(primo::ustring(fileName));
66+
67+
primo::ref<MediaSocket> outSocket(Library::createMediaSocket());
68+
outSocket->pins()->add(inSocket->pins()->at(i));
69+
outSocket->setFile(primo::ustring(fileName));
70+
71+
transcoder->outputs()->add(outSocket.get());
72+
}
73+
74+
return transcoder;
75+
}
76+
77+
bool demuxMP4(Options& opt)
78+
{
79+
auto transcoder = configureTranscoder(opt);
80+
81+
if (!transcoder)
82+
return false;
83+
84+
if (!transcoder->open())
85+
{
86+
printError("Transcoder open", transcoder->error());
87+
return false;
88+
}
89+
90+
if (!transcoder->run())
91+
{
92+
printError("Transcoder run", transcoder->error());
93+
return false;
94+
}
95+
96+
transcoder->close();
97+
return true;
98+
}
99+
100+
int main(int argc, char* argv[])
101+
{
102+
Options opt;
103+
104+
switch(prepareOptions(opt, argc, argv))
105+
{
106+
case Command: return 0;
107+
case Error: return 1;
108+
case Parsed: break;
109+
}
110+
111+
Library::initialize();
112+
113+
bool demuxResult = demuxMP4(opt);
114+
115+
Library::shutdown();
116+
117+
return demuxResult ? 0 : 1;
118+
}

0 commit comments

Comments
 (0)