这是一次失败的传输试验,除了传输之外的都成功了,就差传输了。
问题1:发过去的内容提示RTP版本不支持
问题2:发过去接受的结构体显示if pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO,没错,是AVMEDIA_TYPE_AUDIO,而我发过去的明明完完全全的是AVMEDIA_TYPE_VIDEO。
问题3:多次尝试之后,PTS和DTS会有概率出现负数的问题、
问题4:发送端提示
[udp @ 0000019ae70abc80] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)
[udp @ 0000019ae70bbf40] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)
[rtp_mpegts @ 0000019ae70a9e00] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
[libx264 @ 0000019ae46a4fc0] non-strictly-monotonic PTS
接收端提示
a78140] decode_slice_header error
[h264 @ 000001f6d2a78140] no frame!
[h264 @ 000001f6d2a78140] non-existing PPS 0 referenced
[h264 @ 000001f6d2a78140] non-existing PPS 0 referenced
[h264 @ 000001f6d2a78140] decode_slice_header error
[h264 @ 000001f6d2a78140] no frame!
先记录一下,在慢慢研究
发送端:
/**
* ref. 雷霄骅 Lei Xiaohua
//packet->pFrame->pFrameYUV->pPacket->send
*/
#include <stdio.h>
#include <iostream>
#include <winsock2.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#pragma comment(lib,"ws2_32.lib")
#define __STDC_CONSTANT_MACROS
extern "C"
{
#include "include/libavcodec/avcodec.h"
#include "include/libavformat/avformat.h"
#include "include/libswscale/swscale.h"
#include "include/libavdevice/avdevice.h"
#include "include/libavutil/imgutils.h"
#include "include/libavutil/opt.h"
#include "include/libavutil/imgutils.h"
#include "include/libavutil/mathematics.h"
#include "include/libavutil/time.h"
//#include "includes/SDL.h"
};
#pragma pack(push,1)
struct sendbuf {
AVPacket pPacket;
char buf[1500];
};
int Send(uint8_t * buf ,int size) {
return 0;
}
struct sockaddr_in G_Servaddr;
#pragma pack(pop)
int main(int argc, char* argv[])
{
AVFormatContext *pFormatContext = NULL;
int i = 0, videoindex;
AVCodecContext *pCodecContext = NULL;
AVCodec *pCodec = NULL;
FILE *fp_out;
//fp_out = fopen("ds.h264", "wb");
fp_out = fopen("ds.h264", "wb");
AVPacket pPacket;
int y_size;
FILE *fp_yuv = fopen("output.yuv", "wb+");
struct SwsContext *img_convert_ctx;
AVFormatContext *pFormatContextEncod = NULL;
AVCodecContext *pCodecContextEncod = NULL;
AVCodec *pCodecEncod = NULL;
//AVCodecID codec_id = AV_CODEC_ID_H264;//H.265和HEVC是同一个东西
AVCodecID codec_id = AV_CODEC_ID_H264;//H.265和HEVC是同一个东西
int in_w = 1920, in_h = 1080;
int framenum = 100;
int ret, got_output, xy_size, got_picture;
/*socket--------------------------------*/
WSADATA wsa;
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
{
printf("WSAStartup failed!\n");
return 1;
}
int connfd;
//socklen_t addrlen(0);
SOCKET ServerS = socket(AF_INET, SOCK_DGRAM, 0);
SOCKADDR_IN DistAddr;
DistAddr.sin_family = AF_INET;
DistAddr.sin_port = htons(8800);
DistAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); //inet_addr("192.168.23.232");
if (DistAddr.sin_addr.s_addr == INADDR_NONE)
{
printf("不可用地址!\n");
return -1;
}
int time_out = 2000;
//ret = setsockopt(ServerS, SOL_SOCKET, SO_RCVTIMEO, (char*)&time_out, sizeof(time_out))
/*socket--------------------------------*/
char buf[1400]; //1500 bytes
sendbuf buff;
av_register_all();
avformat_network_init();
pFormatContext = avformat_alloc_context();
avdevice_register_all();
AVDictionary* options = NULL;
av_dict_set(&options, "video_size", "1920*1080", 0);//设定捕捉范围
av_dict_set(&options, "framerate", "25", 0);
AVInputFormat *ifmt = av_find_input_format("gdigrab");
if (avformat_open_input(&pFormatContext, "desktop", ifmt, &options) != 0)//输入流
{ printf("Couldn't open input stream.\n"); return -1; }
if (avformat_find_stream_info(pFormatContext, NULL) < 0)//找到流
{ printf("Couldn't find stream information.\n"); return -1; }
videoindex = -1;
for (i = 0; i < pFormatContext->nb_streams; i++)
{
if (pFormatContext->streams[i]->codec->codec_typ