avformat/utils: Move creation-time functions to mux_utils

Only used by muxers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2022-05-06 16:40:53 +02:00
parent 533836b8e0
commit d78838414b
13 changed files with 60 additions and 51 deletions

View File

@ -22,12 +22,12 @@
#include <inttypes.h>
#include "libavutil/intreadwrite.h"
#include "libavutil/dict.h"
#include "avformat.h"
#include "avio_internal.h"
#include "apetag.h"
#include "internal.h"
#include "mux.h"
#define APE_TAG_FLAG_CONTAINS_HEADER (1U << 31)
#define APE_TAG_FLAG_LACKS_FOOTER (1 << 30)

View File

@ -29,6 +29,7 @@
#include "avlanguage.h"
#include "avio_internal.h"
#include "internal.h"
#include "mux.h"
#include "riff.h"
#include "asf.h"

View File

@ -23,6 +23,7 @@
#include "caf.h"
#include "isom.h"
#include "avio_internal.h"
#include "mux.h"
#include "libavutil/intfloat.h"
#include "libavutil/dict.h"

View File

@ -31,15 +31,14 @@
#include "libavutil/time_internal.h"
#include "avformat.h"
#include "internal.h"
#include "libavcodec/dv_profile.h"
#include "libavcodec/dv.h"
#include "dv.h"
#include "mux.h"
#include "libavutil/avassert.h"
#include "libavutil/fifo.h"
#include "libavutil/mathematics.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/opt.h"
#include "libavutil/timecode.h"
#define MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32-bit audio

View File

@ -28,6 +28,7 @@
#include "avio.h"
#include "avio_internal.h"
#include "id3v2.h"
#include "mux.h"
static void id3v2_put_size(AVIOContext *pb, int size)
{

View File

@ -881,26 +881,6 @@ void ff_format_io_close_default(AVFormatContext *s, AVIOContext *pb);
*/
int ff_is_http_proto(const char *filename);
/**
* Parse creation_time in AVFormatContext metadata if exists and warn if the
* parsing fails.
*
* @param s AVFormatContext
* @param timestamp parsed timestamp in microseconds, only set on successful parsing
* @param return_seconds set this to get the number of seconds in timestamp instead of microseconds
* @return 1 if OK, 0 if the metadata was not present, AVERROR(EINVAL) on parse error
*/
int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds);
/**
* Standardize creation_time metadata in AVFormatContext to an ISO-8601
* timestamp string.
*
* @param s AVFormatContext
* @return <0 on error
*/
int ff_standardize_creation_time(AVFormatContext *s);
struct AVBPrint;
/**
* Finalize buf into extradata and set its size appropriately.

View File

@ -27,6 +27,7 @@
#include "internal.h"
#include "lrc.h"
#include "metadata.h"
#include "mux.h"
#include "version.h"
#include "libavutil/dict.h"
#include "libavutil/log.h"

View File

@ -103,4 +103,24 @@ enum AVWriteUncodedFrameFlags {
*/
int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size);
/**
* Parse creation_time in AVFormatContext metadata if exists and warn if the
* parsing fails.
*
* @param s AVFormatContext
* @param timestamp parsed timestamp in microseconds, only set on successful parsing
* @param return_seconds set this to get the number of seconds in timestamp instead of microseconds
* @return 1 if OK, 0 if the metadata was not present, AVERROR(EINVAL) on parse error
*/
int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds);
/**
* Standardize creation_time metadata in AVFormatContext to an ISO-8601
* timestamp string.
*
* @param s AVFormatContext
* @return <0 on error
*/
int ff_standardize_creation_time(AVFormatContext *s);
#endif /* AVFORMAT_MUX_H */

View File

@ -19,6 +19,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/dict.h"
#include "libavutil/internal.h"
#include "libavutil/log.h"
#include "libavutil/mem.h"
#include "libavutil/parseutils.h"
#include "avformat.h"
#include "avio.h"
#include "internal.h"
@ -79,3 +84,29 @@ end:
av_free(buf);
return ret;
}
int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds)
{
AVDictionaryEntry *entry;
int64_t parsed_timestamp;
int ret;
if ((entry = av_dict_get(s->metadata, "creation_time", NULL, 0))) {
if ((ret = av_parse_time(&parsed_timestamp, entry->value, 0)) >= 0) {
*timestamp = return_seconds ? parsed_timestamp / 1000000 : parsed_timestamp;
return 1;
} else {
av_log(s, AV_LOG_WARNING, "Failed to parse creation_time %s\n", entry->value);
return ret;
}
}
return 0;
}
int ff_standardize_creation_time(AVFormatContext *s)
{
int64_t timestamp;
int ret = ff_parse_creation_time_metadata(s, &timestamp, 0);
if (ret == 1)
return avpriv_dict_set_timestamp(&s->metadata, "creation_time", timestamp);
return ret;
}

View File

@ -30,6 +30,7 @@
#include "libavutil/opt.h"
#include "libavcodec/bytestream.h"
#include "libavcodec/mpegaudiodata.h"
#include "mux.h"
#include "nut.h"
#include "internal.h"
#include "avio_internal.h"

View File

@ -26,6 +26,7 @@
#include "avformat.h"
#include "internal.h"
#include "mux.h"
#include "smjpeg.h"
typedef struct SMJPEGMuxContext {

View File

@ -29,7 +29,6 @@
#include "libavutil/dict.h"
#include "libavutil/internal.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixfmt.h"
#include "libavutil/thread.h"
#include "libavutil/time.h"
@ -1689,32 +1688,6 @@ int ff_is_http_proto(const char *filename) {
return proto ? (!av_strcasecmp(proto, "http") || !av_strcasecmp(proto, "https")) : 0;
}
int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds)
{
AVDictionaryEntry *entry;
int64_t parsed_timestamp;
int ret;
if ((entry = av_dict_get(s->metadata, "creation_time", NULL, 0))) {
if ((ret = av_parse_time(&parsed_timestamp, entry->value, 0)) >= 0) {
*timestamp = return_seconds ? parsed_timestamp / 1000000 : parsed_timestamp;
return 1;
} else {
av_log(s, AV_LOG_WARNING, "Failed to parse creation_time %s\n", entry->value);
return ret;
}
}
return 0;
}
int ff_standardize_creation_time(AVFormatContext *s)
{
int64_t timestamp;
int ret = ff_parse_creation_time_metadata(s, &timestamp, 0);
if (ret == 1)
return avpriv_dict_set_timestamp(&s->metadata, "creation_time", timestamp);
return ret;
}
int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf)
{
int ret;

View File

@ -25,12 +25,12 @@
* @author Zhentan Feng <spyfeng at gmail dot com>
*/
#include "libavutil/intreadwrite.h"
#include "libavutil/avassert.h"
#include "avformat.h"
#include "avio_internal.h"
#include "internal.h"
#include "mpegts.h"
#include "mux.h"
#include "wtv.h"
#define WTV_BIGSECTOR_SIZE (1 << WTV_BIGSECTOR_BITS)