作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对如何将视频流保存到 mp4 文件感到很困惑。我正在使用 ffmpeg。让我解释一下问题:
// Prepare the output
AVFormatContext* oc = avformat_alloc_context();
oc->oformat = av_guess_format(NULL, "video.mp4", NULL);
// Must write header, packets, and trailing
avio_open2(&oc->pb, "video.mp4", AVIO_FLAG_WRITE, NULL, NULL);
// Write header
AVStream* stream = avformat_new_stream(oc, (AVCodec*) context->streams[video_stream_index]->codec->codec);
avcodec_copy_context(stream->codec, context->streams[video_stream_index]->codec);
stream->sample_aspect_ratio = context->streams[video_stream_index]->codec->sample_aspect_ratio;
avformat_write_header(oc, NULL);
// FOR EACH FRAME...
... av_write_frame(oc, circular[k]); ...
// Write trailer and close the file
av_write_trailer(oc);
avcodec_close(stream->codec);
avio_close(oc->pb);
avformat_free_context(oc);
最佳答案
第一:当您使用相机时,最好通过 RTP over TCP(TCP 作为传输协议(protocol))工作。
要启用此功能:
AVDictionary *ifmtdict;
av_dict_set(&ifmtdict, "rtsp_transport", "tcp", 0);
...
avformat_open_input (..., &ifmtdict);
关于c++ - 将来自网络摄像机 (RTSP) 的帧保存到 mp4 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20522950/
我是一名优秀的程序员,十分优秀!