Using libavformat (library from ffmpeg), you can demultiplex the video into packages that represent a single frame. You can then encrypt the data in packets marked as key frames. Finally, you can reconfigure the video to a new file. There is a good libavformat / libavcodec tutorial here . You will not need to actually decode / encode frames, because I assume that you just want to encrypt the compressed data. In this case, after reading AVPacket, just encrypt your data if it is a key frame ( packet->flags & PKT_FLAG_KEY). Then you have to write the packages to a new file.
, , I-frame, libavformat - , , . , libavformat . .
, - , , , , , I-. , (AVI, MP4, MPEG-PS/TS) , - . , , , , . ffmpeg :
ffmpeg -i filename -an -vcodec copy -f rawvideo output_filename
( ) . , , I-.
, MPEG-4 32- 0x000001b6, VOP ( ). , I- , , 00. I-, , (24- 0x000001). , , , .
, I- , ; . , , , , B P, . I-, (I- , ) . - , . I- .
:
, 4- , . ++ :
#include <iostream>
using namespace std;
ifstream ifs("filename", ios::in | ios::binary);
unsigned char buffer[4] = {0xff, 0xff, 0xff, 0xff};
while(!ifs.eof())
{
buffer[0] = buffer[1];
buffer[1] = buffer[2];
buffer[2] = buffer[3];
buffer[3] = ifs.get();
if(buffer[0]==0x00 && buffer[1]==0x00 && buffer[2]==0x01 && buffer[3]==0xb6)
{
unsigned char ch = ifs.get();
int vop_coding_type = (ch & 0xc0) >> 6;
if(vop_coding_type == 0)
{
}
}
}
24- , 3- . , ffmpeg .