summaryrefslogtreecommitdiffstats
path: root/common/recorder.c
Commit message (Collapse)AuthorAgeFilesLines
* recorder: fix a couple of memory leaksDudemanguy2023-09-261-7/+16
| | | | Not sure how long these have been around but it leaked on every packet.
* ffmpeg: update to handle deprecation of `av_init_packet`Philip Langdale2022-12-031-7/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This has been a long standing annoyance - ffmpeg is removing sizeof(AVPacket) from the API which means you cannot stack-allocate AVPacket anymore. However, that is something we take advantage of because we use short-lived AVPackets to bridge from native mpv packets in our main decoding paths. We don't think that switching these to `av_packet_alloc` is desirable, given the cost of heap allocation, so this change takes a different approach - allocating a single packet in the relevant context and reusing it over and over. That's fairly straight-forward, with the main caveat being that re-initialising the packet is unintuitive. There is no function that does exactly what we need (what `av_init_packet` did). The closest is `av_packet_unref`, which additionally frees buffers and side-data. However, we don't copy those things - we just assign them in from our own packet, so we have to explicitly clear the pointers before calling `av_packet_unref`. But at least we can make a wrapper function for that. The weirdest part of the change is the handling of the vtt subtitle conversion. This requires two packets, so I had to pre-allocate two in the context struct. That sounds excessive, but if allocating the primary packet is too expensive, then allocating the secondary one for vtt subtitles must also be too expensive. This change is not conditional as heap allocated AVPackets were available for years and years before the deprecation.
* recorder: add support for attachments (fonts)TheAMM2021-07-081-1/+33
| | | | | | Though, only when the output format is matroska, to avoid muxing errors. This is quite useful when the input has ASS subtitles, as they tend to rely on embedded fonts.
* recorder: ignore packet queue in mux_packets()TheAMM2021-07-081-19/+8
| | | | | | | | | | | | I've looked and studied the flow in the recorder, and to my understanding, the packet queue is moot after the initial sync, maybe even then - but that's beyond me right now. With the previous choice to mux trailing packets whatever the case, this doesn't result in any new ill effects (and some missing packets at the end is no big deal). Notably, since we don't have to hold onto the packets after we get muxing, we'll never run into any issues with veeery long GOPs filling up our queue (resulting in dropped packets and much user chagrin).
* recorder: clear packet queue after they've been muxedTheAMM2021-07-081-1/+1
| | | | | | | | | | | | | In commit f7678575a5d7f598abf267cb303e0a74db276f27, wm4 chooses to mux all remaining packets when mp_recorder_mark_discontinuity() is called and adds a call to mux_packets(). However, it is called only after flush_packets(), which clears the packets before they can be muxed out. This has no ill effects per se - recordings end on keyframes, as before - but judging from his commit message, the intention explicitly was to output the inter frames, since long GOPs can mean several seconds of missing content from the output. So, clear the stream packet queues only after the final mux. Also, flushing can mean both discarding and committing. What a country!
* recorder: fix codec_tag / codec_id confusionTheAMM2021-05-261-2/+2
|
* recorder: clear codec_tag if no target format supportTheAMM2021-05-261-0/+6
| | | | | | | Avoiding blindly copying the codec_tag between different formats allows us to mux packets from, say, mpegts streams to matroska, making the recorder (dump-cache) much more usable as unsupported codec_tags can make the muxer reject the streams.
* Remove remains of Libav compatibilitywm42020-02-161-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Libav seems rather dead: no release for 2 years, no new git commits in master for almost a year (with one exception ~6 months ago). From what I can tell, some developers resigned themselves to the horrifying idea to post patches to ffmpeg-devel instead, while the rest of the developers went on to greener pastures. Libav was a better project than FFmpeg. Unfortunately, FFmpeg won, because it managed to keep the name and website. Libav was pushed more and more into obscurity: while there was initially a big push for Libav, FFmpeg just remained "in place" and visible for most people. FFmpeg was slowly draining all manpower and energy from Libav. A big part of this was that FFmpeg stole code from Libav (regular merges of the entire Libav git tree), making it some sort of Frankenstein mirror of Libav, think decaying zombie with additional legs ("features") nailed to it. "Stealing" surely is the wrong word; I'm just aping the language that some of the FFmpeg members used to use. All that is in the past now, I'm probably the only person left who is annoyed by this, and with this commit I'm putting this decade long problem finally to an end. I just thought I'd express my annoyance about this fucking shitshow one last time. The most intrusive change in this commit is the resample filter, which originally used libavresample. Since the FFmpeg developer refused to enable libavresample by default for drama reasons, and the API was slightly different, so the filter used some big preprocessor mess to make it compatible to libswresample. All that falls away now. The simplification to the build system is also significant.
* recorder: don't use a magic index for mp_recorder_get_sink()wm42019-09-291-4/+10
| | | | | | | | | | | | | | | | | | | Although this was sort of elegant, it just seems to complicate things slightly. Originally, the API meant that you cache mp_recorder_sink yourself (which would avoid the mess of passing an index around), but that too seems slightly roundabout. In a later change, I want to change the set of streams passed to mp_recorder_create(), and then I'd have to keep track of the index for each stream, which would suck. With this commit, I can just pass the unambiguous sh_stream to it, and it will be guaranteed to match the correct stream. The disadvantages are barely worth discussing. It's a new linear search per packet, but usually only 2 to 4 streams are active at a time. Also, in theory a user could want to write 2 streams using the same sh_stream (same metadata, just writing different packets or so), but in practice this is never done.
* recorder: always mux all packets on discont/closewm42019-09-191-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is the muxer used by all 3 stream recording features (why are there so many?). It tried hard to avoid writing broken files. In particular, it buffered packets until it new there was a keyframe packet (which, in mpv's/FFmpeg's definition, mean seek points from which decoding can resume), or final EOF. The danger that was probably considered here was that due to video frame reordering, not muxing some trailing, missing packets of a keyframe range could lead to broken decoding or skipped frames, so better discard packets belonging to an incomplete range. Sounds like a good idea so far. Unfortunately, this will drop an entire keyframe range even if the current packet run is complete and mp_recorder_mark_discontinuity() is called, simply because recorder.c can not know that the next packet would have been a keyframe. It seems better to mux all packets to avoid losing valid data, even if it means that sometimes packets/frames will be missing from the file. It benefits especially the dump-cache command, which will call the function to signal a discontinuity after every range. Before this commit, it discarded the last packets, even if they were perfectly fine. (An alternative solution for dump-cache would have been a second discontinuity marker function, that communicates that the current packet range is complete. But this commit's solution is simpler and overall more robust, at the danger of producing more semi-broken files.) This may make some of the complex buffering/waiting logic in recorder.c pointless. Untested (in this final form).
* recorder: use shared PTS macroswm42019-09-191-9/+7
| | | | | | | | These macros explicitly honor MP_NOPTS_VALUE, instead of implicitly relying on the fact that this value is the lowest allowed value. In addition, this changes one case to use MP_NOPTS_VALUE instead of INFINITY, also a cosmetic change.
* demux: add another stream recording featurewm42018-12-061-2/+1
| | | | | | --record-file is nice, but only sometimes. If you watch some sort of livestream which you want to record, it's actually much nicer not to record what you're currently "seeing", but anything you're receiving.
* Fix various typos in log messagesNicolas F2017-12-031-1/+1
|
* player: add experimental stream recording featurewm42017-02-071-0/+384
This is basically a WIP, but it can't remain in a branch forever. A warning is print when using it as it's still a bit "shaky".