
Recherche avancée
Autres articles (54)
-
Soumettre améliorations et plugins supplémentaires
10 avril 2011Si vous avez développé une nouvelle extension permettant d’ajouter une ou plusieurs fonctionnalités utiles à MediaSPIP, faites le nous savoir et son intégration dans la distribution officielle sera envisagée.
Vous pouvez utiliser la liste de discussion de développement afin de le faire savoir ou demander de l’aide quant à la réalisation de ce plugin. MediaSPIP étant basé sur SPIP, il est également possible d’utiliser le liste de discussion SPIP-zone de SPIP pour (...) -
Participer à sa traduction
10 avril 2011Vous pouvez nous aider à améliorer les locutions utilisées dans le logiciel ou à traduire celui-ci dans n’importe qu’elle nouvelle langue permettant sa diffusion à de nouvelles communautés linguistiques.
Pour ce faire, on utilise l’interface de traduction de SPIP où l’ensemble des modules de langue de MediaSPIP sont à disposition. ll vous suffit de vous inscrire sur la liste de discussion des traducteurs pour demander plus d’informations.
Actuellement MediaSPIP n’est disponible qu’en français et (...) -
Encoding and processing into web-friendly formats
13 avril 2011, parMediaSPIP automatically converts uploaded files to internet-compatible formats.
Video files are encoded in MP4, Ogv and WebM (supported by HTML5) and MP4 (supported by Flash).
Audio files are encoded in MP3 and Ogg (supported by HTML5) and MP3 (supported by Flash).
Where possible, text is analyzed in order to retrieve the data needed for search engine detection, and then exported as a series of image files.
All uploaded files are stored online in their original format, so you can (...)
Sur d’autres sites (4181)
-
ffmpeg api : av_interleaved_write_frame return error broken pipe under linux
23 juin 2021, par guoyanzhangI just came into contact with the ffmpeg function, and I encountered a problem, av_interleaved_write_frame function fails and returns broken pipe. I don't know what the problem is ? Someone on the Internet said there was a disconnect in the client or server,but what causes the disconnection ? Please help me, thank you


#include "/usr/local/include/libavcodec/avcodec.h"
#include "/usr/local/include/libavformat/avformat.h"
#include "/usr/local/include/libavfilter/avfilter.h"
#include "/usr/local/include/libavutil/mathematics.h"
#include "/usr/local/include/libavutil/time.h"

extern VideoDataStruct *VideoDataListHeader;
extern PushVideoStruct PushVideoInfo;
extern enum IsPushingVideo IsPushingVideoFlag;
extern UCHAR ChangeAnotherVideo;
typedef long long int64;


#define READ_BUF_LEN 1024*12

extern enum IsStopPushVideo StopPushVideoFlag; 

static int read_packet(void *opaque, uint8_t *buf, int buf_size)
{
 int64 dataLen = 0;

 while (dataLen < buf_size)
 {
 if ((VideoDataListHeader != NULL) && (VideoDataListHeader->flag == 1))
 {
 memcpy(&buf[dataLen], VideoDataListHeader->buf, sizeof(VideoDataListHeader->buf));
 dataLen += sizeof(VideoDataListHeader->buf);

 VideoDataListHeader->flag = 0;
 VideoDataListHeader = VideoDataListHeader->next;
 }
 else 
 {
 usleep(10000);
 }
 }
 return buf_size;
}

void *PushVideoFunction(void *arg)
{
 AVFormatContext *m_pFmtCtx = NULL;
 AVPacket pkt; 
 AVIOContext *m_pIOCtx = NULL;
 AVInputFormat *in_fmt = NULL;
 int ret = 0;
 unsigned int i = 0;
 int vid_idx =-1;
 unsigned char *m_pIOBuf = NULL;
 int m_pIOBuf_size = READ_BUF_LEN;
 int64 start_time = 0;
 int frame_index = 0;
 //const char *rtmp_url = "rtmp://192.168.1.108/mytv/01";
 char rtmp_url[140] = {0};
 memset(rtmp_url, 0, sizeof(rtmp_url));
 strcpy(rtmp_url, PushVideoInfo.VideoServer);
 CHAR fileName[64] = {0};

 avformat_network_init(); 
 if (strcmp(PushVideoInfo.VideoType, REAL_VIDEO) == 0) 
 {
 m_pIOBuf = (unsigned char*)av_malloc(m_pIOBuf_size);
 if(m_pIOBuf == NULL)
 {
 printf("av malloc failed!\n");
 goto end;
 }

 
 m_pIOCtx = avio_alloc_context(m_pIOBuf, m_pIOBuf_size, 0, NULL, read_packet, NULL, NULL); 
 if (!m_pIOCtx) 
 {
 printf("avio alloc context failed!\n");
 goto end;
 }

 
 m_pFmtCtx = avformat_alloc_context();
 if (!m_pFmtCtx) 
 {
 printf("avformat alloc context failed!\n");
 goto end;
 }


 //m_pFmtCtx->probesize = BYTES_PER_FRAME * 8;
 m_pFmtCtx->pb = m_pIOCtx; 
 ret = avformat_open_input(&m_pFmtCtx, "", in_fmt, NULL);
 }
 else if (strcmp(PushVideoInfo.VideoType, HISTORY_VIDEO) == 0) 
 {
 sprintf(fileName, "%s", VIDEO_FILE_FOLDER);
 sprintf(fileName+strlen(fileName), "%s", PushVideoInfo.VideoFile);
 ret = avformat_open_input(&m_pFmtCtx, fileName, NULL, NULL);
 }
 if (ret < 0)
 {
 printf("avformat open failed!\n");
 goto end; 
 }

 ret = avformat_find_stream_info(m_pFmtCtx, 0);
 if (ret < 0)
 {
 printf("could not find stream info!\n");
 goto end; 
 } 
 for(i = 0; i < m_pFmtCtx->nb_streams; i++)
 {
 if((m_pFmtCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && (vid_idx < 0))
 {
 vid_idx = i;
 }
 }

 AVFormatContext *octx = NULL;

 ret = avformat_alloc_output_context2(&octx, 0, "flv", rtmp_url);
 if (ret < 0)
 {
 printf("avformat alloc output context2 failed!\n");
 goto end;
 } 

 av_init_packet(&pkt); 

 
 for (i = 0;i < m_pFmtCtx->nb_streams; i++)
 {
 AVCodec *codec = avcodec_find_decoder(m_pFmtCtx->streams[i]->codecpar->codec_id);
 AVStream *out = avformat_new_stream(octx, codec);
 ret = avcodec_parameters_copy(out->codecpar, m_pFmtCtx->streams[i]->codecpar);
 out->codecpar->codec_tag = 0;
 }

 ret = avio_open(&octx->pb, rtmp_url, AVIO_FLAG_WRITE);
 if (!octx->pb)
 {
 printf("avio open failed!\n");
 goto end; 
 }

 ret = avformat_write_header(octx, 0);
 if (ret < 0)
 {
 printf("avformat write header failed!\n");
 goto end; 
 }

 start_time = av_gettime();
 AVStream *in_stream, *out_stream;
 AVRational time_base1;
 AVRational time_base;
 AVRational time_base_q;
 int64 calc_duration;
 int64 pts_time;
 int64 now_time;
 
 ChangeAnotherVideo = 0;
 while((!StopPushVideoFlag) && (ChangeAnotherVideo == 0))
 {
 ret = av_read_frame(m_pFmtCtx, &pkt);
 if (ret < 0)
 {
 break;
 }
 if (pkt.pts == AV_NOPTS_VALUE)
 {
 time_base1 = m_pFmtCtx->streams[vid_idx]->time_base;
 calc_duration = (double)AV_TIME_BASE/av_q2d(m_pFmtCtx->streams[vid_idx]->r_frame_rate);
 
 pkt.pts = (double)(frame_index*calc_duration)/(double)(av_q2d(time_base1)*AV_TIME_BASE);
 pkt.dts = pkt.pts;
 pkt.duration = (double)calc_duration/(double)(av_q2d(time_base1)*AV_TIME_BASE);
 }
 if (pkt.stream_index == vid_idx)
 {
 time_base = m_pFmtCtx->streams[vid_idx]->time_base;
 time_base_q = (AVRational){1, AV_TIME_BASE}; 
 pts_time = av_rescale_q(pkt.dts, time_base, time_base_q);
 now_time = av_gettime() - start_time;
 if (pts_time > now_time)
 {
 av_usleep(pts_time - now_time);
 }
 }
 in_stream = m_pFmtCtx->streams[pkt.stream_index];
 out_stream = octx->streams[pkt.stream_index];
 pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, out_stream->time_base, (enum AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
 pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, out_stream->time_base, (enum AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
 pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base, out_stream->time_base);
 pkt.pos = -1;
 if(pkt.stream_index == vid_idx)
 {
 printf("Send %8d video frames to output URL\n",frame_index);
 frame_index++;
 }
 ret = av_interleaved_write_frame(octx, &pkt);
 if (ret < 0)
 {
 goto end;
 }
 av_packet_unref(&pkt);
 }
 
end:
 printf("---------------------------------stop push video -------------------------------------------\n");
 StopPushVideoFlag = NO_STOP_PUSH;
 IsPushingVideoFlag = NO_PUSHING; 
 ChangeAnotherVideo = 0;
 avformat_close_input(&m_pFmtCtx);
 if (octx)
 {
 avio_closep(&octx->pb);
 avformat_free_context(octx);
 }
 /* note: the internal buffer could have changed, and be != avio_ctx_buffer */
 if (m_pIOCtx) 
 {
 av_freep(&m_pIOCtx->buffer);
 av_freep(&m_pIOCtx);
 }

 if (ret < 0) 
 {
 printf("Error occured : %s\n", av_err2str(ret));
 //return 1;
 }
 pthread_exit((void*)"push video end!"); 
 
}


void PushVideo(void)
{
 int ret = 0;
 pthread_t pushVideoThread;

 ret = pthread_create(&pushVideoThread, NULL, PushVideoFunction, NULL);
 if(ret != 0)
 {
 printf("error : push video thread create failed!\n");
 exit(-1);
 }
 else
 {
 printf("(debug) push video thread create success!\n");
 } 
} 



-
before avio_open() function is executed, it has no connection with RTMP server
23 juin 2021, par guoyanzhangI'm a beginner of ffmpeg API. I think the function connecting to RTMP server is avio_open() function. In my code, before avio_open() function is executed, it has no connection with RTMP server. Whether I understand correctly.
I have a problem at this time : the RTMP server does not find the key frame within 5 seconds after the client connects to the RTMP server, the server will close the connection.
However, according to my understanding, the client has found the key frame before connecting to the server, so the server should also find the key frame. Why can't the key frame be found ?


#include "/usr/local/include/libavcodec/avcodec.h"
#include "/usr/local/include/libavformat/avformat.h"
#include "/usr/local/include/libavfilter/avfilter.h"
#include "/usr/local/include/libavutil/mathematics.h"
#include "/usr/local/include/libavutil/time.h"

extern VideoDataStruct *VideoDataListHeader;
extern PushVideoStruct PushVideoInfo;
extern enum IsPushingVideo IsPushingVideoFlag;
extern UCHAR ChangeAnotherVideo;
typedef long long int64;


#define READ_BUF_LEN 1024*12

extern enum IsStopPushVideo StopPushVideoFlag; 

static int read_packet(void *opaque, uint8_t *buf, int buf_size)
{
 int64 dataLen = 0;

 while (dataLen < buf_size)
 {
 if ((VideoDataListHeader != NULL) && (VideoDataListHeader->flag == 1))
 {
 memcpy(&buf[dataLen], VideoDataListHeader->buf, sizeof(VideoDataListHeader->buf));
 dataLen += sizeof(VideoDataListHeader->buf);

 VideoDataListHeader->flag = 0;
 VideoDataListHeader = VideoDataListHeader->next;
 }
 else 
 {
 usleep(10000);
 }
 }
 return buf_size;
}

void *PushVideoFunction(void *arg)
{
 AVFormatContext *m_pFmtCtx = NULL;
 AVPacket pkt; 
 AVIOContext *m_pIOCtx = NULL;
 AVInputFormat *in_fmt = NULL;
 int ret = 0;
 unsigned int i = 0;
 int vid_idx =-1;
 unsigned char *m_pIOBuf = NULL;
 int m_pIOBuf_size = READ_BUF_LEN;
 int64 start_time = 0;
 int frame_index = 0;
 //const char *rtmp_url = "rtmp://192.168.1.108/mytv/01";
 char rtmp_url[140] = {0};
 memset(rtmp_url, 0, sizeof(rtmp_url));
 strcpy(rtmp_url, PushVideoInfo.VideoServer);
 CHAR fileName[64] = {0};

 avformat_network_init(); 
 if (strcmp(PushVideoInfo.VideoType, REAL_VIDEO) == 0) 
 {
 m_pIOBuf = (unsigned char*)av_malloc(m_pIOBuf_size);
 if(m_pIOBuf == NULL)
 {
 printf("av malloc failed!\n");
 goto end;
 }

 
 m_pIOCtx = avio_alloc_context(m_pIOBuf, m_pIOBuf_size, 0, NULL, read_packet, NULL, NULL); 
 if (!m_pIOCtx) 
 {
 printf("avio alloc context failed!\n");
 goto end;
 }

 
 m_pFmtCtx = avformat_alloc_context();
 if (!m_pFmtCtx) 
 {
 printf("avformat alloc context failed!\n");
 goto end;
 }


 //m_pFmtCtx->probesize = BYTES_PER_FRAME * 8;
 m_pFmtCtx->pb = m_pIOCtx; 
 ret = avformat_open_input(&m_pFmtCtx, "", in_fmt, NULL);
 }
 else if (strcmp(PushVideoInfo.VideoType, HISTORY_VIDEO) == 0) 
 {
 sprintf(fileName, "%s", VIDEO_FILE_FOLDER);
 sprintf(fileName+strlen(fileName), "%s", PushVideoInfo.VideoFile);
 ret = avformat_open_input(&m_pFmtCtx, fileName, NULL, NULL);
 }
 if (ret < 0)
 {
 printf("avformat open failed!\n");
 goto end; 
 }

 ret = avformat_find_stream_info(m_pFmtCtx, 0);
 if (ret < 0)
 {
 printf("could not find stream info!\n");
 goto end; 
 } 
 for(i = 0; i < m_pFmtCtx->nb_streams; i++)
 {
 if((m_pFmtCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && (vid_idx < 0))
 {
 vid_idx = i;
 }
 }

 AVFormatContext *octx = NULL;

 ret = avformat_alloc_output_context2(&octx, 0, "flv", rtmp_url);
 if (ret < 0)
 {
 printf("avformat alloc output context2 failed!\n");
 goto end;
 } 

 av_init_packet(&pkt); 

 
 for (i = 0;i < m_pFmtCtx->nb_streams; i++)
 {
 AVCodec *codec = avcodec_find_decoder(m_pFmtCtx->streams[i]->codecpar->codec_id);
 AVStream *out = avformat_new_stream(octx, codec);
 ret = avcodec_parameters_copy(out->codecpar, m_pFmtCtx->streams[i]->codecpar);
 out->codecpar->codec_tag = 0;
 }

 ret = avio_open(&octx->pb, rtmp_url, AVIO_FLAG_WRITE);
 if (!octx->pb)
 {
 printf("avio open failed!\n");
 goto end; 
 }

 ret = avformat_write_header(octx, 0);
 if (ret < 0)
 {
 printf("avformat write header failed!\n");
 goto end; 
 }

 start_time = av_gettime();
 AVStream *in_stream, *out_stream;
 AVRational time_base1;
 AVRational time_base;
 AVRational time_base_q;
 int64 calc_duration;
 int64 pts_time;
 int64 now_time;
 
 ChangeAnotherVideo = 0;
 while((!StopPushVideoFlag) && (ChangeAnotherVideo == 0))
 {
 ret = av_read_frame(m_pFmtCtx, &pkt);
 if (ret < 0)
 {
 break;
 }
 if (pkt.pts == AV_NOPTS_VALUE)
 {
 time_base1 = m_pFmtCtx->streams[vid_idx]->time_base;
 calc_duration = (double)AV_TIME_BASE/av_q2d(m_pFmtCtx->streams[vid_idx]->r_frame_rate);
 
 pkt.pts = (double)(frame_index*calc_duration)/(double)(av_q2d(time_base1)*AV_TIME_BASE);
 pkt.dts = pkt.pts;
 pkt.duration = (double)calc_duration/(double)(av_q2d(time_base1)*AV_TIME_BASE);
 }
 if (pkt.stream_index == vid_idx)
 {
 time_base = m_pFmtCtx->streams[vid_idx]->time_base;
 time_base_q = (AVRational){1, AV_TIME_BASE}; 
 pts_time = av_rescale_q(pkt.dts, time_base, time_base_q);
 now_time = av_gettime() - start_time;
 if (pts_time > now_time)
 {
 av_usleep(pts_time - now_time);
 }
 }
 in_stream = m_pFmtCtx->streams[pkt.stream_index];
 out_stream = octx->streams[pkt.stream_index];
 pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, out_stream->time_base, (enum AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
 pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, out_stream->time_base, (enum AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
 pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base, out_stream->time_base);
 pkt.pos = -1;
 if(pkt.stream_index == vid_idx)
 {
 printf("Send %8d video frames to output URL\n",frame_index);
 frame_index++;
 }
 ret = av_interleaved_write_frame(octx, &pkt);
 if (ret < 0)
 {
 goto end;
 }
 av_packet_unref(&pkt);
 }
 
end:
 printf("---------------------------------stop push video -------------------------------------------\n");
 StopPushVideoFlag = NO_STOP_PUSH;
 IsPushingVideoFlag = NO_PUSHING; 
 ChangeAnotherVideo = 0;
 avformat_close_input(&m_pFmtCtx);
 if (octx)
 {
 avio_closep(&octx->pb);
 avformat_free_context(octx);
 }
 /* note: the internal buffer could have changed, and be != avio_ctx_buffer */
 if (m_pIOCtx) 
 {
 av_freep(&m_pIOCtx->buffer);
 av_freep(&m_pIOCtx);
 }

 if (ret < 0) 
 {
 printf("Error occured : %s\n", av_err2str(ret));
 //return 1;
 }
 pthread_exit((void*)"push video end!"); 
 
}


void PushVideo(void)
{
 int ret = 0;
 pthread_t pushVideoThread;

 ret = pthread_create(&pushVideoThread, NULL, PushVideoFunction, NULL);
 if(ret != 0)
 {
 printf("error : push video thread create failed!\n");
 exit(-1);
 }
 else
 {
 printf("(debug) push video thread create success!\n");
 } 
} 



-
Ffmpeg push video is successful, but why is there a mistake at the beginning ?
23 juin 2021, par guoyanzhangI'm a beginner of ffmpeg. Now I use ffmpeg to push video stream to RTMP server, which can push successfully. But at the beginning, there were some errors. I don't know what caused them. This error happens every time. My read_ packet() callback function, the read data is READ_BUF_LEN = 1024 * 12 = 12288 bytes, it seems that it can't find the key frame in 12288 bytes, because READ_BUF_LEN is too small ?


#include "/usr/local/include/libavcodec/avcodec.h"
#include "/usr/local/include/libavformat/avformat.h"
#include "/usr/local/include/libavfilter/avfilter.h"
#include "/usr/local/include/libavutil/mathematics.h"
#include "/usr/local/include/libavutil/time.h"

extern VideoDataStruct *VideoDataListHeader;
extern PushVideoStruct PushVideoInfo;
extern enum IsPushingVideo IsPushingVideoFlag;
extern UCHAR ChangeAnotherVideo;
typedef long long int64;


#define READ_BUF_LEN 1024*12

extern enum IsStopPushVideo StopPushVideoFlag; 

static int read_packet(void *opaque, uint8_t *buf, int buf_size)
{
 int64 dataLen = 0;

 while (dataLen < buf_size)
 {
 if ((VideoDataListHeader != NULL) && (VideoDataListHeader->flag == 1))
 {
 memcpy(&buf[dataLen], VideoDataListHeader->buf, sizeof(VideoDataListHeader->buf));
 dataLen += sizeof(VideoDataListHeader->buf);

 VideoDataListHeader->flag = 0;
 VideoDataListHeader = VideoDataListHeader->next;
 }
 else 
 {
 usleep(10000);
 }
 }
 return buf_size;
}

void *PushVideoFunction(void *arg)
{
 AVFormatContext *m_pFmtCtx = NULL;
 AVPacket pkt; 
 AVIOContext *m_pIOCtx = NULL;
 AVInputFormat *in_fmt = NULL;
 int ret = 0;
 unsigned int i = 0;
 int vid_idx =-1;
 unsigned char *m_pIOBuf = NULL;
 int m_pIOBuf_size = READ_BUF_LEN;
 int64 start_time = 0;
 int frame_index = 0;
 //const char *rtmp_url = "rtmp://192.168.1.108/mytv/01";
 char rtmp_url[140] = {0};
 memset(rtmp_url, 0, sizeof(rtmp_url));
 strcpy(rtmp_url, PushVideoInfo.VideoServer);
 CHAR fileName[64] = {0};

 avformat_network_init(); 
 if (strcmp(PushVideoInfo.VideoType, REAL_VIDEO) == 0) 
 {
 m_pIOBuf = (unsigned char*)av_malloc(m_pIOBuf_size);
 if(m_pIOBuf == NULL)
 {
 printf("av malloc failed!\n");
 goto end;
 }

 
 m_pIOCtx = avio_alloc_context(m_pIOBuf, m_pIOBuf_size, 0, NULL, read_packet, NULL, NULL); 
 if (!m_pIOCtx) 
 {
 printf("avio alloc context failed!\n");
 goto end;
 }

 
 m_pFmtCtx = avformat_alloc_context();
 if (!m_pFmtCtx) 
 {
 printf("avformat alloc context failed!\n");
 goto end;
 }


 //m_pFmtCtx->probesize = BYTES_PER_FRAME * 8;
 m_pFmtCtx->pb = m_pIOCtx; 
 ret = avformat_open_input(&m_pFmtCtx, "", in_fmt, NULL);
 }
 else if (strcmp(PushVideoInfo.VideoType, HISTORY_VIDEO) == 0) 
 {
 sprintf(fileName, "%s", VIDEO_FILE_FOLDER);
 sprintf(fileName+strlen(fileName), "%s", PushVideoInfo.VideoFile);
 ret = avformat_open_input(&m_pFmtCtx, fileName, NULL, NULL);
 }
 if (ret < 0)
 {
 printf("avformat open failed!\n");
 goto end; 
 }

 ret = avformat_find_stream_info(m_pFmtCtx, 0);
 if (ret < 0)
 {
 printf("could not find stream info!\n");
 goto end; 
 } 
 for(i = 0; i < m_pFmtCtx->nb_streams; i++)
 {
 if((m_pFmtCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && (vid_idx < 0))
 {
 vid_idx = i;
 }
 }

 AVFormatContext *octx = NULL;

 ret = avformat_alloc_output_context2(&octx, 0, "flv", rtmp_url);
 if (ret < 0)
 {
 printf("avformat alloc output context2 failed!\n");
 goto end;
 } 

 av_init_packet(&pkt); 

 
 for (i = 0;i < m_pFmtCtx->nb_streams; i++)
 {
 AVCodec *codec = avcodec_find_decoder(m_pFmtCtx->streams[i]->codecpar->codec_id);
 AVStream *out = avformat_new_stream(octx, codec);
 ret = avcodec_parameters_copy(out->codecpar, m_pFmtCtx->streams[i]->codecpar);
 out->codecpar->codec_tag = 0;
 }

 ret = avio_open(&octx->pb, rtmp_url, AVIO_FLAG_WRITE);
 if (!octx->pb)
 {
 printf("avio open failed!\n");
 goto end; 
 }

 ret = avformat_write_header(octx, 0);
 if (ret < 0)
 {
 printf("avformat write header failed!\n");
 goto end; 
 }

 start_time = av_gettime();
 AVStream *in_stream, *out_stream;
 AVRational time_base1;
 AVRational time_base;
 AVRational time_base_q;
 int64 calc_duration;
 int64 pts_time;
 int64 now_time;
 
 ChangeAnotherVideo = 0;
 while((!StopPushVideoFlag) && (ChangeAnotherVideo == 0))
 {
 ret = av_read_frame(m_pFmtCtx, &pkt);
 if (ret < 0)
 {
 break;
 }
 if (pkt.pts == AV_NOPTS_VALUE)
 {
 time_base1 = m_pFmtCtx->streams[vid_idx]->time_base;
 calc_duration = (double)AV_TIME_BASE/av_q2d(m_pFmtCtx->streams[vid_idx]->r_frame_rate);
 
 pkt.pts = (double)(frame_index*calc_duration)/(double)(av_q2d(time_base1)*AV_TIME_BASE);
 pkt.dts = pkt.pts;
 pkt.duration = (double)calc_duration/(double)(av_q2d(time_base1)*AV_TIME_BASE);
 }
 if (pkt.stream_index == vid_idx)
 {
 time_base = m_pFmtCtx->streams[vid_idx]->time_base;
 time_base_q = (AVRational){1, AV_TIME_BASE}; 
 pts_time = av_rescale_q(pkt.dts, time_base, time_base_q);
 now_time = av_gettime() - start_time;
 if (pts_time > now_time)
 {
 av_usleep(pts_time - now_time);
 }
 }
 in_stream = m_pFmtCtx->streams[pkt.stream_index];
 out_stream = octx->streams[pkt.stream_index];
 pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, out_stream->time_base, (enum AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
 pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, out_stream->time_base, (enum AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
 pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base, out_stream->time_base);
 pkt.pos = -1;
 if(pkt.stream_index == vid_idx)
 {
 printf("Send %8d video frames to output URL\n",frame_index);
 frame_index++;
 }
 ret = av_interleaved_write_frame(octx, &pkt);
 if (ret < 0)
 {
 goto end;
 }
 av_packet_unref(&pkt);
 }
 
end:
 printf("---------------------------------stop push video -------------------------------------------\n");
 StopPushVideoFlag = NO_STOP_PUSH;
 IsPushingVideoFlag = NO_PUSHING; 
 ChangeAnotherVideo = 0;
 avformat_close_input(&m_pFmtCtx);
 if (octx)
 {
 avio_closep(&octx->pb);
 avformat_free_context(octx);
 }
 /* note: the internal buffer could have changed, and be != avio_ctx_buffer */
 if (m_pIOCtx) 
 {
 av_freep(&m_pIOCtx->buffer);
 av_freep(&m_pIOCtx);
 }

 if (ret < 0) 
 {
 printf("Error occured : %s\n", av_err2str(ret));
 //return 1;
 }
 pthread_exit((void*)"push video end!"); 
 
}


void PushVideo(void)
{
 int ret = 0;
 pthread_t pushVideoThread;

 ret = pthread_create(&pushVideoThread, NULL, PushVideoFunction, NULL);
 if(ret != 0)
 {
 printf("error : push video thread create failed!\n");
 exit(-1);
 }
 else
 {
 printf("(debug) push video thread create success!\n");
 } 
} 



push error :


[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] decode_slice_header error
[h264 @ 0xffff54001480] no frame!
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] decode_slice_header error
[h264 @ 0xffff54001480] no frame!
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] decode_slice_header error
[h264 @ 0xffff54001480] no frame!
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] decode_slice_header error
[h264 @ 0xffff54001480] no frame!
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] decode_slice_header error
[h264 @ 0xffff54001480] no frame!
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] decode_slice_header error
[h264 @ 0xffff54001480] no frame!
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] decode_slice_header error
[h264 @ 0xffff54001480] no frame!
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] decode_slice_header error
[h264 @ 0xffff54001480] no frame!
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] non-existing PPS 0 referenced
[h264 @ 0xffff54001480] decode_slice_header error
[h264 @ 0xffff54001480] corrupted macroblock 11 13 (total_coeff=-1)
[h264 @ 0xffff54001480] error while decoding MB 11 13
[h264 @ 0xffff54001480] concealing 78 DC, 78 AC, 78 MV errors in I frame
[h264 @ 0xffff54001480] mb_type 84 in P slice too large at 16 6
[h264 @ 0xffff54001480] error while decoding MB 16 6
[h264 @ 0xffff54001480] concealing 213 DC, 213 AC, 213 MV errors in P frame