流式视频(C#使用FFmpeg AutoGen)发送多个数据请求 [英] Streaming video (C# using FFmpeg AutoGen) sends multiple data requests

查看:3586
本文介绍了流式视频(C#使用FFmpeg AutoGen)发送多个数据请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个以h264格式(mp4)格式保存视频的视频发生器。当我从我的天蓝色服务流式传输视频时,我看到以下网络流量:

I've written a video generator that rights a video in h264 format (mp4). When I stream the video from my azure service, i'm seeing the following network traffic:

我使用的AVCodecContext布局如下:

The AVCodecContext layout I'm using is as follows:

AVCodec* videoCodec = ffmpeg.avcodec_find_encoder(AVCodecID.AV_CODEC_ID_H264)
AVCodecContext* videoCodecContext = ffmpeg.avcodec_alloc_context3(videoCodec);
videoCodecContext->bit_rate = 400000;
videoCodecContext->width = 1280;
videoCodecContext->height = 720;
videoCodecContext->gop_size = 12;
videoCodecContext->max_b_frames = 1;
videoCodecContext->pix_fmt = videoCodec->pix_fmts[0];
videoCodecContext->codec_id = videoCodec->id;
videoCodecContext->codec_type = videoCodec->type;
videoCodecContext->time_base = new AVRational
{
    num = 1,
    den = 30
};

ffmpeg.av_opt_set(videoCodecContext->priv_data, "preset", "ultrafast");

我也尝试通过AVDictionary为avformat_write_header()设置movflags选项,但是av_write_trailer()返回-2,导致文件没有完成写入。

I'm also tried setting the "movflags" option for avformat_write_header() via an AVDictionary, but then av_write_trailer() returns -2, cause the file to not finish writing.

我不知道如何解决这个问题。使用Windows Movie Maker流完美生成的视频。

I cannot figure out how to solve this problem. Videos generating using Windows Movie Maker stream perfectly.

我知道这与mdat和mov位置有关。

I know this has something to do with mdat and mov positions.

此外,这似乎只发生在Google Chrome中。

Also, this appears to only happening in Google Chrome.

推荐答案

好的,想出来了。我以前一直在写视频帧和音频帧。相反,您必须并排编写它们,以便快速启动实际工作并允许视频流。

OK, figured this out. I've been writing the video frames first and the audio frames afterwards. Instead, you have to write them side by side in order for faststart to actually work and allow the video to stream.

所以,写一个特定数量的音频,然后确定如果视频帧应该通过检查当前写入索引的时间段来写入。

So, write a specific amount of audio and then determine if a video frame should be written by checking the timebases against the current writing indexes.

这个示例将向您展示如何完成。

This example will show you how its done.

此外,要获取视频和音频流具有准确的PTS / DTS值,请查看问题。

Also, to get the video and audio streams to have accurate PTS/DTS values, look at this question.

这篇关于流式视频(C#使用FFmpeg AutoGen)发送多个数据请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆