Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

light-weight c++ based http/s streamer

License

NotificationsYou must be signed in to change notification settings

nejatafshar/lxstreamer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

a light-weight, fast and cross-platform c++ library for http/s streaming and recording based on FFmpeg

Features

  • streaming:
    • video/audio streaming for multiple sources
    • http streaming
    • optionalhttps streaming withOpenSSLas dependency
    • sources could be any live stream, camera, webcam, file and whateverFFmpeg supports
    • custom stream encoding for video and audio
    • stream authentication
    • preferred transport container selection
  • record:
    • record sources tomp4,mkv,... files
    • chunked record by size or duration
    • record to defined files without chunking
    • custom video and audio encoding
    • optional batch writes to disk
  • webcam:
    • record
    • streaming with custom encoding
    • auto defined encoding config if not defined
  • local media files:
    • stream, record and reencode
    • seek
    • speed change
  • cross-platform: compiles for any platform with ac++17 compiler
  • light-weight and fast with low overhead

Dependencies

  • FFmpeg 5.1.* or later
  • OpenSSL 1.1.* for https

Rundepends.sh to get depedent libs for your current OS. All dependencies are put into3rdparty directory.

depends.sh gets pre-compiledFFmpeg libraries that include the most commonly used decoders and encoders, optimized for a suitable build size. If you require additional encoders or decoders not included in these builds, you can provide your own compiledFFmpeg libraries.

Build

Run in terminal:

mkdir buildcd buildcmake /path/to/lxstreamermake

lxstreamer is built as a static lib. Examples are also built by default which could be disabled by trunning off CMake optionBUILD_EXAMPLES.

HTTPS option should beON forhttps capability withOpenSSL libs in3rdparty directory.

Usage samples

A simplehttp streamer on port8000 streaming a local video file:

lxstreamer::streamer streamer{8000};streamer.add_source({"src1","path/to/local/video/file"});streamer.start();

https streamer with multiple sources:

lxstreamer::streamer streamer{8000,true};// set ssl cert and key file names in app dir (or full pathes)streamer.set_ssl_cert_path("server.pem","server.key");streamer.add_source({"src1","rtsp://192.168.1.10/main"});streamer.add_source({"src2","rtsp://192.168.1.49/main"});...streamer.start();

a streamer with awebcam as a source, streaming inh264 codec with max500 kb/s bandwidth:

lxstreamer::streamer streamer{8000};lxstreamer::source_args_t args;args.name                              ="webcam1";args.url                               ="avdevice::video=USB2.0_Camera";args.video_encoding_view.codec         = lxstreamer::codec_t::h264;args.video_encoding_view.max_bandwidth =500;// kb/sstreamer.add_source(args);streamer.start();

A streamerrecording an added source in chunks of100 MBmkv files, buffering packets and writing every3 seconds to disk:

lxstreamer::streamer streamer{8000};streamer.add_source({"src1","rtsp://192.168.1.10/main"});lxstreamer::record_options_t opt;opt.format         = lxstreamer::file_format_t::mkv;opt.file_size      =100;// MBopt.write_interval =3;// secondsstreamer.start_recording("src1", opt);streamer.start();

turn offstdout logging, make it verbose and use a custom handler to write messages and errors to files:

lxstreamer::streamer streamer{8000};// create and open log filesstd::ofstreamtrace_log("log_trace.txt", std::ios_base::app);std::ofstreamnormal_log("log_normal.txt", std::ios_base::app);lxstreamer::streamer::set_log_level(lxstreamer::log_level_t::trace);streamer.set_log_to_stdout(false);streamer.set_log_callback(    [&](std::string str, lxstreamer::log_level_t level) {if (level == lxstreamer::log_level_t::trace) {            trace_log << str << std::endl;            trace_log.flush();        }else {            normal_log << str << std::endl;            normal_log.flush();        }    });...streamer.start();

Notes

To get stream in a client the following format should be used:

  • forhttp
http://{IP}:{PORT}/stream?source={NAME}
  • forhttps
https://{IP}:{PORT}/stream?source={NAME}

For stream authentication you can setauth_session value when adding a source to streamer. Then clients should provide asession in stream query with the proper value:

https://{IP}:{PORT}/stream?source={NAME}&session={AUTH_SESSION}

License

Copyright (C) 2022-present Nejat Afsharnejatafshar@gmail.com

Distributed under the MIT License (http://opensource.org/licenses/MIT)


[8]ページ先頭

©2009-2025 Movatter.jp