简体   繁体   English

使用Ffmpeg传输SEI

[英]Transport SEI With Ffmpeg

I need to transport some data from drone through the help of Ffmpeg.The data includes frame data and some other parameters such as the timing roll/pitch/height/direction of the drone,and when I get the image of the frame,the corresponding parameters should be also pulled out,So I dicede to send these parameters as SEI. 我需要通过Ffmpeg来从无人机上传输一些数据。这些数据包括帧数据和其他一些参数,例如无人机的定时滚动/俯仰/高度/方向,以及当我获得帧图像时,相应的参数也应该被拉出,所以我切丁将这些参数作为SEI发送。 Then the questions coming,after sending sps pps,I send my own SEI packet,eg: 然后问题来了,在发送sps pps之后,我发送了自己的SEI数据包,例如:

 if(pkt->size>10&&pkt->data[0] ==0
       &&pkt->data[1] ==0
       &&pkt->data[2] ==0
       &&pkt->data[3] ==1
       &&(pkt->data[4] == 103 || pkt->data[4] == 104)){
        i++;
    }
    AVPacket *newPacket = nullptr;
    // 0 0 0 1 6 8*16
    if(i == 2){
        i = 0;
        newPacket = (AVPacket *)av_malloc(sizeof(AVPacket));
        av_init_packet(newPacket);
        newPacket->data = new uint8_t[8];
        newPacket->data[0] = 0;
        newPacket->data[1] = 0;
        newPacket->data[2] = 0;
        newPacket->data[3] = 1;
        newPacket->data[4] = 6;
        newPacket->data[5] = 123;
        newPacket->data[6] = 134;
        newPacket->data[7] = 128;
        newPacket->size = 8;
    }
 av_write_frame(*it , pkt);
        av_free_packet(pkt);
        if(newPacket){
            av_write_frame(*it , newPacket);
            av_free_packet(newPacket);
        }

But,At the receiving terminate,I only find the API:av_read_frame.The API just decode every complete frame from AVFormatContext.My SEI go nothing! 但是,在接收终止时,我只找到API:av_read_frame。API只是从AVFormatContext解码每个完整的帧。我的SEI毫无用处! Besides,I also trying to put my parameters in side_data or metadate of AVFrame,but after rtp tansporting,received AVFrame's side_data and metadata is 0x00 again. 此外,我还尝试将参数放入AVFrame的side_data或metadate中,但是在rtp tansporting之后,收到的AVFrame的side_data和元数据再次为0x00。 Could someone give me some train of thought? 有人可以给我一些思路吗?

At the receiving terminal, did you check if the AVPackets you obtained using av_read_frame() has your SEI message on their data? 在接收终端,您是否检查过使用av_read_frame()获得的AVPackets的数据上是否包含SEI消息? My approach to save SEI for each frame was similiar to yours except the encoding part. 除编码部分外,我为每一帧保存SEI的方法与您的相似。 My steps are: 我的步骤是:

  1. First, I encoded frames using x264 library (I don't think this would make a difference) 首先,我使用x264库对帧进行了编码(我认为这不会有所作为)
  2. Then, like you I fwrite() a packet then a SEI (you don't have to explicity declare a AVPacket for SEI and use packet->data for SEI, simply declare uchar* or uint8_t*) 然后,像您一样先写一个数据包,然后写一个SEI(您不必为SEI显式声明一个AVPacket并为SEI使用packet-> data,只需声明uchar *或uint8_t *)
  3. After using av_read_frame(), the SEI message appears on packet->data along with encoded frame. 使用av_read_frame()之后,SEI消息与编码帧一起出现在packet-> data上。
  4. I obtain SEI message from packet->data just after the encoded frame's last byte. 我在编码帧的最后一个字节之后从数据包->数据中获取SEI消息。 (Actually, you cannot determine the last byte of encoded frame. But you can do a trick and indicate its length on SEI) (实际上,您无法确定编码帧的最后一个字节。但是您可以做一些技巧,并在SEI上指出其长度)
  5. Lastly, without modifying the packet->data, I decode the frame with the usual way. 最后,在不修改数据包->数据的情况下,我以通常的方式对帧进行解码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM