-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp.save-failed
90 lines (82 loc) · 3.25 KB
/
main.cpp.save-failed
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <stdio.h>
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
//exemple trouvé sur https://trac.ffmpeg.org/wiki/Create%20a%20video%20slideshow%20from%20images
// ffmpeg -framerate 1/5 -i img%03d.png -c:v libx264 -vf "fps=25,format=yuv420p" out.mp4
//
//exemple trouvé sur http://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg/
//command = [ FFMPEG_BIN,
// '-y', # (optional) overwrite output file if it exists
// '-f', 'rawvideo',
// '-vcodec','rawvideo',
// '-s', '1280x720', # size of one frame
// '-pix_fmt', 'rgb24',
// '-r', '24', # frames per second
// '-i', '-', # The imput comes from a pipe
// '-an', # Tells FFMPEG not to expect any audio
// '-vcodec', 'mpeg'",
// 'my_output_videofile.mp4' ]
//
// exemple trouvé sur https://sites.google.com/site/linuxencoding/ffmpeg-tips
// cat $(ls -t *jpg) | ffmpeg -f image2pipe -vcodec mjpeg -r 25 -i - -i backwards.wav -vcodec libx264 -preset slow -crf 20 -threads 0 -acodec flac output.mkv
// NB:
//preset
//Sets the time that FFMPEG will take to compress the video. The slower,
//the better the compression rate. Possibilities are: ultrafast,superfast,
//veryfast, faster, fast, medium (default), slow, slower, veryslow,
//placebo.
// exemple élaboré et testé avec succès sous Linux, avec des petites images, les très grandes semblant problématiques
// cat Nov17_3?.JPG|avconv -y -c:v mjpeg -f image2pipe -framerate 1/2 -i - -an -r 24 -c:v libx264 -bitrate 3000k -pix_fmt yuv420p tmp.mp4
//
using namespace std;
using namespace cv;
int main() {
FILE *in, *bis;
char executable[]="D:\\Utilisateurs\\FR20340\\Desktop\\ffmpeg-20140818-git-3c19744-win64-shared\\bin\\ffmpeg.exe \
-y -f rawvideo -vcodec rawvideo -s 1280x720 -pix_fmt rgb24 -framerate 1/5 -i - -r 24 -an -vcodec libx264 -preset slow -pix_fmt yuv420p \
D:\\TEMP\\output_ffmpeg.mp4";
cout << "début du programme\n";
cout << executable << endl;
if(!(in = popen(executable, "w"))){
cerr << "le pOpen() s'est mal passé";
return 1;
}
if (!(bis = fopen("D:\\TEMP\\bis.raw","w"))){
cerr << "le fopen s'est mal passé";
return 2;
}
Mat im = imread("D:\\Google Drive\\mes données\\photos\\TMP.JPG");
if (im.empty()) {
cout<< "impossible de lire l image\n";
return -2;
}
//imshow("titre",im);
Mat dst;
Size size(1280, 720); // 720 rows x 1280 cols x 3 uchars => 3840 uchar par row; step=[3840, 3]
resize(im, dst,size);
printf( "row=%d, cols=%d, step=(%d,%d).\n",dst.rows, dst.cols, dst.step[0], dst.step[1]);
imshow("en grand", dst);
//cf. http://docs.opencv.org/opencv_tutorials.pdf
int i,j,k,l;
uchar *p /*, r[2]*/;
for (k=l=0; l<2; l++)
for (i=0 ; i<dst.rows ; i++) {
p = dst.data+i*dst.step[0];
for (j=0 ; j<dst.cols ; j++) {
k+=fwrite((void*)p, dst.step[1], 1, in);
fwrite((void*)p, 1, 3, bis);
/* *r=*p;
r[0]=i % 255;
r[1]=0*j % 255;
r[2]=0*(i+j) % 255;
k+=fwrite((void*)r, dst.step[1], 3, in);
fwrite((void*)r, 1, 3, bis); */
}
}
cout << k << " octets ecrits.\n";
pclose(in);
waitKey(0);
cout << "fin. le programme se termine normalement.";
return 0;
}