Tag: libavformat

无法将libavformat / ffmpeg与x264和RTP同步

我一直在研究一些流媒体软件,它使用H.264通过网络从各种摄像机和流中获取实时信息。 为了实现这一点,我直接使用x264编码器(带有“zerolatency”预设)并提供NAL,因为它们可用于libavformat以打包到RTP(最终是RTSP)。 理想情况下,此应用程序应尽可能实时。 在大多数情况下,这一直运作良好。 不幸的是,存在某种同步问题:客户端上的任何video播放似乎都显示了一些平滑的帧,然后是短暂的暂停,然后是更多的帧; 重复。 此外,似乎有大约4秒的延迟。 我尝试过的每一个video播放器都会出现这种情况:Totem,VLC和基本的gstreamer管道。 我把它煮成了一个小小的测试用例: #include #include #include #include #include #include #define WIDTH 640 #define HEIGHT 480 #define FPS 30 #define BITRATE 400000 #define RTP_ADDRESS “127.0.0.1” #define RTP_PORT 49990 struct AVFormatContext* avctx; struct x264_t* encoder; struct SwsContext* imgctx; uint8_t test = 0x80; void create_sample_picture(x264_picture_t* picture) { // create a frame to […]

FFMpeg复制流没有转码

我试图将所有来自多个文件的流复制到一个文件而不转码流。 你通常使用ffmpeg实用程序做的事情ffmpeg -i “file_with_audio.mp4” -i “file_with_video.mp4” -c copy -shortest file_with_audio_and_video.mp4 这是代码: int ffmpegOpenInputFile(const char* filename, AVFormatContext **ic) { int ret; unsigned int i; *ic = avformat_alloc_context(); if (!(*ic)) return -1; // Couldn’t allocate input context if((ret = avformat_open_input(ic, filename, NULL, NULL)) < 0) return ret; // Couldn't open file // Get format info (retrieve stream […]

使用libavformat读取位于内存中的文件

我目前正在尝试阅读从服务器发送的小型video文件 为了使用libavformat读取文件,您应该调用 av_open_input_file(&avFormatContext, “C:\\path\\to\\video.avi”, 0, 0, 0); 问题是在这种情况下,文件不在磁盘上,而是在内存中。 我现在正在做的是下载文件,使用临时名称将其写入磁盘,然后使用临时文件名调用av_open_input_file ,这不是一个非常干净的解决方案。 事实上,我想要的是像av_open_custom(&avFormatContext, &myReadFunction, &mySeekFunction);这样的函数av_open_custom(&avFormatContext, &myReadFunction, &mySeekFunction); 但我没有在文档中找到任何内容。 我想这在技术上是可行的,因为文件的名称不能帮助库确定它使用的格式。 那么有这样的函数,还是av_open_input_file的替代品?

使用FFmpeg libavformat记录RTSP流

我正试图用FFmpeg libavformat记录来自Axis相机的RTSP流。 我可以从文件中获取video,然后将其保存到另一个文件,这没关系。 但是摄像机发送奇怪的数据,FPS为100,摄像机每隔4帧发送一次,因此结果FPS约为25.但是libavformat设置数据包dts / pts为90000 fps(默认值?),新文件流有100fps。 结果是一小时video,只有100帧。 这是我的代码 #include #include #include #include #include int main(int argc, char** argv) { AVFormatContext* context = avformat_alloc_context(); int video_stream_index; av_register_all(); avcodec_register_all(); avformat_network_init(); //open rtsp if(avformat_open_input(&context, “rtsp://195.200.199.8/mpeg4/media.amp”,NULL,NULL) != 0){ return EXIT_FAILURE; } if(avformat_find_stream_info(context,NULL) < 0){ return EXIT_FAILURE; } //search video stream for(int i =0;inb_streams;i++){ if(context->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) video_stream_index = […]