aboutsummaryrefslogtreecommitdiffstats
path: root/fftools/ffmpeg_mux.c
Commit message (Collapse)AuthorAgeFilesLines
* fftools/ffmpeg_mux: replace monotonous with monotonicLeo Izen2023-09-011-1/+1
| | | | | | | The word "monotonous" means "spoken in a monotone" which is not what we mean here. We mean "monotonic" i.e. nondecreasing. Signed-off-by: Leo Izen <leo.izen@gmail.com>
* fftools/ffmpeg_mux: rename of_close() to of_free()Anton Khirnov2023-08-301-1/+1
| | | | | | This function is primarily a destructor for OutputFile, the underlying AVIOContext is normally closed earlier (right after writing the trailer).
* fftools/ffmpeg_mux: stop rescaling timestamps in of_streamcopy()Anton Khirnov2023-08-301-21/+23
| | | | | | | | | | | | | | | | This function converts packet timestamps from the input stream timebase to OutputStream.mux_timebase, which may or may not be equal to the actual output AVStream timebase (and even when it is, this may not always be the optimal choice due to bitstream filtering). Just keep the timestamps in input stream timebase, they will be rescaled as needed before bitstream filtering and/or sending the packet to the muxer. Move the av_rescale_delta() call for audio (needed to preserve accuracy with coarse demuxer timebases) to write_packet. Drop now-unused OutputStream.mux_timebase.
* fftools/ffmpeg_mux: use correct timebases for bitstream filteringAnton Khirnov2023-08-301-6/+6
| | | | | | | | | | Bitstream filtering input timebase is not always necessarily equal to OutputStream.mux_timebase. Also, set AVPacket.time_base correctly for packets output by bitstream filters Do not rescale at all in of_output_packet() when not doing bitstream filtering, as it's unnecessary - write_packet() will rescale to the actual muxer timebase.
* fftools/ffmpeg_mux: return errors from of_output_packet() instead of abortingAnton Khirnov2023-07-201-11/+9
|
* fftools/ffmpeg_mux: return errors from of_streamcopy() instead of abortingAnton Khirnov2023-07-151-8/+12
|
* fftools/ffmpeg_mux: forward EOF from the sync queueAnton Khirnov2023-07-131-2/+8
| | | | | | | EOF from sq_receive() means no packets will ever be output by the sync queue. Since the muxing sync queue is always used by all interleaved (i.e. non-attachment) streams, this means no further packets can make it to the muxer and we can terminate muxing now.
* fftools/ffmpeg_dec: move decoding to a separate threadAnton Khirnov2023-06-191-5/+0
| | | | | | | | | | This is only a preparatory step to a fully threaded architecture and does not yet make decoding truly parallel - the main thread will currently submit a packet and wait until it has been fully processed by the decoding thread before moving on. Decoder behavior as observed by the rest of the program should remain unchanged. That will change in future commits after encoders and filters are moved to threads and a thread-aware scheduler is added.
* fftools/ffmpeg_mux: make OutputStream.pkt privateAnton Khirnov2023-06-051-2/+2
| | | | It is no longer used outside of muxing code.
* fftools/ffmpeg_mux: simplify calling of_output_packet()Anton Khirnov2023-06-051-7/+7
| | | | | Use NULL packets to signal EOF instead of a separate variable. This is made possible by the previous commit.
* fftools/ffmpeg_mux: use a dedicated packet for BSF outputAnton Khirnov2023-06-051-2/+7
| | | | | | Currently of_output_packet() reuses the input packet, which requires its callers to submit blank packets even on EOF, which makes the code more complex.
* fftools/ffmpeg: convert timestamps inside the muxerAnton Khirnov2023-06-051-0/+6
| | | | | | Packets submitted to the muxer now have their timebase attached to them, so the muxer can do conversion to muxing timebase and avoid exposing it to callers.
* fftools/ffmpeg_mux: set stream duration after the timebase is certainly knownAnton Khirnov2023-06-051-0/+5
| | | | | Stop assuming the encoder knows the muxing timebase, which does not always have to hold (e.g. due to bitstream filters).
* fftools/ffmpeg_mux: flush bsfs immediately on exceeding recoding timeAnton Khirnov2023-05-311-6/+5
| | | | | | Current code marks the output stream as finished and waits for a flush packet, but that is both unnecessary and suspect, as in theory nothing should be sent to a finished stream - not even flush packets.
* fftools/ffmpeg_filter: always pass graph description to fg_create()Anton Khirnov2023-05-311-1/+0
| | | | | | Currently NULL would be passed for simple filtergraphs, which would make the filter code extract the graph description from the output stream when needed. This is unnecessarily convoluted.
* fftools/ffmpeg: replace print_error() by more meaningful messagesAnton Khirnov2023-05-151-1/+3
|
* fftools/ffmpeg_filter: add filtergraph private dataAnton Khirnov2023-05-021-1/+0
| | | | | Start by moving OutputStream.filtered_frame to it, which really belongs to the filtergraph rather than the output stream.
* fftools/ffmpeg: reduce access to OutputStream.enc_ctxAnton Khirnov2023-05-021-1/+1
| | | | It will be made private to Encoder in the future.
* fftools/ffmpeg: remove unused function argumentsAnton Khirnov2023-04-241-2/+2
|
* fftools/ffmpeg_mux: fix reporting muxer EOF as errorZhao Zhili2023-04-231-3/+9
| | | | | | Fix #10327. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* fftools/ffmpeg: propagate frame durations to packets when encodingAnton Khirnov2023-04-191-9/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove now-obsolete code setting packet durations pre-muxing for CFR encoded video. Changes output in the following FATE tests: * numerous adpcm tests * ffmpeg-filter_complex_audio * lavf-asf * lavf-mkv * lavf-mkv_attachment * matroska-encoding-delay All of these change due to the fact that the output duration is now the actual input data duration and does not include padding added by the encoder. * apng-osample: less wrong packet durations are now passed to the muxer. They are not entirely correct, because the first frame duration should be 3 rather than 2. This is caused by the vsync code and should be addressed later, but this change is a step in the right direction. * tscc2-mov: last output frame has a duration of 11 rather than 1 - this corresponds to the duration actually returned by the demuxer. * film-cvid: video frame durations are now 2 rather than 1 - this corresponds to durations actually returned by the demuxer and matches the timestamps. * mpeg2-ticket6677: durations of some video frames are now 2 rather than 1 - this matches the timestamps.
* fftools/ffmpeg_mux: make copy_initial_nonkeyframes private to muxing codeAnton Khirnov2023-04-171-1/+1
| | | | It is no longer used outside of ffmpeg_mux*
* fftools/ffmpeg_mux: make copy_prior_start private to muxing codeAnton Khirnov2023-04-171-1/+1
| | | | It is no longer used outside of ffmpeg_mux*
* fftools/ffmpeg_mux: make streamcopy_started private to muxing codeAnton Khirnov2023-04-171-3/+3
| | | | It is no longer used outside of ffmpeg_mux*
* fftools/ffmpeg_mux: make ts_copy_start private to muxing codeAnton Khirnov2023-04-171-2/+2
| | | | It is no longer used outside of ffmpeg_mux*
* fftools/ffmpeg_mux: stop using filter_in_rescale_delta_last for streamcopyAnton Khirnov2023-04-171-3/+3
| | | | | | | | | | | | | 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.
* fftools/ffmpeg_mux: use output stream parameters in of_streamcopy()Anton Khirnov2023-04-171-3/+3
| | | | | They should always be the same as the input stream parameters, but this reduces the need to access InputStream in muxing code.
* fftools/ffmpeg: move do_streamcopy() to ffmpeg_muxAnton Khirnov2023-04-171-0/+76
| | | | | | 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.
* fftools/ffmpeg: add muxer-input codec parameters to OutputStreamAnton Khirnov2023-04-171-2/+4
| | | | | | | | | | | It stores codec parameters of the stream submitted to the muxer, which may be different from the codec parameters in AVStream due to bitstream filtering. This avoids the confusing back and forth synchronisation between the encoder, bitstream filters, and the muxer, now information flows only in one direction. It also reduces the need for non-muxing code to access AVStream.
* fftools/ffmpeg: store stream media type in OutputStreamAnton Khirnov2023-04-171-6/+5
| | | | | | | | | 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.
* fftools/ffmpeg_mux: make data_size_mux private to ffmpeg_muxAnton Khirnov2023-04-131-2/+3
| | | | It is no longer used outside of this file.
* fftools/ffmpeg: rewrite printing the final output sizesAnton Khirnov2023-04-131-3/+33
| | | | | | | | | | 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.
* fftools/ffmpeg_mux: log final stats to muxer contextAnton Khirnov2023-04-131-8/+8
|
* fftools/ffmpeg_mux: reindentAnton Khirnov2023-04-131-28/+28
|
* fftools/ffmpeg: move printing verbose muxing stats to ffmpeg_muxAnton Khirnov2023-04-131-0/+37
| | | | This is a more appropriate place for this.
* fftools/ffmpeg: factorize checking whether any output was writtenAnton Khirnov2023-04-131-0/+43
| | | | | | | | | | | | | | 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.
* fftools/ffmpeg: eliminate the main_return_code globalAnton Khirnov2023-04-131-7/+5
| | | | | | | | 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
* fftools/ffmpeg: move OutputStream.sq_frame to EncoderAnton Khirnov2023-04-131-1/+0
| | | | | It is audio/video encoding-only and does not need to be visible outside of ffmpeg_enc.c
* fftools/ffmpeg: add encoder private dataAnton Khirnov2023-04-091-1/+2
| | | | | Start by moving OutputStream.last_frame to it. In the future it will hold other encoder-internal state.
* fftools/sync_queue: use timebase from input frames/packetsAnton Khirnov2023-04-091-3/+0
| | | | | They are always properly set now. Avoid a separate timebase-setting call, which duplicates the knowledge of the timebase being used.
* fftools/ffmpeg_mux: distinguish between sync queue and muxer EOFAnton Khirnov2023-02-101-5/+9
| | | | | | | Individual streams should be terminated in the former case, the whole muxing process in the latter. Reported-by: Gyan Doshi
* fftools/ffmpeg: add an option for writing pre-muxing statsAnton Khirnov2023-02-091-1/+9
| | | | | | 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.
* fftools/ffmpeg: store output packet timebases in the packetAnton Khirnov2023-02-091-3/+4
| | | | Useful to keep track of what timebase the packet's timestamps are in.
* fftools/ffmpeg: add an AVClass to MuxStream/OutputStreamAnton Khirnov2023-01-291-7/+6
| | | | | Use it for logging. This makes log messages related to this output stream more consistent.
* fftools/ffmpeg: add an AVClass to Muxer/OutputFileAnton Khirnov2023-01-291-16/+10
| | | | | Use it for logging. This makes log messages related to this output file more consistent.
* fftools/ffmpeg: add options for writing encoding statsAnton Khirnov2023-01-291-0/+8
| | | | | | | Similar to -vstats, but more flexible: - works for audio as well as video - frame and/or packet information - user-specifiable format
* fftools/ffmpeg: avoid storing full forced keyframe specAnton Khirnov2022-11-281-1/+0
| | | | | It is not needed after the spec is parsed. Also avoids ugly string comparisons for each video frame.
* fftools/ffmpeg: parse forced keyframes in of_open()Anton Khirnov2022-11-281-8/+0
| | | | Allows to remove the ugly of_get_chapters() wrapper.
* fftools/ffmpeg: move force-keyframe-related vars to a separate structAnton Khirnov2022-11-281-3/+4
| | | | | | 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.
* fftools/ffmpeg_mux_init: postpone matching -disposition to streamsAnton Khirnov2022-11-231-1/+0
| | | | | | | | | 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().