forked from Raveler/ffmpeg-cpp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencode_video.cpp
More file actions
57 lines (44 loc) · 1.62 KB
/
Copy pathencode_video.cpp
File metadata and controls
57 lines (44 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include "ffmpegcpp.h"
using namespace std;
using namespace ffmpegcpp;
int main()
{
// This example will take a raw audio file and encode it into as MP3.
try
{
// Create a muxer that will output the video as MKV.
Muxer* muxer = new Muxer("output.mpg");
// Create a MPEG2 codec that will encode the raw data.
VideoCodec* codec = new VideoCodec("mpeg2video");
// Set the global quality of the video encoding. This maps to the command line
// parameter -qscale and must be within range [0,31].
codec->SetQualityScale(0);
// Create an encoder that will encode the raw audio data as MP3.
// Tie it to the muxer so it will be written to the file.
VideoEncoder* encoder = new VideoEncoder(codec, muxer);
// Load the raw video file so we can process it.
// FFmpeg is very good at deducing the file format, even from raw video files,
// but if we have something weird, we can specify the properties of the format
// in the constructor as commented out below.
RawVideoFileSource* videoFile = new RawVideoFileSource("samples/carphone_qcif.y4m", encoder);
// Prepare the output pipeline. This will push a small amount of frames to the file sink until it IsPrimed returns true.
videoFile->PreparePipeline();
// Push all the remaining frames through.
while (!videoFile->IsDone())
{
videoFile->Step();
}
// Save everything to disk by closing the muxer.
muxer->Close();
}
catch (FFmpegException e)
{
cerr << "Exception caught!" << endl;
cerr << e.what() << endl;
throw e;
}
cout << "Encoding complete!" << endl;
cout << "Press any key to continue..." << endl;
getchar();
}