'Encrypting a video file with the 3DES algorithm
I am encrypting a video file using 3DES algorithm and ffmpeg library.In my program, I use two channels, each connected to its own instance of FFmpeg. Basically, I tried to read the images one by one from the input pipe, invert the color of each pixel with the 3DES algorithm, then write the modified images to the output pipe. The input video I'm using is mp4 type, but I have a segmantation problem Can someone help me?
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
//#include "key.txt"
#define W 720
#define H 720
unsigned char frame[H][W][3] = {0};
unsigned char frame0[H][W][3] = {0};
FILE* out;
int LEFT[17][32], RIGHT[17][32];
int IPpixel[64];
int EXPpixel[48];
int XORpixel[48];
int X[8][6];
int X2[32];
int R[32];
int key56bit[56];
int key48bit[17][48];
int CIPHER[64];
int ENCRYPTED[64];
int main()
{
int x,y,count;
int32_t L , R ;
FILE *pipein0 = popen("ffmpeg -i video2.mp4 -f image2pipe -vcodec rawvideo -pix_fmt rgb24 -", "r");
out = popen("ffmpeg -y -f rawvideo -vcodec rawvideo -pix_fmt rgb24 -s 1280x720 -r 25 -i - -f mp4 -q:v 5 -an -vcodec mpeg4 output1.mp4", "wb");
fclose(out);
out = fopen("decrypted.txt", "wb+");
fclose(out);
out = fopen("cipher.txt", "wb+");
fclose(out);
create16Keys();
while(1)
{
// Read a frame from the input pipe into the buffer
count = fread(frame, 1, H*W*3, pipein0);
if (count != H*W*3) break;
// Process this frame
for (y=0 ; y<H ; ++y) for (x=0 ; x<W ; ++x)
{////****** il faut divise la valeur de pixel et prandre le left of value and the rigth of value*************////
L =frame[y][x][0];///red
R= frame[y][x][0];
long int n1 = findFileSize() / 8;
convertCharToBit(n1);
encrypt(n1);
decrypt(n1);
frame[y][x][0]=L & R;
L =frame[y][x][1];///green
R= frame[y][x][1];
long int n2 = findFileSize() / 8;
convertCharToBit(n2);
encrypt(n2);
decrypt(n2);
frame[y][x][1]=L & R;
L =frame[y][x][2];///blue
R= frame[y][x][2];
long int n3 = findFileSize() / 8;
convertCharToBit(n3);
encrypt(n3);
decrypt(n3);
frame[y][x][2]=L & R;
fwrite(frame0, 1, H*W*3, out);
}
}
fflush(pipein0);
pclose(pipein0);
fflush(out);
pclose(out);
return 0;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
