-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
125 changed files
with
30,217 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Drawing; | ||
using RtspCapture.processor; | ||
using RtspCapture.RawFramesReceiving; | ||
|
||
namespace RtspCapture | ||
{ | ||
|
@@ -23,28 +25,65 @@ public class Options | |
[Option('i', "interval", Required = false, HelpText = "Snapshots saving interval in seconds")] | ||
public int Interval { get; set; } = 5; | ||
} | ||
private static readonly RTSPProcessor rTSPProcessor = new RTSPProcessor(); | ||
//private RawFramesSource _rawFramesSource; | ||
|
||
public event EventHandler<string> StatusChanged; | ||
|
||
//public IVideoSource VideoSource => _realtimeVideoSource; | ||
static void Main(string[] args) | ||
{ | ||
Parser.Default.ParseArguments<Options>(args) | ||
.WithParsed(options => | ||
{ | ||
var cancellationTokenSource = new CancellationTokenSource(); | ||
|
||
Task makeSnapshotsTask = MakeSnapshotsAsync(options, cancellationTokenSource.Token); | ||
|
||
Console.ReadKey(); | ||
Parser.Default.ParseArguments<Options>(args) | ||
.WithParsed(options => | ||
{ | ||
var cancellationTokenSource = new CancellationTokenSource(); | ||
|
||
//Task makeSnapshotsTask = MakeSnapshotsAsync(options, cancellationTokenSource.Token); | ||
StartCapture(options); | ||
Console.ReadKey(); | ||
|
||
cancellationTokenSource.Cancel(); | ||
makeSnapshotsTask.Wait(); | ||
}) | ||
.WithNotParsed(options => | ||
{ | ||
Console.WriteLine("Usage example: MjpegSnapshotsMaker.exe " + | ||
cancellationTokenSource.Cancel(); | ||
//makeSnapshotsTask.Wait(); | ||
}) | ||
.WithNotParsed(options => | ||
{ | ||
Console.WriteLine("Usage example: MjpegSnapshotsMaker.exe " + | ||
"-u rtsp://admin:[email protected]:554/ucast/11 " + | ||
"-p S:\\Temp"); | ||
}); | ||
}); | ||
|
||
Console.WriteLine("Press any key to cancel"); | ||
Console.ReadLine(); | ||
|
||
} | ||
|
||
private static void StartCapture(Options options) | ||
{ | ||
//if (_rawFramesSource != null) | ||
// return; | ||
if (!Directory.Exists(options.Path)) | ||
Directory.CreateDirectory(options.Path); | ||
|
||
int intervalMs = options.Interval * 1000; | ||
int lastTimeSnapshotSaved = Environment.TickCount - intervalMs; | ||
|
||
var connectionParameters = new ConnectionParameters(options.Uri); | ||
|
||
RawFramesSource _rawFramesSource = new RawFramesSource(connectionParameters); | ||
_rawFramesSource.ConnectionStatusChanged += ConnectionStatusChanged; | ||
|
||
rTSPProcessor.SetRawFramesSource(_rawFramesSource); | ||
|
||
_rawFramesSource.Start(); | ||
} | ||
|
||
private static void ConnectionStatusChanged(object sender, string s) | ||
{ | ||
//StatusChanged?.Invoke(this, s); | ||
} | ||
|
||
private static async Task MakeSnapshotsAsync(Options options, CancellationToken token) | ||
{ | ||
try | ||
|
@@ -56,37 +95,38 @@ private static async Task MakeSnapshotsAsync(Options options, CancellationToken | |
int lastTimeSnapshotSaved = Environment.TickCount - intervalMs; | ||
|
||
var connectionParameters = new ConnectionParameters(options.Uri); | ||
using (var rtspClient = new RtspClient(connectionParameters)) | ||
{ | ||
rtspClient.FrameReceived += (sender, frame) => | ||
{ | ||
|
||
//using (var rtspClient = new RtspClient(connectionParameters)) | ||
//{ | ||
// rtspClient.FrameReceived += (sender, frame) => | ||
// { | ||
|
||
int ticksNow = Environment.TickCount; | ||
// int ticksNow = Environment.TickCount; | ||
|
||
if (Math.Abs(ticksNow - lastTimeSnapshotSaved) < intervalMs) | ||
return; | ||
// if (Math.Abs(ticksNow - lastTimeSnapshotSaved) < intervalMs) | ||
// return; | ||
|
||
lastTimeSnapshotSaved = ticksNow; | ||
// lastTimeSnapshotSaved = ticksNow; | ||
|
||
string snapshotName = frame.Timestamp.ToString("O").Replace(":", "_") + ".jpg"; | ||
string path = Path.Combine(options.Path, snapshotName); | ||
// string snapshotName = frame.Timestamp.ToString("O").Replace(":", "_") + ".jpg"; | ||
// string path = Path.Combine(options.Path, snapshotName); | ||
|
||
ArraySegment<byte> frameSegment = frame.FrameSegment; | ||
// ArraySegment<byte> frameSegment = frame.FrameSegment; | ||
|
||
var stream = new MemoryStream(frameSegment.Array, 0, frameSegment.Count); | ||
// //var stream = new MemoryStream(frameSegment.Array, 0, frameSegment.Count); | ||
|
||
Image image = Image.FromStream(stream); | ||
// //Image image = Image.FromStream(stream); | ||
|
||
image.Save($"[{DateTime.UtcNow}] Snapshot is saved to {snapshotName}"); | ||
// //image.Save($"[{DateTime.UtcNow}] Snapshot is saved to {snapshotName}"); | ||
|
||
Console.WriteLine($"[{DateTime.UtcNow}] Snapshot is saved to {snapshotName}"); | ||
}; | ||
// Console.WriteLine($"[{DateTime.UtcNow}] Snapshot is saved to {snapshotName}"); | ||
// }; | ||
|
||
Console.WriteLine("Connecting..."); | ||
await rtspClient.ConnectAsync(token); | ||
Console.WriteLine("Receiving..."); | ||
await rtspClient.ReceiveAsync(token); | ||
} | ||
// Console.WriteLine("Connecting..."); | ||
// await rtspClient.ConnectAsync(token); | ||
// Console.WriteLine("Receiving..."); | ||
// await rtspClient.ReceiveAsync(token); | ||
//} | ||
} | ||
catch (OperationCanceledException) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// dllmain.cpp : Defines the entry point for the DLL application. | ||
|
||
#include "stdafx.h" | ||
|
||
BOOL APIENTRY DllMain( HMODULE hModule, | ||
DWORD ul_reason_for_call, | ||
LPVOID lpReserved | ||
) | ||
{ | ||
switch (ul_reason_for_call) | ||
{ | ||
case DLL_PROCESS_ATTACH: | ||
avcodec_register_all(); | ||
#if defined(_DEBUG) | ||
av_log_set_level(AV_LOG_VERBOSE); | ||
#else | ||
av_log_set_level(AV_LOG_PANIC); | ||
#endif | ||
break; | ||
case DLL_THREAD_ATTACH: | ||
case DLL_THREAD_DETACH: | ||
case DLL_PROCESS_DETACH: | ||
break; | ||
} | ||
return TRUE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#ifdef _WINDLL | ||
#define DllExport(rettype) extern "C" __declspec(dllexport) rettype __cdecl | ||
#else | ||
#define DllExport(rettype) extern "C" __attribute__((cdecl)) rettype | ||
#endif | ||
|
||
DllExport(int) create_video_decoder(int codec_id, void **handle); | ||
DllExport(int) set_video_decoder_extradata(void *handle, void *extradata, int extradataLength); | ||
DllExport(int) decode_video_frame(void *handle, void *rawBuffer, int rawBufferLength, int *frameWidth, int *frameHeight, int *framePixelFormat); | ||
DllExport(int) scale_decoded_video_frame(void *handle, void *scalerHandle, void *scaledBuffer, int scaledBufferStride); | ||
DllExport(void) remove_video_decoder(void *handle); | ||
|
||
DllExport(int) create_video_scaler(int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight, int sourcePixelFormat, | ||
int scaledWidth, int scaledHeight, int scaledPixelFormat, int quality, void **handle); | ||
DllExport(void) remove_video_scaler(void *handle); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* AC-3 parser prototypes | ||
* Copyright (c) 2003 Fabrice Bellard | ||
* Copyright (c) 2003 Michael Niedermayer | ||
* | ||
* This file is part of FFmpeg. | ||
* | ||
* FFmpeg is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* FFmpeg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with FFmpeg; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#ifndef AVCODEC_AC3_PARSER_H | ||
#define AVCODEC_AC3_PARSER_H | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
/** | ||
* Extract the bitstream ID and the frame size from AC-3 data. | ||
*/ | ||
int av_ac3_parse_header(const uint8_t *buf, size_t size, | ||
uint8_t *bitstream_id, uint16_t *frame_size); | ||
|
||
|
||
#endif /* AVCODEC_AC3_PARSER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* This file is part of FFmpeg. | ||
* | ||
* FFmpeg is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* FFmpeg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with FFmpeg; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#ifndef AVCODEC_ADTS_PARSER_H | ||
#define AVCODEC_ADTS_PARSER_H | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
#define AV_AAC_ADTS_HEADER_SIZE 7 | ||
|
||
/** | ||
* Extract the number of samples and frames from AAC data. | ||
* @param[in] buf pointer to AAC data buffer | ||
* @param[out] samples Pointer to where number of samples is written | ||
* @param[out] frames Pointer to where number of frames is written | ||
* @return Returns 0 on success, error code on failure. | ||
*/ | ||
int av_adts_header_parse(const uint8_t *buf, uint32_t *samples, | ||
uint8_t *frames); | ||
|
||
#endif /* AVCODEC_ADTS_PARSER_H */ |
Oops, something went wrong.