mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-04-14 00:58:38 +02:00
lavf/dashenc: update bitrates on dash_write_trailer
Provides a way to change bandwidth parameter inside DASH manifest after a non-CBR H.264 encoding. Caller now is able to compute the bitrate by itself, after all packets have been written, and then set that value in AVFormatContext->streams->codecpar->bit_rate before calling av_write_trailer. As a result that value will be set in DASH manifest. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
parent
70a9407b50
commit
89c0fda5f4
@ -561,6 +561,30 @@ static int write_manifest(AVFormatContext *s, int final)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int set_bitrate(AVFormatContext *s)
|
||||||
|
{
|
||||||
|
DASHContext *c = s->priv_data;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < s->nb_streams; i++) {
|
||||||
|
OutputStream *os = &c->streams[i];
|
||||||
|
|
||||||
|
os->bit_rate = s->streams[i]->codecpar->bit_rate;
|
||||||
|
if (os->bit_rate) {
|
||||||
|
snprintf(os->bandwidth_str, sizeof(os->bandwidth_str),
|
||||||
|
" bandwidth=\"%d\"", os->bit_rate);
|
||||||
|
} else {
|
||||||
|
int level = s->strict_std_compliance >= FF_COMPLIANCE_STRICT ?
|
||||||
|
AV_LOG_ERROR : AV_LOG_WARNING;
|
||||||
|
av_log(s, level, "No bit rate set for stream %d\n", i);
|
||||||
|
if (s->strict_std_compliance >= FF_COMPLIANCE_STRICT)
|
||||||
|
return AVERROR(EINVAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int dash_init(AVFormatContext *s)
|
static int dash_init(AVFormatContext *s)
|
||||||
{
|
{
|
||||||
DASHContext *c = s->priv_data;
|
DASHContext *c = s->priv_data;
|
||||||
@ -597,6 +621,10 @@ static int dash_init(AVFormatContext *s)
|
|||||||
if (!c->streams)
|
if (!c->streams)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
|
ret = set_bitrate(s);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
for (i = 0; i < s->nb_streams; i++) {
|
for (i = 0; i < s->nb_streams; i++) {
|
||||||
OutputStream *os = &c->streams[i];
|
OutputStream *os = &c->streams[i];
|
||||||
AVFormatContext *ctx;
|
AVFormatContext *ctx;
|
||||||
@ -604,18 +632,6 @@ static int dash_init(AVFormatContext *s)
|
|||||||
AVDictionary *opts = NULL;
|
AVDictionary *opts = NULL;
|
||||||
char filename[1024];
|
char filename[1024];
|
||||||
|
|
||||||
os->bit_rate = s->streams[i]->codecpar->bit_rate;
|
|
||||||
if (os->bit_rate) {
|
|
||||||
snprintf(os->bandwidth_str, sizeof(os->bandwidth_str),
|
|
||||||
" bandwidth=\"%d\"", os->bit_rate);
|
|
||||||
} else {
|
|
||||||
int level = s->strict_std_compliance >= FF_COMPLIANCE_STRICT ?
|
|
||||||
AV_LOG_ERROR : AV_LOG_WARNING;
|
|
||||||
av_log(s, level, "No bit rate set for stream %d\n", i);
|
|
||||||
if (s->strict_std_compliance >= FF_COMPLIANCE_STRICT)
|
|
||||||
return AVERROR(EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = avformat_alloc_context();
|
ctx = avformat_alloc_context();
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
@ -981,6 +997,8 @@ static int dash_write_trailer(AVFormatContext *s)
|
|||||||
{
|
{
|
||||||
DASHContext *c = s->priv_data;
|
DASHContext *c = s->priv_data;
|
||||||
|
|
||||||
|
set_bitrate(s);
|
||||||
|
|
||||||
if (s->nb_streams > 0) {
|
if (s->nb_streams > 0) {
|
||||||
OutputStream *os = &c->streams[0];
|
OutputStream *os = &c->streams[0];
|
||||||
// If no segments have been written so far, try to do a crude
|
// If no segments have been written so far, try to do a crude
|
||||||
|
Loading…
x
Reference in New Issue
Block a user