mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-12-20 14:00:13 +01:00
fftools/ffmpeg_enc: do not set AVStream timebase directly
Instead, pass the encoder context to of_stream_init() and have the muxer take the timebase from there. Note that the muxer can currently access the codec context directly, but that will change in future commits. This is a step towards decoupling encoders from muxers.
This commit is contained in:
@@ -871,7 +871,8 @@ int enc_loopback(Encoder *enc);
|
|||||||
*
|
*
|
||||||
* Open the muxer once all the streams have been initialized.
|
* Open the muxer once all the streams have been initialized.
|
||||||
*/
|
*/
|
||||||
int of_stream_init(OutputFile *of, OutputStream *ost);
|
int of_stream_init(OutputFile *of, OutputStream *ost,
|
||||||
|
const AVCodecContext *enc_ctx);
|
||||||
int of_write_trailer(OutputFile *of);
|
int of_write_trailer(OutputFile *of);
|
||||||
int of_open(const OptionsContext *o, const char *filename, Scheduler *sch);
|
int of_open(const OptionsContext *o, const char *filename, Scheduler *sch);
|
||||||
void of_free(OutputFile **pof);
|
void of_free(OutputFile **pof);
|
||||||
|
|||||||
@@ -367,11 +367,7 @@ int enc_open(void *opaque, const AVFrame *frame)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy timebase while removing common factors
|
ret = of_stream_init(of, ost, enc_ctx);
|
||||||
if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0)
|
|
||||||
ost->st->time_base = av_add_q(ost->enc_ctx->time_base, (AVRational){0, 1});
|
|
||||||
|
|
||||||
ret = of_stream_init(of, ost);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|||||||
@@ -608,12 +608,19 @@ static int bsf_init(MuxStream *ms)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int of_stream_init(OutputFile *of, OutputStream *ost)
|
int of_stream_init(OutputFile *of, OutputStream *ost,
|
||||||
|
const AVCodecContext *enc_ctx)
|
||||||
{
|
{
|
||||||
Muxer *mux = mux_from_of(of);
|
Muxer *mux = mux_from_of(of);
|
||||||
MuxStream *ms = ms_from_ost(ost);
|
MuxStream *ms = ms_from_ost(ost);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (enc_ctx) {
|
||||||
|
// use upstream time base unless it has been overridden previously
|
||||||
|
if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0)
|
||||||
|
ost->st->time_base = av_add_q(enc_ctx->time_base, (AVRational){0, 1});
|
||||||
|
}
|
||||||
|
|
||||||
/* initialize bitstream filters for the output stream
|
/* initialize bitstream filters for the output stream
|
||||||
* needs to be done here, because the codec id for streamcopy is not
|
* needs to be done here, because the codec id for streamcopy is not
|
||||||
* known until now */
|
* known until now */
|
||||||
|
|||||||
@@ -3385,7 +3385,7 @@ int of_open(const OptionsContext *o, const char *filename, Scheduler *sch)
|
|||||||
OutputStream *ost = of->streams[i];
|
OutputStream *ost = of->streams[i];
|
||||||
|
|
||||||
if (!ost->enc) {
|
if (!ost->enc) {
|
||||||
err = of_stream_init(of, ost);
|
err = of_stream_init(of, ost, NULL);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user