Skip to content

Commit d1b7d11

Browse files
committed
Auto push on 2021-09-03 21:18:49
1 parent 60f958a commit d1b7d11

File tree

21 files changed

+1198
-26
lines changed

21 files changed

+1198
-26
lines changed

.vscode/launch.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,39 @@
3636
"environment": [],
3737
"externalConsole": false,
3838
"preLaunchTask": "Build All - Debug x64 - Demo"
39+
},
40+
{
41+
"name": "enc_avc_file",
42+
"type": "cppdbg",
43+
"request": "launch",
44+
// see: https://code.visualstudio.com/docs/cpp/config-clang-mac
45+
"osx": {
46+
"program": "${workspaceFolder}/bin/x64/enc_avc_file",
47+
"MIMode": "lldb",
48+
},
49+
// see: https://code.visualstudio.com/docs/cpp/config-linux
50+
"linux": {
51+
"program": "${workspaceFolder}/bin/x64/enc_avc_file",
52+
"MIMode": "gdb",
53+
"setupCommands": [
54+
{
55+
"description": "Enable pretty-printing for gdb",
56+
"text": "-enable-pretty-printing",
57+
"ignoreFailures": true
58+
}
59+
],
60+
},
61+
// see: https://code.visualstudio.com/docs/cpp/config-msvc
62+
"windows": {
63+
"type": "cppvsdbg",
64+
"program": "${workspaceFolder}/bin/x64/enc_avc_file.exe",
65+
},
66+
"args": [],
67+
"stopAtEntry": false,
68+
"cwd": "${workspaceFolder}/bin/x64",
69+
"environment": [],
70+
"externalConsole": false,
71+
"preLaunchTask": "Build All - Debug x64 - Demo"
3972
}
4073
]
4174
}

samples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ string(TOLOWER ${CMAKE_SYSTEM_NAME} OS)
99
# add projects, each project should be in its own directory
1010
if (OS STREQUAL "darwin")
1111
add_subdirectory(${OS}/dec_avc_au)
12+
add_subdirectory(${OS}/enc_avc_file)
1213
endif()
1314

1415
if(OS STREQUAL "linux")

samples/darwin/dec_avc_au/dec_avc_au.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* Copyright (c) 2013 Primo Software. All Rights Reserved.
2+
* Copyright (c) Primo Software. All Rights Reserved.
33
*
4-
* Use of this source code is governed by a BSD-style license
4+
* Use of this source code is governed by a MIT License
55
* that can be found in the LICENSE file in the root of the source
66
* tree.
77
*/

samples/darwin/dec_avc_au/options.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
2-
* Copyright (c) 2013 Primo Software. All Rights Reserved.
2+
* Copyright (c) Primo Software. All Rights Reserved.
33
*
4-
* Use of this source code is governed by a BSD-style license
4+
* Use of this source code is governed by a MIT License
55
* that can be found in the LICENSE file in the root of the source
66
* tree.
77
*/
88

99
#include <primo/avblocks/AVBlocks.h>
10+
1011
#include <string>
1112
#include <iostream>
1213
#include <iomanip>
@@ -17,8 +18,6 @@
1718
#include "program_options.h"
1819
#include "util.h"
1920

20-
namespace fs = std::filesystem;
21-
2221
using namespace std;
2322
using namespace primo::avblocks;
2423
using namespace primo::codecs;

samples/darwin/dec_avc_au/options.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* Copyright (c) 2013 Primo Software. All Rights Reserved.
2+
* Copyright (c) Primo Software. All Rights Reserved.
33
*
4-
* Use of this source code is governed by a BSD-style license
4+
* Use of this source code is governed by a MIT License
55
* that can be found in the LICENSE file in the root of the source
66
* tree.
77
*/

samples/darwin/dec_avc_au/util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* Copyright (c) 2013 Primo Software. All Rights Reserved.
2+
* Copyright (c) Primo Software. All Rights Reserved.
33
*
4-
* Use of this source code is governed by a BSD-style license
4+
* Use of this source code is governed by a MIT License
55
* that can be found in the LICENSE file in the root of the source
66
* tree.
77
*/
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(enc_avc_file)
4+
set (target enc_avc_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")
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 ApplicationServices"
86+
)
87+
endif()

samples/darwin/enc_avc_file/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## enc_avc_file
2+
3+
The enc_avc_file sample shows how to convert a raw YUV video file to a compressed H.264 video file.
4+
5+
### Command Line
6+
7+
enc_avc_file --frame <width>x<height> --rate <fps> --color <COLOR> --input <file.yuv> --output <file.h264>
8+
[--colors]
9+
[--help]
10+
11+
### Examples
12+
13+
The following command encodes a raw YUV video from `foreman_qcif.yuv` to a H.264 video in `foreman_qcif.h264`:
14+
15+
./enc_avc_file --frame 176x144 --rate 30 --color yuv420 --input ../assets/vid/foreman_qcif.yuv --output foreman_qcif.h264
16+
17+
and using default option:
18+
19+
./enc_avc_file
20+
21+
***
22+
23+
mac:~/AVBlocksSDK.macosx/lib$ ./enc_avc_file
24+
25+
Using defaults:
26+
enc_avc_file --input ../assets/vid/foreman_qcif.yuv --output foreman_qcif.h264 --rate 30 --frame 176x144 --color yuv420
27+
Transcoder open: Success
28+
Transcoder run: Success
29+
Transcoder close: Success
30+
31+
mac:~/AVBlocksSDK.macosx/lib$
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* Copyright (c) Primo Software. All Rights Reserved.
3+
*
4+
* Use of this source code is governed by a MIT License
5+
* that can be found in the LICENSE file in the root of the source
6+
* tree.
7+
*/
8+
9+
#include <iostream>
10+
#include <string>
11+
#include <filesystem>
12+
#include <unistd.h>
13+
14+
#include <primo/avblocks/AVBlocks.h>
15+
16+
#include <primo/platform/Reference++.h>
17+
#include <primo/platform/ErrorFacility.h>
18+
#include <primo/platform/UString.h>
19+
20+
#include "options.h"
21+
#include "util.h"
22+
23+
using namespace std;
24+
using namespace primo::avblocks;
25+
using namespace primo::codecs;
26+
27+
namespace fs = std::filesystem;
28+
namespace av = primo::avblocks;
29+
namespace pc = primo::codecs;
30+
31+
void printStatus(const primo::error::ErrorInfo* e)
32+
{
33+
if (primo::error::ErrorFacility::Success == e->facility())
34+
{
35+
cout << "Success";
36+
37+
}
38+
else
39+
{
40+
if (e->message())
41+
{
42+
cout << primo::ustring(e->message()) << " ";
43+
}
44+
45+
cout << "(facility:" << e->facility() << " error:" << e->code() << ")" << endl;
46+
}
47+
48+
cout << endl;
49+
}
50+
51+
primo::ref<MediaSocket> createInputSocket(Options& opt)
52+
{
53+
auto socket = primo::make_ref(Library::createMediaSocket());
54+
socket->setStreamType(StreamType::UncompressedVideo);
55+
socket->setFile(primo::ustring(opt.yuv_file));
56+
57+
auto pin = primo::make_ref(Library::createMediaPin());
58+
socket->pins()->add(pin.get());
59+
60+
auto vsi = primo::make_ref(Library::createVideoStreamInfo());
61+
pin->setStreamInfo(vsi.get());
62+
63+
vsi->setStreamType(StreamType::UncompressedVideo);
64+
vsi->setFrameWidth(opt.frame_size.width_);
65+
vsi->setFrameHeight(opt.frame_size.height_);
66+
vsi->setColorFormat(opt.yuv_color.Id);
67+
vsi->setFrameRate(opt.fps);
68+
vsi->setScanType(ScanType::Progressive);
69+
70+
return socket;
71+
}
72+
73+
primo::ref<MediaSocket> createOutputSocket(Options& opt)
74+
{
75+
auto socket = primo::make_ref(Library::createMediaSocket());
76+
socket->setFile(primo::ustring(opt.h264_file));
77+
socket->setStreamType(StreamType::H264);
78+
socket->setStreamSubType(StreamSubType::AVC_Annex_B);
79+
80+
auto pin = primo::make_ref(Library::createMediaPin());
81+
socket->pins()->add(pin.get());
82+
83+
auto vsi = primo::make_ref(Library::createVideoStreamInfo());
84+
pin->setStreamInfo(vsi.get());
85+
86+
vsi->setStreamType(StreamType::H264);
87+
vsi->setStreamSubType(StreamSubType::AVC_Annex_B);
88+
89+
return socket;
90+
}
91+
92+
bool encode(Options& opt)
93+
{
94+
// create input socket
95+
auto inSocket = createInputSocket(opt);
96+
97+
// create output socket
98+
auto outSocket = createOutputSocket(opt);
99+
100+
// create transcoder
101+
auto transcoder = primo::make_ref(Library::createTranscoder());
102+
transcoder->setAllowDemoMode(true);
103+
transcoder->inputs()->add(inSocket.get());
104+
transcoder->outputs()->add(outSocket.get());
105+
106+
// transcoder will fail if output exists (by design)
107+
deleteFile(primo::ustring(opt.h264_file));
108+
109+
cout << "Transcoder open: ";
110+
if(transcoder->open())
111+
{
112+
printStatus(transcoder->error());
113+
if(!transcoder->run())
114+
return false;
115+
116+
cout << "Transcoder run: ";
117+
printStatus(transcoder->error());
118+
119+
transcoder->close();
120+
cout << "Transcoder close: ";
121+
printStatus(transcoder->error());
122+
}
123+
else
124+
{
125+
printStatus(transcoder->error());
126+
return false;
127+
}
128+
129+
return true;
130+
}
131+
132+
int main(int argc, char* argv[])
133+
{
134+
Options opt;
135+
136+
switch(prepareOptions(opt, argc, argv))
137+
{
138+
case Command: return 0;
139+
case Error: return 1;
140+
}
141+
142+
Library::initialize();
143+
144+
bool encodeResult = encode(opt);
145+
146+
Library::shutdown();
147+
148+
return encodeResult ? 0 : 1;
149+
}

0 commit comments

Comments
 (0)