Commit Graph

170 Commits

Author SHA1 Message Date
Anton Khirnov
5cf81bed88 fftools/ffmpeg: eliminate the main_return_code global
Properly pass muxing return codes through the call stack instead.
Slightly changes behavior in case of errors:
* the output IO stream is closed even if writing the trailer returns an
  error, which should be more correct
* all files get properly closed with -xerror, even if one of them fails
2023-04-13 15:11:56 +02:00
Anton Khirnov
fd91ac11ed fftools/ffmpeg: move OutputStream.last_filter_pts to OutputFilter
This value is associated with the filtergraph output rather than the
output stream, so this is a more appropriate place for it.
2023-04-13 15:11:56 +02:00
Anton Khirnov
83da6d3f54 fftools/ffmpeg: move OutputStream.last_nb0_frames to Encoder
It is video encoding-only and does not need to be visible outside of
ffmpeg_enc.c

Also, rename the variable to frames_prev_hist to be consistent with
the naming in do_video_out().
2023-04-13 15:11:56 +02:00
Anton Khirnov
87ae84e4af fftools/ffmpeg: move OutputStream.sq_frame to Encoder
It is audio/video encoding-only and does not need to be visible outside
of ffmpeg_enc.c
2023-04-13 15:11:56 +02:00
Anton Khirnov
710da200fc fftools/ffmpeg: move OutputStream.next_pts to Encoder
It is audio/video encoding-only and does not need to be visible outside
of ffmpeg_enc.c
2023-04-13 15:11:56 +02:00
Anton Khirnov
45202556cb fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder
It is video encoding-only and does not need to be visible outside of
ffmpeg_enc.c
2023-04-13 15:11:56 +02:00
Anton Khirnov
f30b620e98 fftools/ffmpeg: add encoder private data
Start by moving OutputStream.last_frame to it. In the future it will
hold other encoder-internal state.
2023-04-09 15:47:45 +02:00
Anton Khirnov
44accfef41 fftools/ffmpeg: move audio/video encoding code to ffmpeg_enc.c 2023-04-09 15:47:45 +02:00
Anton Khirnov
9de5dc74fd fftools/ffmpeg: move subtitle encoding to ffmpeg_enc.c 2023-04-09 15:47:45 +02:00
Anton Khirnov
d96f2fbf76 fftools/ffmpeg: move initializing encoders to a new file
This file will contain more encoding-related code in the future.
2023-04-09 15:47:45 +02:00
Anton Khirnov
8e23a62eff fftools/ffmpeg: drop InputStream.processing_needed
It is equivalent to !InputStream.discard.
2023-04-09 15:47:45 +02:00
Anton Khirnov
3f63685c35 fftools/ffmpeg: supply hw_device_ctx to filters before initializing them
This is more correct, but was not possible before the recently-added
filtergraph parsing API.

Also, only pass hw devices to filters that are flagged as capable of
using them.

Tested-by: Niklas Haas
2023-03-24 10:23:52 +01:00
Anton Khirnov
156ca86569 fftools/ffmpeg: move ts_scale to DemuxStream
It is not needed outside of ffmpeg_demux.
2023-02-20 19:22:22 +01:00
Anton Khirnov
66c1e956aa fftools/ffmpeg_demux: add an AVClass to DemuxStream/InputStream
Use it for logging. This makes log messages related to this input stream
more consistent.
2023-02-20 19:22:22 +01:00
Anton Khirnov
d9079f6700 fftools/ffmpeg_demux: move InputStream.guess_layout_max to stack
It is only needed while processing the stream in add_input_streams(), no
reason to store it in the context.
2023-02-20 19:22:22 +01:00
Anton Khirnov
8a7554a574 fftools/ffmpeg_demux: add InputStream private data
Move {min,max}_pts to it, which is not used outside of ffmpeg_demux.
2023-02-20 19:22:22 +01:00
Anton Khirnov
cd4cd95d5e fftools/ffmpeg_demux: add an AVClass to Demuxer/InputFile
Use it for logging. This makes log messages related to this input file
more consistent.
2023-02-20 19:22:22 +01:00
Anton Khirnov
42a0dd6e7e fftools/ffmpeg: add an option for writing pre-muxing stats
Analogous to -enc_stats*, but happens right before muxing. Useful
because bitstream filters and the sync queue can modify packets after
encoding and before muxing. Also has access to the muxing timebase.
2023-02-09 15:24:15 +01:00
Jan Ekström
9a820ec8b1 ffmpeg: add video heartbeat capability to fix_sub_duration
Splits the currently handled subtitle at random access point
packets that can be configured to follow a specific output stream.
Currently only subtitle streams which are directly mapped into the
same output in which the heartbeat stream resides are affected.

This way the subtitle - which is known to be shown at this time
can be split and passed to muxer before its full duration is
yet known. This is also a drawback, as this essentially outputs
multiple subtitles from a single input subtitle that continues
over multiple random access points. Thus this feature should not
be utilized in cases where subtitle output latency does not matter.

Co-authored-by: Andrzej Nadachowski <andrzej.nadachowski@24i.com>
Co-authored-by: Bernard Boulay <bernard.boulay@24i.com>

Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
2023-02-03 16:17:29 +02:00
Anton Khirnov
806ecace91 fftools/ffmpeg: support input frame params in encoding stats 2023-01-31 09:09:23 +01:00
Anton Khirnov
9b5036fabd fftools/ffmpeg: add an AVClass to MuxStream/OutputStream
Use it for logging. This makes log messages related to this output
stream more consistent.
2023-01-29 09:12:22 +01:00
Anton Khirnov
d2c983c213 fftools/ffmpeg: add an AVClass to Muxer/OutputFile
Use it for logging. This makes log messages related to this output file
more consistent.
2023-01-29 09:10:57 +01:00
Anton Khirnov
425b2c4a56 fftools/ffmpeg: add options for writing encoding stats
Similar to -vstats, but more flexible:
- works for audio as well as video
- frame and/or packet information
- user-specifiable format
2023-01-29 09:09:59 +01:00
Anton Khirnov
2fa2e146cc fftools/ffmpeg: avoid storing full forced keyframe spec
It is not needed after the spec is parsed. Also avoids ugly string
comparisons for each video frame.
2022-11-28 10:28:14 +01:00
Anton Khirnov
334e52e094 fftools/ffmpeg: parse forced keyframes in of_open()
Allows to remove the ugly of_get_chapters() wrapper.
2022-11-28 10:28:14 +01:00
Anton Khirnov
efe4423627 fftools/ffmpeg: store forced keyframe pts in AV_TIME_BASE_Q
Rather than the encoder timebase. Since the times are parsed as
microseconds, this will not reduce precision, except possibly when
chapter times are used and the chapter timebase happens to be better
aligned with the encoder timebase, which is unlikely.

This will allow parsing the keyframe times earlier (before encoder
timebase is known) in future commits.
2022-11-28 10:28:14 +01:00
Anton Khirnov
b1143330c8 fftools/ffmpeg: move force-keyframe-related vars to a separate struct
There are 8 of them and they are typically used together. Allows to pass
just this struct to forced_kf_apply(), which makes it clear that the
rest of the OutputStream is not accessed there.
2022-11-28 10:28:14 +01:00
Anton Khirnov
95af0bcc34 fftools/ffmpeg_mux_init: postpone matching -disposition to streams
Do it in set_dispositions() rather than during stream creation.

Since at this point all other stream information is known, this allows
setting disposition based on metadata, which implements #10015. This
also avoids an extra allocated string in OutputStream that was unused
after of_open().
2022-11-23 10:36:23 +01:00
Anton Khirnov
3da5c60aa9 fftools/ffmpeg: _-prefix variables in MATCH_PER_STREAM_OPT()
Avoids conflicts, e.g. when 'i' is used in the outvar expression.
2022-11-23 10:36:23 +01:00
Anton Khirnov
fd8bf8d3b5 fftools/ffmpeg: remove the input_streams global
Replace it with an array of streams in each InputFile. This is a more
accurate reflection of the actual relationship between InputStream and
InputFile.

Analogous to what was previously done to output streams in
7ef7a22251.
2022-11-23 10:36:23 +01:00
Anton Khirnov
4c40581614 fftools/ffmpeg: replace OutputStream.source_index with a pointer to InputStream
This is simpler. The indirection via an index exists for historical
reasons that longer apply.
2022-11-23 10:36:23 +01:00
Anton Khirnov
b58264217b fftools/ffmpeg_mux_init: drop an always-false check
It cannot be true since 1959351aec. Effectively reverts 6a3833e141.
2022-11-17 10:52:58 +01:00
Anton Khirnov
52380a055b fftools/ffmpeg_mux_init: move validating codec avoptions to a separate function 2022-11-17 10:52:58 +01:00
Anton Khirnov
0fb7d111e8 fftools/ffmpeg: move OutputStream.max_frames to MuxStream
It no longer needs to be visible outside of the muxing code.
2022-11-17 10:52:58 +01:00
Anton Khirnov
c15eb2773a fftools/ffmpeg_[de]mux: constify all uses of OptionsContext 2022-11-16 08:41:14 +01:00
Anton Khirnov
4119480681 fftools/ffmpeg_mux_init: stop using OptionsContext as storage in copy_metadata()
It should be input-only to this code. Will allow making it const in
future commits.
2022-11-16 08:41:14 +01:00
Gyan Doshi
5ccd4d3060 ffmpeg: fix implementation of updated input start time
The current adjustment of input start times just adjusts the tsoffset.
And it does so, by resetting the tsoffset to nullify the new start time.
This leads to breakage of -copyts, ignoring of input_ts_offset, breaking
of -isync as well as breaking wrap correction.

Fixed by taking cognizance of these parameters, and by correcting start times
just before sync offsets are applied.
2022-11-03 14:38:42 +05:30
Anton Khirnov
5c1a096d02 fftools/ffmpeg: move nb_streams_warn from InputFile to Demuxer
It is private to the demuxer and do not need to be visible outside of
it.
2022-10-25 11:04:42 +02:00
Anton Khirnov
541104f3a3 fftools/ffmpeg: move duration/time_base from InputFile to Demuxer
They are private to the demuxer and do not need to be visible outside of
it.
2022-10-25 11:04:42 +02:00
Anton Khirnov
5bc1f177d3 fftools/ffmpeg: move threading fields from InputFile to Demuxer
They are private to the demuxer and do not need to be visible outside of
it.
2022-10-25 11:04:42 +02:00
Anton Khirnov
c20977c4e0 fftools/ffmpeg: drop free_input_threads()
Stop demuxer threads in ifile_close() instead. Simplifies the demuxer
API.
2022-10-25 11:04:42 +02:00
Anton Khirnov
295848bacb fftools/ffmpeg: move closing the input file into a separate function
For now this is just closing the format context and freeing InputFile,
but will contain more in the future.
2022-10-25 11:04:42 +02:00
Anton Khirnov
09cd147dcc fftools/ffmpeg: drop init_input_threads()
Start threads implicitly when ifile_get_packet() is called. Simplifies
the demuxer API.
2022-10-25 11:04:42 +02:00
Anton Khirnov
6975320506 fftools/ffmpeg_demux: add demuxer private data
Move InputFile.loop into it.
2022-10-25 11:04:42 +02:00
Anton Khirnov
78efefa9a5 fftools/ffmpeg_opt: move opening input files to ffmpeg_demux.c
This is similar to what was done before for output files and will allow
introducing demuxer-private state in future commits

Unlike for muxing, the code is moved to existing ffmpeg_demux.c rather
than to a new file. The reason is just file size - the demuxing code is
much smaller than muxing.
2022-10-25 11:04:42 +02:00
Anton Khirnov
4cfffdd551 fftools/ffmpeg: rename read_file() to avoid conflict with libass
libass defines a non-static read_file() symbol, which causes conflicts
with static linking.
2022-10-21 10:13:16 +02:00
Jan Ekström
b9058765d7 ffmpeg: Deprecate display rotation override with a metadata key
Now that we have proper options for defining display matrix
overrides, this should no longer be required.

fftools does not have its own versioning, so for now the define is
just set to 1 and disables the functionality if set to zero.
2022-10-19 11:53:52 +02:00
Jan Ekström
c889248647 ffmpeg: Add display_{rotation, hflip, vflip} options
This enables overriding the rotation as well as horizontal/vertical
flip state of a specific video stream on the input side.

Additionally, switch the singular test that was utilizing the rotation
metadata to instead override the input display rotation, thus leading
to the same result.
2022-10-19 11:53:52 +02:00
Andreas Rheinhardt
ff2c37d449 fftools/ffmpeg_opt: Move stuff only used by ffmpeg_mux_init to it
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-10-18 14:19:11 +02:00
Anton Khirnov
c5d7b6f49b fftools/ffmpeg_mux: move muxing queue fields from OutputStream to MuxStream
They are private to the muxer and do not need to be visible outside of
it.
2022-10-18 14:19:11 +02:00