Comments (1)
Hey,
This is actually the use case I developed this library for, so I can confirm this works.
We were using this library to receive video data frame by frame and record it to a h264-encoded file. In our case, the video data came from a render engine, but it can come from a video, as long as the video data is in a format ffmpeg can understand.
Here's the code we used to write frame by frame from whatever source. EncodeFrame is called with a raw, unencoded RGBA byte array that whenever a frame arrives from the source.
// AniHub.LipSync.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include <string>
#include <iostream>
#include <stdio.h>
#include <io.h>
#include <filesystem>
#include <fstream>
#include <sstream>
using namespace std;
using namespace ffmpegcpp;
struct Context
{
VideoCodec* codec = nullptr;
Muxer* muxer = nullptr;
RawVideoDataSource* source = nullptr;
VideoFrameSink* encoder = nullptr;
};
void CleanUp(Context* ctx)
{
if (ctx->muxer != nullptr) delete ctx->muxer;
if (ctx->source != nullptr) delete ctx->source;
if (ctx->encoder != nullptr) delete ctx->encoder;
delete ctx;
}
void* StartExport(const char* outputFileName, int width, int height, int framesPerSecond)
{
Context* ctx = new Context();
try
{
// create the output muxer
ctx->muxer = new Muxer(outputFileName);
// create the codec based on the output extension
H264NVEncCodec* h264codec = new H264NVEncCodec();
h264codec->SetPreset("losslesshp");
ctx->codec = h264codec;
// create the encoder that will link the source and muxer together
ctx->encoder = new VideoEncoder(ctx->codec, ctx->muxer);
// if we need to extract alpha, we need to send the A-channel to the filter
// and we let the filter take care of the conversion to the final pixel format.
ctx->source = new RawVideoDataSource(width, height, AV_PIX_FMT_BGRA, AV_PIX_FMT_RGBA, framesPerSecond, ctx->encoder);
return ctx;
}
catch (FFmpegException e)
{
CleanUp(ctx);
return nullptr;
}
}
int EncodeFrame(void* handle, void* frameData, int bytesPerRow)
{
Context* ctx = (Context*)handle;
// push to the source
try
{
ctx->source->WriteFrame(frameData, bytesPerRow);
return 0;
}
catch (FFmpegException e)
{
return -1;
}
}
void Cancel(void* handle)
{
Context* ctx = (Context*)handle;
CleanUp(ctx);
}
int Close(void* handle)
{
Context* ctx = (Context*)handle;
try
{
ctx->muxer->Close();
CleanUp(ctx);
return 0;
}
catch (FFmpegException e)
{
return -1;
}
}
from ffmpeg-cpp.
Related Issues (20)
- Links are dead HOT 1
- Amerge filter
- Win32 version
- transcode to memory HOT 2
- Using namespace is not allowed in header file HOT 4
- For your information
- C++17 / v142 / 4.2.3 HOT 1
- demo with 'GENERATED video failed
- filter output HOT 1
- Linux support HOT 5
- cannot support Alpha-Channel video? HOT 2
- Reading timecode metadata from file?
- [ERROR] Dead Link on the Code -> README.MD : Raveler FFMPEG CPP
- UDP streaming
- Can I use this library for video captureing from my screen? ( as Screen Recorder)
- Setting packet duration
- support for latest ffmpeg version
- compiling error
- OpenCV and RTMP HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ffmpeg-cpp.