Commit Graph

459 Commits

Author SHA1 Message Date
Anton Khirnov d064c9ded5 fftools/ffmpeg: deobfuscate check_decode_result() call
Passing ist=NULL is currently used to identify stream types that do not
decode into AVFrames, i.e. subtitles. That is highly non-obvious -
always pass a non-NULL InputStream and just check the type explicitly.
2023-05-22 17:10:44 +02:00
Anton Khirnov 4fbc699ac3 fftools/ffmpeg: replace an unreachable return with av_assert0(0)
This cannot be reached, because initialization will fail if decoding is
requested for a stream but no decoder can be found.
2023-05-22 17:10:44 +02:00
Anton Khirnov 4a59dde0c7 fftools/ffmpeg: eliminate InputStream.got_output
It tracks whether the decoder for this stream ever produced any frames
and its only use is for checking whether a filter input ever received a
frame - those that did not are prioritized by the scheduler.

This is awkward and unnecessarily complicated - checking whether the
filtergraph input format is valid works just as well and does not
require maintaining an extra variable.
2023-05-22 17:10:44 +02:00
Anton Khirnov 5fa00b38e6 fftools/ffmpeg: drop an obsolete hack
This special handling for decoder flushing has not been needed since
af1761f7b5, as the filtergraph actually is drained after that commit.
2023-05-22 17:10:44 +02:00
Anton Khirnov 82c75ddfad fftools/ffmpeg: move ifilter_has_all_input_formats() to ffmpeg_filter
That is a more appropriate place for that function.
2023-05-22 17:10:44 +02:00
Anton Khirnov 30a3fee24f fftools/ffmpeg: rework applying input -r
Do not use a separate counter for CFR timestamps forced with -r used as
an input option. Set durations properly and let estimation code do the
rest.
2023-05-22 17:10:44 +02:00
Anton Khirnov 7b41785eb6 fftools/ffmpeg: replace stream timebase with decoded frame one
They are the same for now, but this may change in the future.
2023-05-22 17:10:44 +02:00
Anton Khirnov 1372e81aaa fftools/ffmpeg: drop a useless local variable
Store decoded frame timestamp directly in AVFrame.pts, there is no
advantage to using a separate local variable for it.
2023-05-22 17:10:44 +02:00
Anton Khirnov 94a9647195 fftools/ffmpeg: shorten a variable name
There is only one frame used in decode_video() -- the one output by the
decoder. So there is no point in explicitly calling it the _decoded_
frame.
2023-05-22 17:10:44 +02:00
Anton Khirnov 7be945a011 fftools/ffmpeg: rename transcode_init()
It does no initialization anymore, except for setting
transcode_init_done - the bulk of the function is printing the
input/output maps. It also cannot fail anymore, so remove the useless
return value.
2023-05-15 13:32:02 +02:00
Anton Khirnov ab223a4d8c fftools/ffmpeg: stop accessing input format from decoding code
Export the corresponding flag in InputFile instead. This will allow
making the demuxer AVFormatContext private in future commits, similarly
to what was previously done for muxers.
2023-05-15 13:32:02 +02:00
Anton Khirnov 2ab9f247f7 fftools/ffmpeg: log corrupt-frame errors to the appropriate context 2023-05-15 13:32:02 +02:00
Anton Khirnov a1002bc39c fftools/ffmpeg: replace print_error() by more meaningful messages 2023-05-15 13:32:01 +02:00
Anton Khirnov 9429624a76 fftools/ffmpeg: move discarding unused programs to ffmpeg_demux
This is a more appropriate place for this code.
2023-05-15 13:32:01 +02:00
Anton Khirnov f9657b7443 fftools/ffmpeg: simplify tracking -readrate start time
There is no point in having a per-stream wallclock start time, since
they are all computed at the same instant. Keep a per-file start time
instead, initialized when the demuxer thread starts.
2023-05-15 13:32:01 +02:00
Anton Khirnov 6fcfe4307c fftools/ffmpeg: drop unused decode_video() parameter 2023-05-15 13:32:01 +02:00
Anton Khirnov 2b99c6bfd5 fftools/ffmpeg: move post-demux packet processing to ffmpeg_demux
That is a more appropriate place for this code and will allow hiding
more of InputStream.

The value of repeat_pict extracted from libavformat internal parser no
longer needs to be trasmitted outside of the demuxing thread.

Move readrate handling to the demuxer thread. This has to be done in the
same commit, since it reads InputStream.dts,nb_packets, which are now
set in the demuxer thread.
2023-05-15 11:03:15 +02:00
Anton Khirnov 09c686788e fftools/ffmpeg: attach InputStream.dts to demuxed packets when needed
This way computing it and using it for streamcopy does not need to
happen in sync. Will be useful in following commits, where updating
InputStream.dts will be moved to the demuxing thread.
2023-05-15 10:57:19 +02:00
Anton Khirnov 989e87b03c fftools/ffmpeg: stop using decoder properties in ist_dts_update()
This code runs post-demuxing and is not synchronized with the decoder
output (which may be delayed with respect to its input by arbitrary and
unknowable amounts), so accessing any decoder properties is incorrect.
2023-05-15 10:57:19 +02:00
Anton Khirnov 0d25b404d4 fftools/ffmpeg: reindent after previous commit 2023-05-15 10:57:19 +02:00
Anton Khirnov 702ff2d281 fftools/ffmpeg: consolidate InputStream.[next_]dts updates
Move them to a separate function called right after timestamp
discontinuity processing. This is now possible, since these values have
no interaction with decoding anymore.
2023-05-15 10:57:19 +02:00
Anton Khirnov a238ba9c3c fftools/ffmpeg: stop using deprecated ticks_per_frame 2023-05-15 10:56:48 +02:00
Anton Khirnov 78e84c054a fftools/ffmpeg: fix computing video frame duration from repeat_pict
This field contains the number of _field_ durations by which the
standard frame duration should be extended.
2023-05-15 10:31:55 +02:00
Anton Khirnov 2d43c23b81 fftools/ffmpeg: discard packets for unused streams in demuxing thread
Avoids the pointless overhead of transferring them to the main thread.
2023-05-08 10:38:59 +02:00
Anton Khirnov dd1c67d539 fftools/ffmpeg: move unconfigured graph handling to ffmpeg_filter
This code more properly belongs there.
2023-05-08 10:38:59 +02:00
Anton Khirnov c7c73a3250 fftools/ffmpeg_filter: take fallback parameters from decoder, not demuxer
When an input stream terminates and no frames were successfully decoded,
filtering code will currently configure the filtergraph using demuxer
stream parameters. Use decoder parameters instead, which should be more
reliable. Also, initialize them immediately when an input stream is
bound to a filtergraph input, so that these parameters are always
available (if at all) and filtering code does not need to reach into the
decoder at some arbitrary later point.
2023-05-08 10:38:59 +02:00
Anton Khirnov f5cfb2c5df fftools/ffmpeg: eliminate need_output()
Replace it by simply calling choose_output() earlier.
2023-05-08 10:38:58 +02:00
Anton Khirnov 5673da4797 fftools/ffmpeg: merge choose_output() and got_eagain()
These two functions are a part of a single logical action - determining
which, if any, output stream needs to be processed next. Keeping them
separate is a historical artifact that obscures what is actually being
done.
2023-05-08 10:38:58 +02:00
Anton Khirnov 0e00d23510 fftools/ffmpeg: reduce -re to -readrate 1
They are exactly equivalent, so there is no point in maintaining a
separate flag for -re.
2023-05-07 15:49:27 +02:00
James Almer c7a8681860 fftools: use the new AVFrame keyframe flag
Signed-off-by: James Almer <jamrial@gmail.com>
2023-05-04 19:19:18 -03:00
James Almer 3675dd0e0c fftools: use the new AVFrame interlace flags
Signed-off-by: James Almer <jamrial@gmail.com>
2023-05-04 18:15:00 -03:00
Anton Khirnov 129c7bf53f fftools/ffmpeg: always use the same path for setting InputStream.[next_]dts
Currently those are set in different ways depending on whether the
stream is decoded or not, using some values from the decoder if it is.
This is wrong, because there may be arbitrary amount of delay between
input packets and output frames (depending e.g. on the thread count when
frame threading is used).

Always use the path that was previously used only for streamcopy. This
should not cause any issues, because these values are now used only for
streamcopy and discontinuity handling.

This change will allow to decouple discontinuity processing from
decoding and move it to ffmpeg_demux. It also makes the code simpler.

Changes output in fate-cover-art-aiff-id3v2-remux and
fate-cover-art-mp3-id3v2-remux, where attached pictures are now written
in the correct order. This happens because InputStream.dts is no longer
reset to AV_NOPTS_VALUE after decoding, so streamcopy actually sees
valid dts values.
2023-05-02 10:59:24 +02:00
Anton Khirnov 3190bed148 fftools/ffmpeg: constify packets passed to decode*()
They are not modified by these functions.
2023-05-02 10:59:24 +02:00
Anton Khirnov 302aecd06a fftools/ffmpeg: drop InputStream.[next_]pts
They are no longer used for anything.
2023-05-02 10:59:24 +02:00
Anton Khirnov ae95cd85dc fftools/ffmpeg_filter: stop using InputStream.pts for filter EOF ts
Use InputStream.last_frame_pts/duration instead, which is more accurate.
2023-05-02 10:59:24 +02:00
Anton Khirnov ef69f6a9d2 fftools/ffmpeg: stop using InputStream.pts for generating video timestamps
This was added in 380db56928 as a
temporary crutch that is not needed anymore. The only case where this
code can be triggered is the very first frame, for which InputStream.pts
is always equal to 0.
2023-05-02 10:59:24 +02:00
Anton Khirnov d85c6aba0c fftools/ffmpeg: rework audio-decode timestamp handling
Stop using InputStream.dts for generating missing timestamps for decoded
frames, because it contains pre-decoding timestamps and there may be
arbitrary amount of delay between input packets and output frames (e.g.
dependent on the thread count when frame threading is used). It is also
in AV_TIME_BASE (i.e. microseconds), which may introduce unnecessary
rounding issues.

New code maintains a timebase that is the inverse of the LCM of all the
samplerates seen so far, and thus can accurately represent every audio
sample. This timebase is used to generate missing timestamps after
decoding.

Changes the result of the following FATE tests
* pcm_dvd-16-5.1-96000
* lavf-smjpeg
* adpcm-ima-smjpeg
In all of these the timestamps now better correspond to actual frame
durations.
2023-05-02 10:59:24 +02:00
Anton Khirnov 6bbea932ca fftools/ffmpeg: set AVFrame.time_base for decoded frames
Makes it easier to keep track of the timebase the frames are in.
2023-05-02 10:59:24 +02:00
Anton Khirnov b6e7d64394 fftools/ffmpeg: stop using packet pts for decoded audio frame pts
If input packets have timestamps, they will be propagated to output
frames by the decoder, so at best this block does not do anything.

There can also be an arbitrary amount of delay between packets sent to
the decoder and decoded frames (e.g. due to decoder's intrinsic delay or
frame threading), so deriving any timestamps from packet properties is
wrong.
2023-05-02 10:59:24 +02:00
Anton Khirnov 5b3aeab1bd fftools/ffmpeg_filter: use correct timebase for filter EOF timestamp
It does not need to be equal to demuxer timebase.
2023-05-02 10:59:24 +02:00
Anton Khirnov 38c937e8c4 fftools/ffmpeg: drop undocumented runtime debug-setting
This feature is of highly questionable usefulness and - as the comment
in the code says - is not actually supported by the API.
2023-05-02 10:59:24 +02:00
Anton Khirnov f4a60b8ddc fftools/ffmpeg: reduce access to OutputStream.enc_ctx
It will be made private to Encoder in the future.
2023-05-02 10:59:24 +02:00
Anton Khirnov cc7a8ddf56 fftools/ffmpeg: move freeing a filtergraph into a separate function 2023-04-24 16:56:06 +02:00
Anton Khirnov eb9ce9de3b fftools/ffmpeg: move filtering functions to ffmpeg_filter 2023-04-24 16:56:06 +02:00
Anton Khirnov 03a465be57 fftools/ffmpeg: replace stream timebase with packet one where appropriate 2023-04-24 16:56:06 +02:00
Anton Khirnov 65b1350ad4 fftools/ffmpeg: stop setting InputStream.pts for streamcopy
It is not used in that case anymore.
Forgotten in d56652fdc8.
2023-04-24 16:56:06 +02:00
Anton Khirnov d8bc37f1f4 fftools/ffmpeg: stop using InputStream.pts in ts_discontinuity_detect()
ts_discontinuity_detect() is applied right after demuxing, while
InputStream.pts is a post-decoding timestamp, which may be delayed with
respect to demuxing by an arbitrary amount (e.g. depending on the thread
count when frame threading is used).
2023-04-24 16:56:06 +02:00
Anton Khirnov 87b4453ec6 fftools/ffmpeg: stop printing PSNR information in status report
When an encoder exports sum-of-squared-differences information in
encoded packets, print_report() will print PSNR information in the
status line. However,
* the code computing PSNR assumes 8bit 420 video and prints incorrect
  values otherwise; there are no issues on trac about this
* only a few encoders (namely aom, vpx, mpegvideo, snow) export this
  information; other often-used encoders such as libx26[45] do not
  export this, even though they could

This suggests that this feature is not useful and it is better to remove
it rather than spend effort on fixing it.
2023-04-24 16:53:59 +02:00
Anton Khirnov 3f11582ca3 fftools/ffmpeg_mux: stop using filter_in_rescale_delta_last for streamcopy
That field was added to store timestamp conversion state for audio
decoding code. Later it started being used by streamcopy as well, but
that use is wrong because, for a given input stream, both decoding and
an arbitrary number of streamcopies may be performed simultaneously.
They would then all overwrite the same state variable.

Store this state in MuxStream instead.

This is the last use of InputStream in of_streamcopy(), so the ist
parameter can now be removed.
2023-04-17 12:01:40 +02:00
Anton Khirnov 2178ff2162 fftools/ffmpeg: move do_streamcopy() to ffmpeg_mux
do_streamcopy() is muxing code, so this is a more appropriate place for
this. The last uses of InputStream in it will be removed in following
commits.
2023-04-17 12:01:40 +02:00
Anton Khirnov a064aed4c3 fftools/ffmpeg: store stream media type in OutputStream
Reduces access to a deeply nested muxer property
OutputStream.st->codecpar->codec_type for this fundamental and immutable
stream property.

Besides making the code shorter, this will allow making the AVStream
(OutputStream.st) private to the muxer in the future.
2023-04-17 12:01:40 +02:00
Anton Khirnov de38e17583 fftools/ffmpeg: initialize no-filter streams earlier
There is no reason to postpone it until transcode_init() anymore, it can
be done right at the end of of_open().
2023-04-17 12:01:40 +02:00
Anton Khirnov 2058402e00 fftools/ffmpeg: open decoders right after we know they are needed
Will allow initializing subtitle encoding earlier.
2023-04-17 12:01:40 +02:00
Anton Khirnov 9ce1a041d8 fftools/ffmpeg: move opening decoders to a new file
All decoding code will be moved to this file in the future.
2023-04-17 12:01:40 +02:00
Anton Khirnov 0c44db4646 fftools/ffmpeg: drop unnecessary indirection
init_input_stream() can print log messages directly, there is no need to
ship them to the caller.

Also, log errors to the InputStream and avoid duplicate information in
the message.
2023-04-17 12:01:40 +02:00
Anton Khirnov 4358d4d8e7 fftools/ffmpeg: move a check to a more appropriate place
reap_filters() no longer needs to access the encoding context.
2023-04-17 12:01:40 +02:00
Anton Khirnov 4fc513b5e3 fftools/ffmpeg: move a misplaced assignment
Changing AVCodecContext.sample_aspect_ratio after the encoder was opened
is by itself questionable, but if anywhere it belongs in encoding rather
than filtering code.
2023-04-17 12:01:36 +02:00
Anton Khirnov 12f3f41bbf fftools/ffmpeg: move init_output_stream_streamcopy() to ffmpeg_mux_init
Everything in it can be done immediately when creating the output
stream, there is no reason to postpone it.
2023-04-17 12:00:06 +02:00
Nongji Chen eb96cfbf57 ffmpeg: make timestamp discontinuity logging a warning
In most cases this should only occur once or so per stream in an
input, and in case the logic ends up in an eternal loop, it should
be visible to the end user instead of being completely invisible.

Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
2023-04-14 15:06:41 +03:00
Anton Khirnov cea71b2139 fftools/ffmpeg: stop using fake dts for generating timestamps
When no packet dts values are available from the container, video
decoding code will currently use its own guessed values, which will then
be propagated to pkt_dts on decoded frames and used as pts in certain
cases. This is inaccurate, fragile, and unnecessarily convoluted.
Simply removing this allows the extrapolation code introduced in the
previous commit to do a better job.

Changes the results of numerous h264 and hevc FATE tests, where no
spurious timestamp gaps are generated anymore. Several tests no longer
need -vsync passthrough.
2023-04-13 15:34:07 +02:00
Anton Khirnov 5d407cb2d7 fftools/ffmpeg: change video decoding timestamp generation
When no timestamps are available from the container, the video decoding
code will currently use fake dts values - generated in
process_input_packet() based on a combination of information from the
decoder and the parser (obtained via the demuxer) - to generate
timestamps during decoder flushing. This is fragile, hard to follow, and
unnecessarily convoluted, since more reliable information can be
obtained directly from post-decoding values.

The new code keeps track of the last decoded frame pts and estimates its
duration based on a number of heuristics. Timestamps generated when both
pts and pkt_dts are missing are then simple pts+duration of the last frame.
The heuristics are somewhat complicated by the fact that lavf insists on
making up packet timestamps based on its highly incomplete information.
That should be removed in the future, allowing to further simplify this
code.

The results of the following tests change:
* h264-3386 now requires -fps_mode passthrough to avoid dropping frames
  at the end; this is a pathology of the interaction of the new and old
  code, and the fact that the sample switches from field to frame coding
  in the last packet, and will be fixed in following commits
* hevc-conformance-DELTAQP_A_BRCM_4 stops inventing an arbitrary
  timestamp gap at the end
* hevc-small422chroma - the single frame output by this test now has a
  timestamp of 0, rather than an arbitrary 7
2023-04-13 15:34:07 +02:00
Anton Khirnov 380db56928 fftools/ffmpeg: use InputStream.pts as last resort for decoded frame pts 2023-04-13 15:34:07 +02:00
Anton Khirnov 95fa4edbd6 fftools/ffmpeg: improve decoder -ts_debug line
* log to the input stream log context
* drop the now-duplicate index/type information
* show pkt_dts and frame duration
2023-04-13 15:34:07 +02:00
Anton Khirnov d56652fdc8 fftools/ffmpeg: stop using InputStream.pts for streamcopy
This field contains different values depending on whether the stream is
being decoded or not. When it is, InputStream.pts is set to the
timestamp of the last decoded frame. Otherwise, it is made equal to
InputStream.dts.

Since a given InputStream can be at the same time decoded and
streamcopied to any number of output streams, this use is incorrect, as
decoded frame timestamps can be delayed with respect to input packets by
an arbitrary amount (e.g. depending on the thread count when frame
threading is used).

Replace all uses of InputStream.pts for streamcopy with InputStream.dts,
which is its value when decoding is not performed. Stop setting
InputStream.pts for pure streamcopy.
Also, pass InputStream.dts as a parameter to do_streamcopy(), which
will allow that function to be decoupled from InputStream completely in
the future.
2023-04-13 15:32:56 +02:00
Anton Khirnov 106eb58ceb fftools/ffmpeg: move checking for input -t out of do_streamcopy()
This check is entirely about the properties of the input stream, while
do_streamcopy() should contain code specific to a given output stream.
2023-04-13 15:11:56 +02:00
Anton Khirnov 0feff04956 fftools/ffmpeg: only set InputStream.next_pts for decoding
It is write-only for streamcopy.
2023-04-13 15:11:56 +02:00
Anton Khirnov d867f9ab8c fftools/ffmpeg: use AVPacket.time_base to simplify do_streamcopy()
Besides making the code shorter, this also reduces the use of
InputStream in this function and will allow not accessing it at all in
the future.
2023-04-13 15:11:56 +02:00
Anton Khirnov fdf29dcebb fftools/ffmpeg: inline check_output_constraints() into its only caller
Which is subtitle encoding. Also, check for AVSubtitle.pts rather than
InputStream.pts, since that is the more authoritative value and is
guaranteed to be valid.
2023-04-13 15:11:56 +02:00
Anton Khirnov ceb0275e45 fftools/ffmpeg: stop calling check_output_constraints() for streamcopy
That function only contains two checks now - whether the muxer returned
EOF and whether the packet timestamp is before requested output start
time.

The first check is unnecessary, since the packet will just be rejected
by the muxer. The second check is better combined with a related check
directly in do_streamcopy().
2023-04-13 15:11:56 +02:00
Anton Khirnov a85e7e5dea fftools/ffmpeg: track a list of non-lavfi outputs in InputStream
Currently, output streams where an input stream is sent directly (i.e.
not through lavfi) are determined by iterating over ALL the output
streams and skipping the irrelevant ones. This is awkward and
inefficient.
2023-04-13 15:11:56 +02:00
Anton Khirnov 2f24290c8e fftools/ffmpeg: disable and deprecate -qphist
This option adds a long string of numbers to the progress line, where
i-th number contains the base-2 logarithm of the number of times a frame
with this QP value was seen by print_report().

There are multiple problems with this feature:
* despite this existing since 2005, web search shows no indication
  that it was ever useful for any meaningful purpose;
* the format of what is printed is entirely undocumented, one has to
  find it out from the source code;
* QP values above 31 are silently ignored;
* it only works with one video stream;
* as it relies on global state, it is in conflict with ongoing
  architectural changes.

It then seems that the nontrivial cost of maintaining this option is not
worth its negligible (or possibly negative - since it pollutes the
already large option space) value.
Users who really need similar functionality can also implement it
themselves using -vstats.
2023-04-13 15:11:56 +02:00
Anton Khirnov 5d97ba5d9c fftools/ffmpeg: move printing verbose demuxing stats to ffmpeg_demux
This is a more appropriate place for this.
2023-04-13 15:11:56 +02:00
Anton Khirnov 37b118096a fftools/ffmpeg: rewrite printing the final output sizes
Current code in print_final_stats(), printing the final summary such as
  video:8851kB audio:548kB subtitle:0kB other streams:0kB global headers:20kB muxing overhead: 0.559521%
was written with a single output file in mind and makes very little
sense otherwise.

Print this information in mux_final_stats() instead, one line per output
file. Use the correct filesize, if available.
2023-04-13 15:11:56 +02:00
Anton Khirnov 3b6b0d1afb fftools/ffmpeg: move printing verbose muxing stats to ffmpeg_mux
This is a more appropriate place for this.
2023-04-13 15:11:56 +02:00
Anton Khirnov 79e136f14b fftools/ffmpeg: factorize checking whether any output was written
This is currently done in two places:
* at the end of print_final_stats(), which merely prints a warning if
  the total size of all written packets is zero
* at the end of transcode() (under a misleading historical 'close each
  encoder' comment), which instead checks the packet count to implement
  -abort_on empty_output[_stream]

Consolidate both of these blocks into a single function called from
of_write_trailer(), which is a more appropriate place for this. Also,
return an error code rather than exit immediately, which ensures all
output files are properly closed.
2023-04-13 15:11:56 +02:00
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 d99846d2f2 fftools/ffmpeg: move the hw_device_free_all() call to ffmpeg_cleanup()
Frees devices on failure as well as success.
2023-04-13 15:11:56 +02:00
Anton Khirnov f2c8dff906 fftools/ffmpeg: drop a useless goto
There is no cleanup in transcode(), can return an error directly.
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 2225134e7d fftools/ffmpeg: clean up #includes
Drop unneeded ctype.h and math.h.
Group all system headers together.
Sort unconditional includes alphabetically.
Group local includes by the library, sort alphabetically.
2023-04-09 15:47:45 +02:00
Anton Khirnov a2a09932f2 fftools/ffmpeg: stop including os_support.h
It was added for usleep(), which
- is not used in ffmpeg
- is not handled in os_support.h anymore
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 b79448fa38 fftools/ffmpeg: replace ff_dlog() with av_log()
ff_dlog() is a lavu internal macro, and av_log() at trace level is just
as good here.
2023-04-09 15:47:45 +02:00
Anton Khirnov a996478e8c fftools/ffmpeg: simplify output stream initialization call graph
Several places in the code currently call init_output_stream_wrapper(),
which in turn calls init_output_stream(), which then calls either
enc_open() or init_output_stream_streamcopy(), followed by
of_stream_init(), which tells the muxer the stream is ready for muxing.

All except one of these callers are in the encoding code, which will be
moved to ffmpeg_enc.c. Keeping this structure would then necessitate
ffmpeg_enc.c calling back into the common code in ffmpeg.c, which would
then just call ffmpeg_mux, thus making the already convoluted call chain
even more so.

Simplify the situation by using separate paths for filter-fed output
streams (audio and video encoders) and others (subtitles, streamcopy,
data, attachments).
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 1dabd48519 fftools/ffmpeg: reindent after previous commit 2023-04-09 15:47:45 +02:00
Anton Khirnov 39291f19e2 fftools/ffmpeg: move encoder initialization to init_output_stream_encode
Encoder initialization is currently split rather arbitrarily between
init_output_stream_encode() and init_output_stream(). Move all of it to
init_output_stream_encode().
2023-04-09 15:47:45 +02:00
Anton Khirnov e1fe6c5577 fftools/ffmpeg: use stack variables to shorten code 2023-04-09 15:47:45 +02:00
Anton Khirnov e1e0c2c7f2 fftools/ffmpeg: drop unnecessary indirection
init_output_stream() can print log messages directly, there is no need
to ship them to the caller.
2023-04-09 15:47:45 +02:00
Anton Khirnov 237f9b9682 fftools/ffmpeg: stop handling AVMEDIA_TYPE_DATA in init_output_stream_encode()
We do not support data encoders, so this should never be reached.
2023-04-09 15:47:45 +02:00
Anton Khirnov 923c6ab170 fftools/ffmpeg: use sync queues for enforcing audio frame size
The code currently uses lavfi for this, which creates a sort of
configuration dependency loop - the encoder should be ideally
initialized with information from the first audio frame, but to get this
frame one needs to first open the encoder to know the frame size. This
necessitates an awkward workaround, which causes audio handling to be
different from video.

With this change, audio encoder initialization is congruent with video.
2023-04-09 15:47:45 +02:00
Anton Khirnov 090950f832 fftools/sync_queue: use timebase from input frames/packets
They are always properly set now. Avoid a separate timebase-setting
call, which duplicates the knowledge of the timebase being used.
2023-04-09 15:47:45 +02:00
Anton Khirnov 87e9f5ad3c fftools/ffmpeg: move initializing next_[pd]ts to add_input_streams()
They are initialized to constants, so it makes most sense to do it as
soon as possible.
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 e1d12aaa45 fftools/ffmpeg: do not return finished streams from choose_output() 2023-04-09 15:47:45 +02:00
Anton Khirnov 416e2661ea fftools/ffmpeg: make sure non-lavfi streams are closed on input EOF 2023-04-09 15:47:45 +02:00
rcombs b68a6ba469 ffmpeg: send only one rect per packet when encoding ASS
The packet and rect formats are identical,
so there's no support for multiple rects per packet.
2023-03-21 14:24:31 -04:00
Marton Balint 6b6f7db819 avcodec: add AVCodecContext.frame_num as 64 bit variant to frame_number
Frame counters can overflow relatively easily (INT_MAX number of frames is
slightly more than 1 year for 60 fps content), so make sure we use 64 bit
values for them.

Also deprecate the old 32 bit frame_number attribute.

Signed-off-by: Marton Balint <cus@passwd.hu>
2023-02-13 00:36:46 +01:00
James Almer e0786a8eeb avcodec: remove FF_API_THREAD_SAFE_CALLBACKS
Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2023-02-09 15:24:16 +01:00