summaryrefslogtreecommitdiff
path: root/fftools/ffmpeg.h
Commit message (Collapse)AuthorAge
* fftools/ffmpeg: add a live mux modeliveAnton Khirnov2022-08-10
| | | | | | | | Track the wallclock time at which each input packet is demuxed and propagate it through decoding and encoding. When the live mux option is used, drop all packets demuxed before the muxer is opened. This is intended to avoid latency when opening the muxer takes a long time.
* fftools/ffmpeg_demux: do not store demux packet in the contextAnton Khirnov2022-08-08
| | | | Its use is local to input_thread().
* fftools/ffmpeg: move -stream_loop handling to the demuxer threadAnton Khirnov2022-08-08
| | | | | | | | | | | | | -stream_loop is currently handled by destroying the demuxer thread, seeking, then recreating it anew. This is very messy and conflicts with the future goal of moving each major ffmpeg component into its own thread. Handle -stream_loop directly in the demuxer thread. Looping requires the demuxer to know the duration of the file, which takes into account the duration of the last decoded audio frame (if any). Use a thread message queue to communicate this information from the main thread to the demuxer thread.
* fftools/ffmpeg: move seek_to_start() to ffmpeg_demux.cAnton Khirnov2022-08-08
| | | | Reduces the diff in the following commit.
* fftools/ffmpeg: move get_input_packet() to ffmpeg_demux.cAnton Khirnov2022-08-08
| | | | Also rename it to use the ifile_* namespace.
* fftools/ffmpeg: move the input thread into its own fileAnton Khirnov2022-08-08
| | | | It will contain more demuxing-specific code in the future.
* fftools/ffmpeg: drop a write-only variableAnton Khirnov2022-08-08
|
* fftools/ffmpeg: store the input file index in InputFileAnton Khirnov2022-08-08
| | | | | | Use it to simplify some code and fix two off-by-one errors. Similar to what was previously done for OutputFile.
* fftools/ffmpeg: deprecate specifying a sync stream with -mapAnton Khirnov2022-08-08
| | | | It has not had any effect whatsoever for over 10 years.
* fftools/ffmpeg: remove OutputStream.sync_istAnton Khirnov2022-08-08
| | | | It is not actually used for anything.
* fftools/ffmpeg: remove OutputStream.encoding_neededAnton Khirnov2022-08-08
| | | | It is unnecessary, as it is always exactly equivalent to !!ost->enc_ctx
* fftools/ffmpeg: remove OutputStream.stream_copyAnton Khirnov2022-08-08
| | | | | | | | | | | | | | | There are currently three possible modes for an output stream: 1) The stream is produced by encoding output from some filtergraph. This is true when ost->enc_ctx != NULL, or equivalently when ost->encoding_needed != 0. 2) The stream is produced by copying some input stream's packets. This is true when ost->enc_ctx == NULL && ost->source_index >= 0. 3) The stream is produced by attaching some file directly. This is true when ost->enc_ctx == NULL && ost->source_index < 0. OutputStream.stream_copy is currently used to identify case 2), and sometimes to confusingly (or even incorrectly) identify case 1). Remove it, replacing its usage with checking enc_ctx/source_index values.
* fftools/ffmpeg: deprecate the -map_channel optionAnton Khirnov2022-07-28
| | | | | It is now entirely redundant with audio filters, and is in fact implemented by setting up a 'pan' filter instance.
* fftools/ffmpeg: move guess_input_channel_layout() to ffmpeg_opt.cAnton Khirnov2022-07-28
| | | | That is the only place where it is used. Also make it static.
* fftools/ffmpeg: drop unused hwaccel variablesAnton Khirnov2022-07-28
|
* fftools/ffmpeg: deprecate -psnrAnton Khirnov2022-07-28
| | | | It is entirely redundant with -flags +psnr.
* fftools/ffmpeg: drop OutputStream.ref_parAnton Khirnov2022-07-28
| | | | | It serves no purpose, codec parameters can be written directly to AVStream.codecpar with the same effect.
* fftools/ffmpeg: move each muxer to a separate threadAnton Khirnov2022-07-23
|
* fftools/ffmpeg: depend on threadsAnton Khirnov2022-07-23
| | | | | ffmpeg will be switched to a fully threaded architecture, starting with muxers.
* fftools/ffmpeg_mux: return errors from of_submit_packet()Anton Khirnov2022-07-23
| | | | | Do not call exit_program(), as that would conflict with moving this code into a separate thread.
* fftools/ffmpeg: make the muxer AVFormatContext private to ffmpeg_mux.cAnton Khirnov2022-07-23
| | | | | Since the muxer will operate in a separate thread in the future, the muxer context should not be accessed from the outside.
* fftools/ffmpeg: only set OutputStream.frame_number for video encodingAnton Khirnov2022-07-23
| | | | | | | It is unused otherwise. Rename the field to vsync_frame_number to better reflect its current purpose.
* fftools/ffmpeg: rework -shortest implementationAnton Khirnov2022-07-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The -shortest option (which finishes the output file at the time the shortest stream ends) is currently implemented by faking the -t option when an output stream ends. This approach is fragile, since it depends on the frames/packets being processed in a specific order. E.g. there are currently some situations in which the output file length will depend unpredictably on unrelated factors like encoder delay. More importantly, the present work aiming at splitting various ffmpeg components into different threads will make this approach completely unworkable, since the frames/packets will arrive in effectively random order. This commit introduces a "sync queue", which is essentially a collection of FIFOs, one per stream. Frames/packets are submitted to these FIFOs and are then released for further processing (encoding or muxing) when it is ensured that the frame in question will not cause its stream to get ahead of the other streams (the logic is similar to libavformat's interleaving queue). These sync queues are then used for encoding and/or muxing when the -shortest option is specified. A new option – -shortest_buf_duration – controls the maximum number of queued packets, to avoid runaway memory usage. This commit changes the results of the following tests: - copy-shortest[12]: the last audio frame is now gone. This is correct, since it actually outlasts the last video frame. - shortest-sub: the video packets following the last subtitle packet are now gone. This is also correct.
* fftools/ffmpeg: use pre-BSF DTS for choosing next outputAnton Khirnov2022-07-23
| | | | | | | | | | The following commits will add a new buffering stage after bitstream filters, which should not be taken into account for choosing next output. OutputStream.last_mux_dts is also used by the muxing code to make up missing DTS values - that field is now moved to the muxer-private MuxStream object.
* fftools/ffmpeg: use last filter output pts to choose next output streamAnton Khirnov2022-07-23
| | | | | This will be needed in following commits that will add new buffering stages after encoding and bitstream filtering.
* fftools/ffmpeg: move output file opts into private contextAnton Khirnov2022-07-23
| | | | It is private to the muxer, no reason to access it from outside.
* fftools/ffmpeg_mux: split of_write_packet()Anton Khirnov2022-07-23
| | | | | | | | | | | | | | | | It is currently called from two places: - output_packet() in ffmpeg.c, which submits the newly available output packet to the muxer - from of_check_init() in ffmpeg_mux.c after the header has been written, to flush the muxing queue Some packets will thus be processed by this function twice, so it requires an extra parameter to indicate the place it is called from and avoid modifying some state twice. This is fragile and hard to follow, so split this function into two. Also rename of_write_packet() to of_submit_packet() to better reflect its new purpose.
* fftools/ffmpeg: move the mux queue into muxer private dataAnton Khirnov2022-07-23
| | | | | | | | | The muxing queue currently lives in OutputStream, which is a very large struct storing the state for both encoding and muxing. The muxing queue is only used by the code in ffmpeg_mux, so it makes sense to restrict it to that file. This makes the first step towards reducing the scope of OutputStream.
* fftools/ffmpeg: access output file chapters through a wrapperAnton Khirnov2022-07-23
| | | | | Avoid accessing the muxer context directly, as this will become forbidden in future commits.
* fftools/ffmpeg: refactor the code checking for bitexact outputAnton Khirnov2022-07-23
| | | | | | | | Figure out earlier whether the output stream/file should be bitexact and store this information in a flag in OutputFile/OutputStream. Stop accessing the muxer in set_encoder_id(), which will become forbidden in future commits.
* fftools/ffmpeg: set want_sdp when initializing the muxerAnton Khirnov2022-07-23
| | | | Allows making the variable local to ffmpeg_mux.
* fftools/ffmpeg: refactor limiting output file size with -fsAnton Khirnov2022-07-23
| | | | | | Move the file size checking code to ffmpeg_mux. Use the recently introduced of_filesize(), making this code consistent with the size shown by print_report().
* fftools/ffmpeg: fix the type of limit_filesizeAnton Khirnov2022-07-23
| | | | | The option is parsed as INT64 (signed). It is also compared to the output of avio_tell(), which is also int64_t.
* fftools/ffmpeg: add a helper function to access output file sizeAnton Khirnov2022-07-23
| | | | Stop accessing muxer internals from outside of ffmpeg_mux.
* fftools/ffmpeg_mux: add private muxer contextAnton Khirnov2022-07-23
| | | | | | | | Move header_written into it, which is not (and should not be) used by any code outside of ffmpeg_mux. In the future this context will contain more muxer-private state that should not be visible to other code.
* ffmpeg: add option -isyncGyan Doshi2022-07-14
| | | | | | | | | | | | This is a per-file input option that adjusts an input's timestamps with reference to another input, so that emitted packet timestamps account for the difference between the start times of the two inputs. Typical use case is to sync two or more live inputs such as from capture devices. Both the target and reference input source timestamps should be based on the same clock source. If either input lacks starting timestamps, then no sync adjustment is made.
* fftools/ffmpeg: change frame counters to 64 bitMarton Balint2022-06-27
| | | | | | | | | | | 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 are always using 64 bit values for them. A live stream can easily run for more than a year and the framedup logic breaks on an overflow. Signed-off-by: Marton Balint <cus@passwd.hu>
* ffmpeg: add option fps_modeGyan Doshi2022-06-11
| | | | | | | fps_mode sets video sync per output stream. Overrides vsync for matching streams. vsync is deprecated.
* fftools/ffmpeg: stop using AVStream.nb_frames in do_video_stats()Anton Khirnov2022-05-24
| | | | | | | | | | Its use for muxing is not documented, in practice it is incremented per each packet successfully passed to the muxer's write_packet(). Since there is a lot of indirection between ffmpeg receiving a packet from the encoder and it actually being written (e.g. bitstream filters, the interleaving queue), using nb_frames here is incorrect. Add a new counter for packets received from encoder instead.
* fftools/ffmpeg: store output format separately from the muxer contextAnton Khirnov2022-04-13
| | | | | | Allows accessing it without going through the muxer context. This will be useful in the following commits, where the muxer context will be hidden.
* fftools/ffmpeg: move freeing the output file to ffmpeg_mux.cAnton Khirnov2022-04-13
|
* fftools/ffmpeg: move writing the trailer to ffmpeg_mux.cAnton Khirnov2022-04-13
|
* fftools/ffmpeg: move some muxing-related code into a separate fileAnton Khirnov2022-04-13
| | | | | This is a first step towards making muxers more independent from the rest of the code.
* fftools/ffmpeg: store the output file index in OutputFileAnton Khirnov2022-04-13
| | | | | Use it to simplify check_init_output_file(). Will allow further simplifications in the following commits.
* fftools/ffmpeg: stop using OutputStream.frame_number for streamcopyAnton Khirnov2022-04-13
| | | | | | | | | | | | | | This field is currently used by checks - skipping packets before the first keyframe - skipping packets before start time to test whether any packets have been output already. But since frame_number is incremented after the bitstream filters are applied (which may involve delay), this use is incorrect. The keyframe check works around this by adding an extra flag, the start-time check does not. Simplify both checks by replacing the seen_kf flag with a flag tracking whether any packets have been output by do_streamcopy().
* ffmpeg: replace custom channel_layout code with an SpecifierOpt based oneJames Almer2022-03-22
| | | | | | This is cleaner and allows fine tuning which stream the option is applied to. Signed-off-by: James Almer <jamrial@gmail.com>
* ffmpeg: convert to new channel layout-APIJames Almer2022-03-15
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* ffmpeg: ensure a keyframe was not seen before skipping packetsJames Almer2022-02-28
| | | | | | | A keyframe could be buffered in the bsf and not be output until more packets had been fed to it. Signed-off-by: James Almer <jamrial@gmail.com>
* ffmpeg: flush delayed frames in codec copy scenariosJames Almer2022-02-28
| | | | | | | Bitstream filters inserted between the input and output were never drained, resulting in packets being lost if the bsf had any buffered. Signed-off-by: James Almer <jamrial@gmail.com>
* ffmpeg: switch to new FIFO APIAnton Khirnov2022-02-07
|