30#include "config_components.h"
79 if (_utime(path, &ut) < 0)
81 struct timeval times[2] = {
82 { .tv_sec = sec, .tv_usec = usec },
83 { .tv_sec = sec, .tv_usec = usec },
85 if (utimes(path, times) < 0)
88 "Failed to set file modification time for %s\n", path);
104 const char *str = strrchr(
s->url,
'.');
105 img->split_planes = str
107 &&
s->nb_streams == 1
110 &&
desc->nb_components >= 3;
112 img->img_number =
img->start_img_number;
114 if (
img->update_filemtime) {
119 if (!proto || strcmp(proto,
"file")) {
121 "update_filemtime is only supported for local files, "
122 "it will be ignored\n");
123 img->update_filemtime = 0;
128 "No valid creation_time metadata found, "
129 "update_filemtime will be ignored\n");
130 img->update_filemtime = 0;
132 img->creation_ts = parsed_ts;
158 st->
id =
pkt->stream_index;
203 char* target[4] = {0};
205 char* filepaths[4] = {0};
215 }
else if (
img->use_strftime) {
217 struct tm *tm, tmpbuf;
221 }
else if (
img->frame_pts) {
230 if (
img->img_number ==
img->start_img_number) {
231 av_log(
s,
AV_LOG_WARNING,
"The specified filename '%s' does not contain an image sequence pattern or a pattern is invalid.\n",
s->url);
233 "Use a pattern such as %%03d for an image sequence or "
234 "use the -update option (with -frames:v 1 if needed) to write a single image.\n");
238 av_log(
s,
AV_LOG_ERROR,
"Cannot write more than one file with the same name. Are you missing the -update option or a sequence pattern?\n");
247 for (
i = 0;
i < 4;
i++) {
249 if (
img->use_rename) {
252 if (!
tmp[
i] || !target[
i]) {
267 if (
img->update_filemtime) {
275 if (!
img->split_planes ||
i+1 >=
desc->nb_components)
277 filename.str[filename.len - 1] =
"UVAx"[
i];
281 if (
img->split_planes) {
284 if (
desc->comp[0].depth >= 9) {
288 if (ysize + 2*usize + (
desc->nb_components > 3) * ysize >
pkt->size) {
297 if (
desc->nb_components > 3)
299 }
else if (
img->muxer) {
309 for (
i = 0;
i < 4 &&
tmp[
i];
i++) {
317 if (
img->update_filemtime) {
325 if (
offset == INT64_MIN ||
329 "Integer overflow computing file mtime, skipping\n");
337 for (
i = 0;
i < 4 && filepaths[
i];
i++)
372#define OFFSET(x) offsetof(VideoMuxData, x)
373#define ENC AV_OPT_FLAG_ENCODING_PARAM
376 {
"start_number",
"set first number in the sequence",
OFFSET(start_img_number),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX,
ENC },
379 {
"atomic_writing",
"write files atomically (using temporary files and renames)",
OFFSET(use_rename),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
ENC },
380 {
"protocol_opts",
"specify protocol options for the opened files",
OFFSET(protocol_opts),
AV_OPT_TYPE_DICT, {0}, 0, 0,
ENC },
381 {
"update_filemtime",
"set output file mtime from creation_time metadata plus frame offset",
OFFSET(update_filemtime),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
ENC },
385#if CONFIG_IMAGE2_MUXER
386static const AVClass img2mux_class = {
387 .class_name =
"image2 muxer",
396 .p.extensions =
"bmp,dpx,exr,jls,jpeg,jpg,jxs,jxl,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv,phm,"
397 "png,ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8,"
398 "im24,sunras,vbn,xbm,xface,pix,y,avif,qoi,hdr,wbmp",
405 .p.priv_class = &img2mux_class,
408#if CONFIG_IMAGE2PIPE_MUXER
410 .p.name =
"image2pipe",
static av_always_inline void update(AVFilterContext *ctx, AVFrame *insamples, int is_silence, int current_sample, int64_t nb_samples_notify, AVRational time_base)
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
int ff_rename(const char *url_src, const char *url_dst, void *logctx)
Wrap ffurl_move() and log if error happens.
#define AVIO_FLAG_WRITE
write-only
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
char * av_asprintf(const char *fmt,...)
Convenience header that includes libavutil's core.
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_UNLIMITED
#define i(width, name, range_min, range_max)
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
#define AV_CEIL_RSHIFT(a, b)
#define FF_COMPLIANCE_NORMAL
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
static void write_header(FFV1Context *f)
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
AVCodecID
Identify the syntax and semantics of the bitstream.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
av_warn_unused_result int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
#define AV_FRAME_FILENAME_FLAGS_MULTIPLE
Allow multiple d.
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_strftime(AVBPrint *buf, const char *fmt, const struct tm *tm)
Append a formatted date and time to a print buffer.
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
#define LIBAVUTIL_VERSION_INT
const IdStrMap ff_img_tags[]
static const AVOption muxoptions[]
static int write_packet(AVFormatContext *s, AVPacket *pkt)
static int write_packet_pipe(AVFormatContext *s, AVPacket *pkt)
static int write_and_close(AVFormatContext *s, AVIOContext **pb, const unsigned char *buf, int size)
static int write_muxed_file(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt)
static int query_codec(enum AVCodecID id, int std_compliance)
static void set_file_mtime(AVFormatContext *s, const char *path, int64_t ts_us)
static int write_header(AVFormatContext *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Memory handling functions.
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
This struct describes the properties of an encoded stream.
int height
The height of the video frame in pixels.
int width
The width of the video frame in pixels.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
AVIOContext * pb
I/O context.
This structure stores compressed data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int id
Format-specific stream ID.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
int64_t creation_ts
creation_time in microseconds since epoch
AVDictionary * protocol_opts
int split_planes
use independent file for each Y, U, V plane