Giter Club home page Giter Club logo

skullanbones / mpeg2ts Goto Github PK

View Code? Open in Web Editor NEW
68.0 4.0 6.0 28.41 MB

A fast, cross-platform and modern C++ SDK for all your MPEG-2 transport stream media format needs following international specification ISO/IEC 13818-1.

License: Other

CMake 12.71% Makefile 0.63% C++ 73.16% Python 5.40% Shell 1.26% Batchfile 0.28% JavaScript 2.93% HTML 0.47% CSS 0.15% Dockerfile 2.77% C 0.25%
mpeg mpeg2 h264 mpegts mpeg-transport-streams streaming dvb-ip dvb hls ip-tv

mpeg2ts's Introduction

MPEG-2 Transport Stream utility library

CircleCI

A fast, cross-platform and modern C++ SDK for all your MPEG-2 transport stream media format needs following international specification ISO/IEC 13818-1. The standard is also called H.222 including both TS and PS. The library is platform independent only using C++11. Mpeg2ts has been tested on the following operating systems:

  • Linux (Ubuntu 18.04 LTS and 16.04 LTS)
  • Windows (Windows 10)
  • Mac OS X (Sierra, Catalina, BigSur)

and following architectures:

  • x86
  • amd64
  • Apple M1

To simplify the build process on all these operating systems, CMake is being used.

Cross platform Artifacts:

Win32: mpeg2ts.dll mpeg2ts.lib
Linux: libmpeg2ts.so libmpeg2ts.a
Apple: libmpeg2ts.dylib libmpeg2ts.a
All OS: mpeg2ts.h

Sample Applications:

Win32: TsUtilities located under samples
(Note: You need copy it's dependency mpeg2ts.dll to where you
installed/built the sample_tsutilities.exe)
Linux: tsparser

In order to parse mpeg2 and h264 codecs, 2 extra libs are supplied. In total there are the 3 following libs:

Lib name Meaning
libmpeg2ts.so mpeg2 transport stream parser
libmpeg2codec.so mpeg2 codec parser
libh264codec.so h264 codec parser

Requirements

C++11 is the minimal requirement. The library is written as platform independent code and tested on Mac OS X (Sierra), Ubuntu 16.04/18.04, Windows 10.

SW Architecture

There are 2 sets of APIs, the core API called mpeg2ts under the same namespace and a utility API to facilitate the usage of the API for more convinient usage (namespace tsutil). These are the APIs:

  • mpeg2ts.h The core and fundamental API for all mpeg2ts usage
  • TsUtilities.h High level API to simplify usage
  • Samples in samples/ shows how to use the tsutil API

Building

To simplify the crosscompile process we use CMake. Under Linux, Mac and Windows just do this:

mkdir build
cd build/
cmake -DCMAKE_BUILD_TYPE=Debug|Release ..
cmake --build .

You will get the following artifacts:

libmpeg2ts.a
tsparser*

To also build the shared libraries you need to tell CMake to build those:

cmake -DCMAKE_BUILD_TYPE=Debug|Release -DBUILD_SHARED_LIBS=YES ..

which result in libmpeg2ts.so* on Linux, libmpeg2ts.dylib* on Mac and libmpeg2ts.dll* on Windows.

If you wanna speed up the build you can type cmake --build . -- -j$(nproc) in the 4th command above (Works only on Mac/Linux).

Installation

In order to install this library you can type:

cmake -DCMAKE_INSTALL_PREFIX=../install ..
cmake --build .
cmake --build . --target install

and now you will find the installed libraries and headers in install directory. Omit CMAKE_INSTALL_PREFIX to install in system default /usr/local/lib.

Packaging

To generate a package with both debug and release build type (Mac & Linux):

./gen_package.sh

or on Windows

./gen_package.bat

This will generate a package

mpeg2ts-0.5.0-Linux.tar.gz   (Linux)
mpeg2ts-0.5.0-Darwin.tar.gz  (Apple)
mpeg2ts-0.5.0-win32.zip      (Windows)

for example containing only shared libs.

Usage in other CMake projects

To find this package using CMake simply use find_package:

find_package(mpeg2ts REQUIRED)

target_link_libraries(${PROJECT_NAME} PUBLIC mpeg2ts::mpeg2ts)

If you want to use mpeg2ts lib installation with your project you need to set the CMAKE_PREFIX_PATH to where mpeg2ts-lib is being installed if it wasn't installed host under your system (/usr/local).

Settings

Edit the settings.json file to change log level, log file name and other properties. These are global settings for the mpeg2ts set of libraries. Log levels are:

VERBOSE
DEBUG
INFO
WARNING
ERROR
FATAL
NONE

where VERBOSE is the maximum log output as compared to NONE which generates no output. The default log output file is mpeg2ts_log.csv in csv style for easier use.

Apps

For more info on how to use the apps like tsparser or h264parser please check README.

Docker

To simplify building mpeg2ts, building dependencies and tools have been bundled into a docker container. This image can be build locally or downloaded from docker hub. To start using docker commands, simplest is to source the tool

source docker/docker-commands.sh

Check README for more information.

Tests

In order to run all tests just type (currently only available under Linux):

cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -DENABLE_COMPONENT_TESTS=ON ..

Building:

make -j $(nproc)
make component-tests
make component-benchmark-tests
make unit-tests

This will run component tests, benchmark and unit-tests. Component tests are developed via pytest while the unit tests are via google tests/mocks (gtest). The different layers like API, and tsutilities are tested as a component (the whole library as such) while class functions are tested as a unit. virtualenv is required for running component tests.

Windows

Since CMake is used for cross platform build, you first need install CMake on your Windows system if you havent done that already.

Visual Studio 2017

To open the CMake project under Windows you need at least Visual Studio 2017 with CMake support (make sure you installed CMake support). Open the root CMakeLists.txt project file and you are ready to build under Windows.

VS Code

To open the CMake project by VS Code under Windows, just open the root folder. Select the supplied Kit (CMake & CMake Tools plugins are required) to simplify builds with predefined options. Existing kits are:

Kit name Meaning
Windows-SharedLib-VS2017-x64 64 bits build DLL on Windows, no tests
Windows-SharedLib-VS2017-x86 32 bits build DLL on Windows, no tests
Windows-Gtests-StaticLib-VS2017-x86 32 bits build gtests/benchmarch on Windows
Windows-Gtests-StaticLib-VS2017-x64 64 bits build gtests/benchmarch on Windows

Currently there is a bug in gmock which only make it possible to link statically and not dynamically with gmock hence the reason for the Windows-Gtests-StaticLib-VS2017-x86.

Visual Studio prior 2017

To cross compile for older VS versions, use powershell and cmake command line with a generator, for example:

cmake -G "Visual Studio 14 2015" --arch "x86" -DENABLE_TESTS=OFF -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF ..

Possible VS generators are:

Generators Meaning
Visual Studio 15 2017 [arch] Generates Visual Studio 2017 project files.
Visual Studio 14 2015 [arch] Generates Visual Studio 2015 project files.
Visual Studio 12 2013 [arch] Generates Visual Studio 2013 project files.
Visual Studio 11 2012 [arch] Generates Visual Studio 2012 project files.
Visual Studio 10 2010 [arch] Generates Visual Studio 2010 project files.
Visual Studio 9 2008 [arch] Generates Visual Studio 2008 project files.

where arch can be x86, Win64 or ARM. To build your new solution type:

cmake --build .
or
cmake --build . --target mpeg2ts

Generate Release

Run the

./gen_package.bat

to create a new release on Windows via CMake and CPack.

Continuous integration (CI)

For CI mpeg2ts use CircleCI which will automatically run all unit tests after a commit either in a branch, pull-request or integration to master. You can check the status tests in any branch by the portal: CircleCI

Static code analysis

Use make cppcheck and make clang-tidy. This however requires one to have installed either cppcheck or clang-tidy on you host machine. If that is not the case, then we recommend using docker interactive via:

source docker/docker-commands.sh
docker-interactive
docker@1ca...: make cppcheck

mpeg2ts's People

Contributors

heliconwave avatar kohnech avatar lnwhome avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mpeg2ts's Issues

Failing to build under ubuntu 22.04

In file included from /home/runner/work/mpeg2ts/mpeg2ts/libs/mpeg2ts/src/JsonSettings.h:39, [132](https://github.com/skullanbones/mpeg2ts/actions/runs/6435208150/job/17475979377#step:5:133) from /home/runner/work/mpeg2ts/mpeg2ts/libs/mpeg2ts/src/JsonSettings.cc:27: [133](https://github.com/skullanbones/mpeg2ts/actions/runs/6435208150/job/17475979377#step:5:134) /home/runner/work/mpeg2ts/mpeg2ts/3rd-party/json-3.9.1/include/nlohmann/json.hpp: In member function ‘bool nlohmann::detail::binary_reader<BasicJsonType, InputAdapterType, SAX>::parse_cbor_internal(bool, nlohmann::detail::cbor_tag_handler_t)’: [134](https://github.com/skullanbones/mpeg2ts/actions/runs/6435208150/job/17475979377#step:5:135) /home/runner/work/mpeg2ts/mpeg2ts/3rd-party/json-3.9.1/include/nlohmann/json.hpp:8272:80: error: useless cast to type ‘std::size_t’ {aka ‘long unsigned int’} [-Werror=useless-cast] [135](https://github.com/skullanbones/mpeg2ts/actions/runs/6435208150/job/17475979377#step:5:136) 8272 | return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler); [136](https://github.com/skullanbones/mpeg2ts/actions/runs/6435208150/job/17475979377#step:5:137) |

Robustness issue

CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.27/Modules/ExternalProject.cmake:3136 (message): [74](https://github.com/skullanbones/mpeg2ts/actions/runs/6447393748/job/17503601193?pr=63#step:4:75) The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is [75](https://github.com/skullanbones/mpeg2ts/actions/runs/6447393748/job/17503601193?pr=63#step:4:76) not set. The policy's OLD behavior will be used. When using a URL [76](https://github.com/skullanbones/mpeg2ts/actions/runs/6447393748/job/17503601193?pr=63#step:4:77) download, the timestamps of extracted files should preferably be that of [77](https://github.com/skullanbones/mpeg2ts/actions/runs/6447393748/job/17503601193?pr=63#step:4:78) the time of extraction, otherwise code that depends on the extracted [78](https://github.com/skullanbones/mpeg2ts/actions/runs/6447393748/job/17503601193?pr=63#step:4:79) contents might not be rebuilt if the URL changes. The OLD behavior [79](https://github.com/skullanbones/mpeg2ts/actions/runs/6447393748/job/17503601193?pr=63#step:4:80) preserves the timestamps from the archive instead, but this is usually not [80](https://github.com/skullanbones/mpeg2ts/actions/runs/6447393748/job/17503601193?pr=63#step:4:81) what you want. Update your project to the NEW behavior or specify the [81](https://github.com/skullanbones/mpeg2ts/actions/runs/6447393748/job/17503601193?pr=63#step:4:82) DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this [82](https://github.com/skullanbones/mpeg2ts/actions/runs/6447393748/job/17503601193?pr=63#step:4:83) robustness issue.

Fix macos build googletest requires C++ 11

There is an "ugly hack" in 3rd-party/CMakeLists.txt for APPLE to build googletest with :

if (APPLE)
    set(CMAKE_CXX_STANDARD 11)
endif(APPLE)

This should be done in a better way

Need clean 3rd-party build

When changing configuration I need also manually clean 3rd-party builds. It would simplify if they also configure and build under build directory.

TsDemuxer seems to deterministically fail to demux final PES packet

TsDemuxer::demux calls TsParser::collectPes on every PES packet, which seems to only release the data for the packet (returning true) upon seeing the beginning of the next PES packet (with isPayloadStart)... but that means the last packet of every file I parse never gets dispatched :(. FWIW, I'd maybe expect this TODO to be relevant?

// TODO: check if we have boud PES and return it if it is coplete

msi license

Update license text Windows msi installer. Currently cmake license.

Linking failure on recent shared library build

Creating library C:/MySpace/Projects/mpeg2ts/build_dll/libs/mpeg2ts/Debug/mpeg2ts-d.lib and object C:/MySpace/Proj

ects/mpeg2ts/build_dll/libs/mpeg2ts/Debug/mpeg2ts-d.exp
mpeg2ts.vcxproj -> C:\MySpace\Projects\mpeg2ts\build_dll\libs\mpeg2ts\Debug\mpeg2ts-d.dll
Building Custom Rule C:/MySpace/Projects/mpeg2ts/samples/TsUtilities/CMakeLists.txt
main.cpp
LINK : fatal error LNK1104: cannot open file '....\libs\mpeg2codec\Debug\mpeg2codec-d.lib' [C:\MySpace\Projects\mpeg2t
s\build_dll\samples\TsUtilities\sample_tsutilities.vcxproj]

Manually copy the library

PS C:\MySpace\Projects\mpeg2ts\build_dll> cmake --build .
Microsoft (R) Build Engine version 17.2.1+52cd2da31 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

common.vcxproj -> C:\MySpace\Projects\mpeg2ts\build_dll\libs\common\Debug\common-d.lib
h264codec.vcxproj -> C:\MySpace\Projects\mpeg2ts\build_dll\libs\h264codec\Debug\h264codec-d.dll
mpeg2codec.vcxproj -> C:\MySpace\Projects\mpeg2ts\build_dll\libs\mpeg2codec\Debug\mpeg2codec-d.dll
mpeg2ts.vcxproj -> C:\MySpace\Projects\mpeg2ts\build_dll\libs\mpeg2ts\Debug\mpeg2ts-d.dll
LINK : fatal error LNK1104: cannot open file '....\libs\mpeg2codec\Debug\mpeg2codec-d.lib' [C:\MySpace\Projects\mpeg2t
s\build_dll\samples\TsUtilities\sample_tsutilities.vcxproj]

Manually copy the library

PS C:\MySpace\Projects\mpeg2ts\build_dll> cmake --build .
Microsoft (R) Build Engine version 17.2.1+52cd2da31 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

common.vcxproj -> C:\MySpace\Projects\mpeg2ts\build_dll\libs\common\Debug\common-d.lib
h264codec.vcxproj -> C:\MySpace\Projects\mpeg2ts\build_dll\libs\h264codec\Debug\h264codec-d.dll
mpeg2codec.vcxproj -> C:\MySpace\Projects\mpeg2ts\build_dll\libs\mpeg2codec\Debug\mpeg2codec-d.dll
mpeg2ts.vcxproj -> C:\MySpace\Projects\mpeg2ts\build_dll\libs\mpeg2ts\Debug\mpeg2ts-d.dll
LINK : fatal error LNK1104: cannot open file '....\libs\h264codec\Debug\h264codec-d.lib' [C:\MySpace\Projects\mpeg2ts
build_dll\samples\TsUtilities\sample_tsutilities.vcxproj]

Manually copy the library
PS C:\MySpace\Projects\mpeg2ts\build_dll> cmake --build .
Microsoft (R) Build Engine version 17.2.1+52cd2da31 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

common.vcxproj -> C:\MySpace\Projects\mpeg2ts\build_dll\libs\common\Debug\common-d.lib
h264codec.vcxproj -> C:\MySpace\Projects\mpeg2ts\build_dll\libs\h264codec\Debug\h264codec-d.dll
mpeg2codec.vcxproj -> C:\MySpace\Projects\mpeg2ts\build_dll\libs\mpeg2codec\Debug\mpeg2codec-d.dll
mpeg2ts.vcxproj -> C:\MySpace\Projects\mpeg2ts\build_dll\libs\mpeg2ts\Debug\mpeg2ts-d.dll
mpeg2codec-d.lib(Mpeg2Codec.obj) : error LNK2019: unresolved external symbol "public: __cdecl GetBits::GetBits(void)" (
??0GetBits@@qeaa@XZ) referenced in function "public: __cdecl mpeg2::Mpeg2VideoEsParser::Mpeg2VideoEsParser(void)" (??0M
peg2VideoEsParser@mpeg2@@qeaa@XZ) [C:\MySpace\Projects\mpeg2ts\build_dll\samples\TsUtilities\sample_tsutilities.vcxproj
]
h264codec-d.lib(H264Codec.obj) : error LNK2001: unresolved external symbol "public: __cdecl GetBits::GetBits(void)" (??
0GetBits@@qeaa@XZ) [C:\MySpace\Projects\mpeg2ts\build_dll\samples\TsUtilities\sample_tsutilities.vcxproj]
mpeg2codec-d.lib(Mpeg2VideoParser.obj) : error LNK2019: unresolved external symbol "public: unsigned __int64 __cdecl Ge
tBits::getBits(int)" (?getBits@GetBits@@QEAA_KH@Z) referenced in function "public: class std::vector<struct mpeg2::EsIn
foMpeg2,class std::allocator > __cdecl mpeg2::Mpeg2VideoEsParser::analyze(void)" (?analyze@M
peg2VideoEsParser@mpeg2@@qeaa?AV?$vector@UEsInfoMpeg2@mpeg2@@v?$allocator@UEsInfoMpeg2@mpeg2@@@std@@@std@@xz) [C:\MySpa
ce\Projects\mpeg2ts\build_dll\samples\TsUtilities\sample_tsutilities.vcxproj]
h264codec-d.lib(H264Parser.obj) : error LNK2001: unresolved external symbol "public: unsigned __int64 __cdecl GetBits::
getBits(int)" (?getBits@GetBits@@QEAA_KH@Z) [C:\MySpace\Projects\mpeg2ts\build_dll\samples\TsUtilities\sample_tsutiliti
es.vcxproj]
mpeg2codec-d.lib(Mpeg2VideoParser.obj) : error LNK2019: unresolved external symbol "public: void __cdecl GetBits::reset
Bits(unsigned char const *,unsigned __int64,unsigned __int64)" (?resetBits@GetBits@@QEAAXPEBE_K1@Z) referenced in funct
ion "public: class std::vector<struct mpeg2::EsInfoMpeg2,class std::allocator > __cdecl mpeg
2::Mpeg2VideoEsParser::analyze(void)" (?analyze@Mpeg2VideoEsParser@mpeg2@@qeaa?AV?$vector@UEsInfoMpeg2@mpeg2@@v?$alloca
tor@UEsInfoMpeg2@mpeg2@@@std@@@std@@xz) [C:\MySpace\Projects\mpeg2ts\build_dll\samples\TsUtilities\sample_tsutilities.v
cxproj]
h264codec-d.lib(H264Parser.obj) : error LNK2001: unresolved external symbol "public: void __cdecl GetBits::resetBits(un
signed char const *,unsigned __int64,unsigned __int64)" (?resetBits@GetBits@@QEAAXPEBE_K1@Z) [C:\MySpace\Projects\mpeg2
ts\build_dll\samples\TsUtilities\sample_tsutilities.vcxproj]
mpeg2codec-d.lib(Mpeg2VideoParser.obj) : error LNK2019: unresolved external symbol "public: void __cdecl GetBits::skipB
its(int)" (?skipBits@GetBits@@QEAAXH@Z) referenced in function "public: class std::vector<struct mpeg2::EsInfoMpeg2,cla
ss std::allocator > __cdecl mpeg2::Mpeg2VideoEsParser::analyze(void)" (?analyze@Mpeg2VideoEs
Parser@mpeg2@@qeaa?AV?$vector@UEsInfoMpeg2@mpeg2@@v?$allocator@UEsInfoMpeg2@mpeg2@@@std@@@std@@xz) [C:\MySpace\Projects
\mpeg2ts\build_dll\samples\TsUtilities\sample_tsutilities.vcxproj]
h264codec-d.lib(H264Parser.obj) : error LNK2001: unresolved external symbol "public: void __cdecl GetBits::skipBits(int
)" (?skipBits@GetBits@@QEAAXH@Z) [C:\MySpace\Projects\mpeg2ts\build_dll\samples\TsUtilities\sample_tsutilities.vcxproj]
C:\MySpace\Projects\mpeg2ts\build_dll\samples\TsUtilities\Debug\sample_tsutilities.exe : fatal error LNK1120: 4 unresol
ved externals [C:\MySpace\Projects\mpeg2ts\build_dll\samples\TsUtilities\sample_tsutilities.vcxproj]
PS C:\MySpace\Projects\mpeg2ts\build_dll>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.