summaryrefslogtreecommitdiff
path: root/libavformat
Commit message (Collapse)AuthorAge
...
* avformat/utils: Remove redundant flushing of packet queueAndreas Rheinhardt2021-08-30
| | | | | | | The packet queue is already flushed in avformat_free_context() which is called a few lines below. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux: Don't access AVStream's internal AVCodecContextAndreas Rheinhardt2021-08-30
| | | | | | | | | | An AVStream's internal AVCodecContext is pretty much unused for muxing: The only place where any of its fields are set is avformat_transfer_internal_stream_timing_info() where its time base is set based upon the desired output format. The max_b_frames field is never set at all, so don't read it in mux.c. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Make ff_compute_frame_duration() staticAndreas Rheinhardt2021-08-30
| | | | | | | | Since 1c0885334dda9ee8652e60c586fa2e3674056586 ff_compute_frame_duration is only called from within utils.c and only for demuxers. So make it static and remove the code in it that deals with muxers. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Remove obsolete todoAndreas Rheinhardt2021-08-30
| | | | | | Also initialize the AVCodecContexts directly. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Remove always-false checkAndreas Rheinhardt2021-08-30
| | | | | | | | | AVFormatContext.internal is already allocated by avformat_alloc_context() on success; and on error, avformat_alloc_context() cleans up manually without avformat_free_context(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/yuv4mpegdec: Don't call avio_tell() twiceAndreas Rheinhardt2021-08-30
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroskadec: Fix heap-buffer overflow upon gigantic timestampsAndreas Rheinhardt2021-08-30
| | | | | | | | | | | | | | | | | | | The WebM DASH Manifest demuxer creates a comma-delimited list of all the timestamps of index entries. It allocates 20 bytes per timestamp; yet the largest 64bit numbers have 20 decimal digits (for int64_t it can be '-'+ 19 digits), so that one needs 21B per entry because of the comma (resp. the final NUL). The code uses snprintf, but snprintf returns the strlen of the string that would have been written had the supplied buffer been big enough. And if this is 21, then the next entry is written at an offset of 21 from the current position. So if enough such entries exist, the buffer won't suffice. This commit fixes this by replacing the allocation of buffer for the supposedly worst-case with dynamic allocations by using an AVBPrint. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mov: Check dts for overflow in mov_read_trun()Michael Niedermayer2021-08-29
| | | | | | | | Fixes: signed integer overflow: 9223372034248226491 + 3275247799 cannot be represented in type 'long' Fixes: clusterfuzz-testcase-minimized-audio_decoder_fuzzer-4538729166077952 Reported-by: Matt Wolenetz <wolenetz@google.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/avidec: Use 64bit for frame number in odml index parsingMichael Niedermayer2021-08-28
| | | | | | | | Fixes: signed integer overflow: 1179337772 + 1392508928 cannot be represented in type 'int' Fixes: 34088/clusterfuzz-testcase-minimized-ffmpeg_dem_AVI_fuzzer-5846945303232512 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/flac_picture: ReindentationAndreas Rheinhardt2021-08-28
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/flac_picture: Simplify parsing titleAndreas Rheinhardt2021-08-28
| | | | | | | Don't allocate the buffer for the title ourselves, leave it to av_dict_set(). This simplifies freeing. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/flac_picture: Try to reuse buffer for attached pictureAndreas Rheinhardt2021-08-28
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/oggparsevorbis: Avoid tmp bufs when parsing VorbisCommentAndreas Rheinhardt2021-08-28
| | | | | | | | | | | | | | | | | | | | | | | | A single VorbisComment consists of a length field and a non-NUL-terminated string of the form "key=value". Up until now, when parsing such a VorbisComment, zero-terminated duplicates of key and value would be created. This is wasteful if these duplicates are freed shortly afterwards, as happens in particular in case of attached pictures: In this case value is base64 encoded and only needed to decode the actual data. Therefore this commit changes this: The buffer is temporarily modified so that both key and value are zero-terminated. Then the data is used in-place and restored to its original state afterwards. This requires that the buffer has at least one byte of padding. All buffers currently have AV_INPUT_BUFFER_PADDING_SIZE bytes padding, so this is ok. Finally, this also fixes weird behaviour from ogm_chapter(): It sometimes freed given to it, leaving the caller with dangling pointers. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/oggparsevorbis: Factor parsing a single VorbisComment outAndreas Rheinhardt2021-08-28
| | | | | | This is in preparation for further commits. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/movenc: Avoid calling strlen multiple timesAndreas Rheinhardt2021-08-27
| | | | | Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/vorbiscomment: Don't compute strlen twiceAndreas Rheinhardt2021-08-27
| | | | | Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/aviobuf: Use ffio_fill for paddingAndreas Rheinhardt2021-08-25
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/aviobuf: Avoid allocation when using dynamic bufferAndreas Rheinhardt2021-08-25
| | | | | | | This can be achieved by allocating the AVIOContext and the dynamic buffer's opaque and internal write buffer together. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/avio: Move internal AVIOContext fields to avio_internal.hAndreas Rheinhardt2021-08-25
| | | | | | | | | | | | | | Currently AVIOContext's private fields are all over AVIOContext. This commit moves them into a new structure in avio_internal.h instead. Said structure contains the public AVIOContext as its first element in order to avoid having to allocate a separate AVIOContextInternal which is costly for those use cases where one just wants to access an already existing buffer via the AVIOContext-API. For these cases ffio_init_context() can't fail and always returned zero, which was typically not checked. Therefore it has been made to not return anything. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/aviobuf: Make ffio_set_buf_size() staticAndreas Rheinhardt2021-08-25
| | | | | | Possible since 9c3adb7ce23522dcceb264bc0bffd3592dd3e1a5. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Move ffio_limit() to aviobufAndreas Rheinhardt2021-08-25
| | | | | | | | It is the more natural place for it given that it only deals with I/O; in fact, the function already has the ffio prefix and its declaration already is in avio_internal.h. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroskadec: Read RealAudio extradata directlyAndreas Rheinhardt2021-08-25
| | | | | | Don't use the avio-API to read a few bytes at fixed offsets. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/aviobuf: Avoid calling function twice due to FFMAX()Andreas Rheinhardt2021-08-25
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/movenc: add support for TTML muxingJan Ekström2021-08-25
| | | | | | | | | | | Includes basic support for both the ISMV ('dfxp') and MP4 ('stpp') methods. This initial version also foregoes fragmentation support in case the built-in sample squashing is to be utilized, as this eases the initial review. Additionally, add basic tests for both muxing modes in MP4. Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
* avformat/ttml: split TTML paragraph based or not check into headerJan Ekström2021-08-25
| | | | | | This way it can be re-utilized in movenc. Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
* avformat/matroskaenc: Only compile functions when neededAndreas Rheinhardt2021-08-24
| | | | | | Fixes unused function warnings in case e.g. the WebM muxer is disabled. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroskadec: Include webm_dash_manifest demuxer only if enabledAndreas Rheinhardt2021-08-24
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroskaenc: Pass dispositions through unchanged by defaultAndreas Rheinhardt2021-08-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Up until now, the Matroska muxer did not use the dispositions it is given as-is; instead it by default overrode the disposition of the first track of a kind (audio, video, subtitles) if no track of this kind has the default disposition set. And up until recently, it also enforced by default that no more than one track of each kind be marked as default. The rationale for the former is that there are lots of containers which lack the concept of default streams, so that it is not uncommon for no stream to be marked as default at all; the rationale for the latter was that up until recently, it was dubious whether the Matroska specification allowed more than one default stream for track type (e.g. mkvmerge disallowed it). It was this point which led to the implementation of the above mentioned behaviour inspired by mkvmerge. Yet the Matroska specifications have changed and now explicitly allow to set more than one track of each type as default, so that the main reason of not using the dispositions as-is was rendered moot. Therefore this commit changes the default to pass the disposition through. The matroska-mpegts-remux FATE-test has been updated to still use the old "infer" mode so that it is still covered by FATE; the matroska-zero-length-block test has also been updated to cover the infer_no_subs mode. The references for lots of other FATE tests needed to be updated because of a newly added FlagDefault element with value zero (whereas a FlagDefault with value 1 needn't be coded at all, as it coincided with the default value of said element). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroskaenc: Allow to set multiple streams as defaultAndreas Rheinhardt2021-08-24
| | | | | | | | | | The Matroska specifications have evolved and now allow to mark multiple tracks of the same kind as default (whether this was legal or not before was dubious; e.g. mkvmerge disallowed it). Yet when the Matroska muxer is set to infer default dispositions if absent, it also enforced the now outdated restriction. So update this. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/crcenc: Simplify writing trailerAndreas Rheinhardt2021-08-24
| | | | | Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/av1dec: Disallow seeking by bytesAndreas Rheinhardt2021-08-23
| | | | | | | | | The low overhead OBU format provides no means to resync after performing a byte-based seek; in other words: Byte based seeking is just not supported. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/av1dec: Flush BSF upon seekingAndreas Rheinhardt2021-08-23
| | | | | | | | | | | | | | The av1_merge_frame BSF outputs its cached data when it sees the beginning of a new frame, i.e. when it sees a temporal delimiter OBU. Therefore it typically has a temporal delimiter OBU cached after outputting a packet. This implies that the OBU demuxer must flush its BSF upon seeking because otherwise the first frame returned after a seek consists of an old temporal delimiter OBU only. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/utils: Also set io_repositioned for generic seekingAndreas Rheinhardt2021-08-23
| | | | | | | | It allows demuxers to perform certain tasks after a successful generic seek. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/av1dec: Deduplicate Annex B and low overhead OBU AV1 demuxerAndreas Rheinhardt2021-08-23
| | | | | Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/av1dec: Set position of AVPackets given to BSFAndreas Rheinhardt2021-08-23
| | | | | Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mov: add AVFMT_SHOW_IDS flagGyan Doshi2021-08-22
| | | | | | The MOV muxer can store streamids as track ids but they aren't visible when probing the result via lavf/dump or ffprobe due to lack of this flag in the demuxer.
* lavf/concatdec: support per-file optionsNicolas George2021-08-22
|
* libavformat/concatdec: remove support for unsafe=-1Nicolas George2021-08-22
| | | | | It only makes sense as the default value, but it is not the default since 689211d5727231c3fe92762d224dbadebdbf4e30.
* avformat/hlsenc: minus subtitle streams count when subtitle stream between ↵Steven Liu2021-08-19
| | | | | | | | | | | | | | | | | | video and audio streams because subtitles streams will be written to webvtt m3u8 list so the stream index should minus subtitles streams count when subtitle between audio and video streams. testcase: before patch: ffmpeg -i input -map 0:a:0 -map 0:s:0 -map 0:v:0 -f hls aaaa.m3u8 will EXC_BAD_ACCESS after patch: ffmpeg -i input -map 0:a:0 -map 0:s:0 -map 0:v:0 -f hls aaaa.m3u8 will ok Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
* avformat/hlsenc: set http options before use delete http methodSteven Liu2021-08-19
| | | | | | | Fix ticket: 9338 Set options which set by user from parent options. Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
* movenc: Get rid of frag_startHu Weiwen2021-08-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "frag_start" is redundant, and every occurance can be replaced with cluster[0].dts - start_dts The proof of no behaviour changes: (All line number below is based on commit bff7d662d728) "frag_start" is read at 4 place (with all possible call stacks): mov_write_packet ... mov_flush_fragment mov_write_moof_tag mov_write_moof_tag_internal mov_write_traf_tag mov_write_tfxd_tag (#1) mov_write_tfdt_tag (#2) mov_add_tfra_entries (#3) mov_write_sidx_tags mov_write_sidx_tag (#4) mov_write_trailer mov_auto_flush_fragment mov_flush_fragment ... (#1 #2 #3 #4) mov_write_sidx_tags mov_write_sidx_tag (#4) shift_data compute_sidx_size get_sidx_size mov_write_sidx_tags mov_write_sidx_tag (#4) All read happens in "mov_write_trailer" and "mov_write_moof_tag". So we need to prove no behaviour change in these two functions. Condition 1: for every track that have "trk->entry == 0", trk->frag_start == trk->track_duration. Condition 2: for every track that have "trk->entry > 0", trk->frag_start == trk->cluster[0].dts - trk->start_dts. Definition 1: "Before flush" means just before the invocation of "mov_flush_fragment", except for the auto-flush case in "mov_write_single_packet", which means before L5934. Lemma 1: If Condition 1 & 2 is true before flush, Condition 1 & 2 is still true after "mov_flush_fragment" returns. Proof: No update to the tracks that have "trk->entry == 0" before flushing, so we only consider tracks that have "trk->entry > 0": Case 1: !moov_written and moov will be written in this iteration trk->entry = 0 L5366 trk->frag_start == trk->cluster[0].dts - trk->start_dts Lemma condition trk->frag_start += trk->start_dts + trk->track_duration - trk->cluster[0].dts; L5363 So trk->entry == 0 && trk->frag_start == trk->track_duration Case 2: !moov_written and moov will NOT be written in this iteration nothing changed Case 3: moov_written trk->entry = 0 L5445 trk->frag_start == trk->cluster[0].dts - trk->start_dts Lemma condition trk->frag_start += trk->start_dts + trk->track_duration - trk->cluster[0].dts; L5444 So trk->entry == 0 && trk->frag_start == trk->track_duration Note that trk->track_duration may be updated for the tracks that have "trk->entry > 0" (mov_write_moov_tag will update track_duration of "tmcd" track, but it must have 1 entry). But in all case, trk->frag_start is also updated to consider the new value. Lemma 2: If Condition 1 & 2 is true before "ff_mov_write_packet" invocation, Condition 1 & 2 is still true after it returns. Proof: Only the track corresponding to the pkt is updated, and no update to relevant variables if trk->entry > 0 before invocation. So we only need to prove "trk->frag_start == trk->cluster[0].dts - trk->start_dts" after trk->entry increase from 0 to 1. Case 1: trk->start_dts == AV_NOPTS_VALUE Case 1.1: trk->frag_discont && use_editlist trk->cluster[0].dts = pkt->dts at L5741 trk->frag_start = pkt->pts at L5785 trk->start_dts = pkt->dts - pkt->pts at L5786 So trk->frag_start == trk->cluster[0].dts - trk->start_dts Case 1.2: trk->frag_discont && !use_editlist trk->cluster[0].dts = pkt->dts at L5741 trk->frag_start = pkt->dts at L5790 trk->start_dts = 0 at L5791 So trk->frag_start == trk->cluster[0].dts - trk->start_dts Case 1.3: !trk->frag_discont trk->cluster[0].dts = pkt->dts at L5741 trk->frag_start = 0 init trk->start_dts = pkt->dts at L5779 So trk->frag_start == trk->cluster[0].dts - trk->start_dts Case 2: trk->start_dts != AV_NOPTS_VALUE Case 2.1: trk->frag_discont trk->cluster[0].dts = pkt->dts at L5741 trk->frag_start = pkt->dts - trk->start_dts at L5763 So trk->frag_start == trk->cluster[0].dts - trk->start_dts Case 2.2: !trk->frag_discont trk->cluster[0].dts = trk->start_dts + trk->track_duration at L5749 trk->track_duration == trk->frag_start Lemma condition So trk->frag_start == trk->cluster[0].dts - trk->start_dts Lemma 3: Condition 1 & 2 is true in all case before and after "ff_mov_write_packet" invocation, before flush and after "mov_flush_fragment" returns. Proof: All updates to relevant variable happen either in "ff_mov_write_packet", or during flush. And Condition 1 & 2 is true initially. So with lemma 1 & 2, we can prove this use induction. Noticed that all read of "frag_start" only happen in "trk->entry > 0" branch. Now we need to prove Condition 2 is true before each read. Because no update to variables relevant to Condition 2 between "before flush" and "mov_write_moof_tag" invocation, we can conclude Condition 2 is true before every invocation of "mov_write_moof_tag". No behaviour change in "mov_write_moof_tag" is proved. In "mov_write_trailer", No update to relevant variables after the last flush and before the invocation of "mov_write_sidx_tag". So no behaviour change to "mov_write_trailer" is proved. Q.E.D. Signed-off-by: Hu Weiwen <sehuww@mail.scut.edu.cn> Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Ensure no separate moof written for empty trackHu Weiwen2021-08-18
| | | | | | | | track->mdat_buf can be not NULL while the track is still empty if the last packet write failed. Signed-off-by: Hu Weiwen <sehuww@mail.scut.edu.cn> Signed-off-by: Martin Storsjö <martin@martin.st>
* avformat/isom_tags: prefer in24 for 24bit PCM in MOVJan Ekström2021-08-14
| | | | | | | | | | | | | In 1c42fd93236e7869ef4d9fe3650dd3e951387321 the ipcm identifier was added in order to demux additional raw audio from Sony MP4 files. Unfortunately, it was not noticed that this same list is utilized for muxing as well, thus causing ipcm to get preferred compared to the identifier officially specified in QTFF documentation. This fixes the order of preference for 24bit PCM, where ipcm is still allowed, but in24 is the first match - thus being preferred. Fixes fate-acodec-pcm-s24be.
* libavformat/isom_tags.c: add ipcm to list of tagsStephen Hutchinson2021-08-14
| | | | Fixes http://trac.ffmpeg.org/ticket/9219
* avformat/mxfdec: store parition score instead of partition pointer in metadataMarton Balint2021-08-14
| | | | | | | | | Partition struct may be reallocated, so let's store the score directly in order to avoid use-after-free. Also mxf->current_partition might be null when reading some local tags. Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/oggdec: Use av_realloc_array()Andreas Rheinhardt2021-08-12
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* libavformat/file.c: 'file_delete()' and 'file_move()' require ↵Michael Witten2021-08-12
| | | | | | | | 'CONFIG_FILE_PROTOCOL' This quashes 2 warnings when the 'file' protocol is not enabled. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* movenc: Don't try to fix the fragment end duration if none will be writtenMartin Storsjö2021-08-10
| | | | | | | | | If autoflushing on a new packet (e.g. due to the frag_every_frame flag being set), there's no samples to be written in the new fragment, so we can't overwrite the track duration in order to make it line up with the next packet to be written. Signed-off-by: Martin Storsjö <martin@martin.st>
* avformat/paf: read frame rate from header @0x88Gregory Montoir2021-08-10
| | | | Signed-off-by: Gregory Montoir <cyx@users.sourceforge.net>
* avformat/mxfdec: make MXFMetadataSet part of all metadata setsMarton Balint2021-08-08
| | | | | | | The code expects every kind of metadata set to start with the generic metadata set attributes. Signed-off-by: Marton Balint <cus@passwd.hu>