How to overwrite i-frames of a video?

I want to destroy all the i-frames of the video. In doing this, I want to check if only the i-frames of the video are encrypted enough to make it impossible. How can i do this? Only deleting them and re-compressing the video will not be the same as rewriting an i-frame in a stream without recalculating b-frames, etc.

+3
source share
3 answers

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);
//initialize buffer to 0xffffffff
unsigned char buffer[4] = {0xff, 0xff, 0xff, 0xff};
while(!ifs.eof())
{
    //Shift to make space for new read.
    buffer[0] = buffer[1];
    buffer[1] = buffer[2];
    buffer[2] = buffer[3];

    //read next byte from file
    buffer[3] = ifs.get();

    //see if the current buffer contains the start code.
    if(buffer[0]==0x00 && buffer[1]==0x00 && buffer[2]==0x01 && buffer[3]==0xb6)
    {
        //vop start code found
        //Test for I-frame
        unsigned char ch = ifs.get();
        int vop_coding_type = (ch & 0xc0) >> 6;   //masks out the first 2 bits and shifts them to the least significant bits of the uchar
        if(vop_coding_type == 0)
        {
            //It is an I-frame
            //...
        }
    }
}

24- , 3- . , ffmpeg .

+5

Windows VFW I-. I-, FindSample FIND_KEY.

0

, AVPAcket, , ? FFmpeg AVPacket

0
source

Source: https://habr.com/ru/post/1740767/


All Articles