FFmpeg  4.4.9
wavenc.c
Go to the documentation of this file.
1 /*
2  * WAV muxer
3  * Copyright (c) 2001, 2002 Fabrice Bellard
4  *
5  * Sony Wave64 muxer
6  * Copyright (c) 2012 Paul B Mahol
7  *
8  * WAV muxer RF64 support
9  * Copyright (c) 2013 Daniel Verkamp <daniel@drv.nu>
10  *
11  * EBU Tech 3285 - Supplement 3 - Peak Envelope Chunk encoder
12  * Copyright (c) 2014 Georg Lippitsch <georg.lippitsch@gmx.at>
13  *
14  * This file is part of FFmpeg.
15  *
16  * FFmpeg is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU Lesser General Public
18  * License as published by the Free Software Foundation; either
19  * version 2.1 of the License, or (at your option) any later version.
20  *
21  * FFmpeg is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24  * Lesser General Public License for more details.
25  *
26  * You should have received a copy of the GNU Lesser General Public
27  * License along with FFmpeg; if not, write to the Free Software
28  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29  */
30 
31 #include <stdint.h>
32 #include <string.h>
33 
34 #include "libavutil/avstring.h"
35 #include "libavutil/dict.h"
36 #include "libavutil/common.h"
37 #include "libavutil/intreadwrite.h"
38 #include "libavutil/mathematics.h"
39 #include "libavutil/opt.h"
40 #include "libavutil/time.h"
42 
43 #include "avformat.h"
44 #include "avio.h"
45 #include "avio_internal.h"
46 #include "internal.h"
47 #include "riff.h"
48 
49 #define RF64_AUTO (-1)
50 #define RF64_NEVER 0
51 #define RF64_ALWAYS 1
52 
53 typedef enum {
54  PEAK_OFF = 0,
56  PEAK_ONLY
58 
59 typedef enum {
63 
64 typedef struct WAVMuxContext {
65  const AVClass *class;
72  uint32_t peak_num_frames;
73  unsigned peak_outbuf_size;
75  unsigned size_increment;
80  int rf64;
85  int peak_ppv;
86  int peak_bps;
88 
89 #if CONFIG_WAV_MUXER
90 static inline void bwf_write_bext_string(AVFormatContext *s, const char *key, int maxlen)
91 {
93  size_t len = 0;
94 
95  if (tag = av_dict_get(s->metadata, key, NULL, 0)) {
96  len = strlen(tag->value);
97  len = FFMIN(len, maxlen);
98  avio_write(s->pb, tag->value, len);
99  }
100 
101  ffio_fill(s->pb, 0, maxlen - len);
102 }
103 
104 static void bwf_write_bext_chunk(AVFormatContext *s)
105 {
106  AVDictionaryEntry *tmp_tag;
107  uint64_t time_reference = 0;
108  int64_t bext = ff_start_tag(s->pb, "bext");
109 
110  bwf_write_bext_string(s, "description", 256);
111  bwf_write_bext_string(s, "originator", 32);
112  bwf_write_bext_string(s, "originator_reference", 32);
113  bwf_write_bext_string(s, "origination_date", 10);
114  bwf_write_bext_string(s, "origination_time", 8);
115 
116  if (tmp_tag = av_dict_get(s->metadata, "time_reference", NULL, 0))
117  time_reference = strtoll(tmp_tag->value, NULL, 10);
118  avio_wl64(s->pb, time_reference);
119  avio_wl16(s->pb, 1); // set version to 1
120 
121  if ((tmp_tag = av_dict_get(s->metadata, "umid", NULL, 0)) && strlen(tmp_tag->value) > 2) {
122  unsigned char umidpart_str[17] = {0};
123  int64_t i;
124  uint64_t umidpart;
125  size_t len = strlen(tmp_tag->value+2);
126 
127  for (i = 0; i < len/16; i++) {
128  memcpy(umidpart_str, tmp_tag->value + 2 + (i*16), 16);
129  umidpart = strtoll(umidpart_str, NULL, 16);
130  avio_wb64(s->pb, umidpart);
131  }
132  ffio_fill(s->pb, 0, 64 - i*8);
133  } else
134  ffio_fill(s->pb, 0, 64); // zero UMID
135 
136  ffio_fill(s->pb, 0, 190); // Reserved
137 
138  if (tmp_tag = av_dict_get(s->metadata, "coding_history", NULL, 0))
139  avio_put_str(s->pb, tmp_tag->value);
140 
141  ff_end_tag(s->pb, bext);
142 }
143 
144 static av_cold void wav_deinit(AVFormatContext *s)
145 {
146  WAVMuxContext *wav = s->priv_data;
147 
148  av_freep(&wav->peak_maxpos);
149  av_freep(&wav->peak_maxneg);
150  av_freep(&wav->peak_output);
151 }
152 
153 static av_cold int peak_init_writer(AVFormatContext *s)
154 {
155  WAVMuxContext *wav = s->priv_data;
156  AVCodecParameters *par = s->streams[0]->codecpar;
157 
158  if (par->codec_id != AV_CODEC_ID_PCM_S8 &&
160  par->codec_id != AV_CODEC_ID_PCM_U8 &&
162  av_log(s, AV_LOG_ERROR, "Codec %s not supported for Peak Chunk\n",
163  avcodec_get_name(par->codec_id));
164  return -1;
165  }
166 
167  wav->peak_bps = av_get_bits_per_sample(par->codec_id) / 8;
168 
169  if (wav->peak_bps == 1 && wav->peak_format == PEAK_FORMAT_UINT16) {
171  "Writing 16 bit peak for 8 bit audio does not make sense\n");
172  return AVERROR(EINVAL);
173  }
174  if (par->channels <= 0 ||
175  par->channels > INT_MAX / (wav->peak_bps * wav->peak_ppv))
176  return AVERROR(ERANGE);
177  wav->size_increment = par->channels * wav->peak_bps * wav->peak_ppv;
178 
179  wav->peak_maxpos = av_mallocz_array(par->channels, sizeof(*wav->peak_maxpos));
180  wav->peak_maxneg = av_mallocz_array(par->channels, sizeof(*wav->peak_maxneg));
181  if (!wav->peak_maxpos || !wav->peak_maxneg)
182  goto nomem;
183 
184  return 0;
185 
186 nomem:
187  av_log(s, AV_LOG_ERROR, "Out of memory\n");
188  return AVERROR(ENOMEM);
189 }
190 
191 static int peak_write_frame(AVFormatContext *s)
192 {
193  WAVMuxContext *wav = s->priv_data;
194  AVCodecParameters *par = s->streams[0]->codecpar;
195  unsigned new_size = wav->peak_outbuf_bytes + wav->size_increment;
196  uint8_t *tmp;
197  int c;
198 
199  if (new_size > INT_MAX) {
200  wav->write_peak = PEAK_OFF;
201  return AVERROR(ERANGE);
202  }
203  tmp = av_fast_realloc(wav->peak_output, &wav->peak_outbuf_size, new_size);
204  if (!tmp) {
205  wav->write_peak = PEAK_OFF;
206  return AVERROR(ENOMEM);
207  }
208  wav->peak_output = tmp;
209 
210  for (c = 0; c < par->channels; c++) {
211  wav->peak_maxneg[c] = -wav->peak_maxneg[c];
212 
213  if (wav->peak_bps == 2 && wav->peak_format == PEAK_FORMAT_UINT8) {
214  wav->peak_maxpos[c] = wav->peak_maxpos[c] / 256;
215  wav->peak_maxneg[c] = wav->peak_maxneg[c] / 256;
216  }
217 
218  if (wav->peak_ppv == 1)
219  wav->peak_maxpos[c] =
220  FFMAX(wav->peak_maxpos[c], wav->peak_maxneg[c]);
221 
222  if (wav->peak_format == PEAK_FORMAT_UINT8) {
223  wav->peak_output[wav->peak_outbuf_bytes++] =
224  wav->peak_maxpos[c];
225  if (wav->peak_ppv == 2) {
226  wav->peak_output[wav->peak_outbuf_bytes++] =
227  wav->peak_maxneg[c];
228  }
229  } else {
231  wav->peak_maxpos[c]);
232  wav->peak_outbuf_bytes += 2;
233  if (wav->peak_ppv == 2) {
235  wav->peak_maxneg[c]);
236  wav->peak_outbuf_bytes += 2;
237  }
238  }
239  wav->peak_maxpos[c] = 0;
240  wav->peak_maxneg[c] = 0;
241  }
242  wav->peak_num_frames++;
243 
244  return 0;
245 }
246 
247 static int peak_write_chunk(AVFormatContext *s)
248 {
249  WAVMuxContext *wav = s->priv_data;
250  AVIOContext *pb = s->pb;
251  AVCodecParameters *par = s->streams[0]->codecpar;
252  int64_t peak = ff_start_tag(s->pb, "levl");
253  int64_t now0;
254  time_t now_secs;
255  char timestamp[28];
256 
257  /* Peak frame of incomplete block at end */
258  if (wav->peak_block_pos) {
259  int ret = peak_write_frame(s);
260  if (ret < 0)
261  return ret;
262  }
263 
264  memset(timestamp, 0, sizeof(timestamp));
265  if (!(s->flags & AVFMT_FLAG_BITEXACT)) {
266  struct tm tmpbuf;
267  av_log(s, AV_LOG_INFO, "Writing local time and date to Peak Envelope Chunk\n");
268  now0 = av_gettime();
269  now_secs = now0 / 1000000;
270  if (strftime(timestamp, sizeof(timestamp), "%Y:%m:%d:%H:%M:%S:", localtime_r(&now_secs, &tmpbuf))) {
271  av_strlcatf(timestamp, sizeof(timestamp), "%03d", (int)((now0 / 1000) % 1000));
272  } else {
273  av_log(s, AV_LOG_ERROR, "Failed to write timestamp\n");
274  return -1;
275  }
276  }
277 
278  avio_wl32(pb, 1); /* version */
279  avio_wl32(pb, wav->peak_format); /* 8 or 16 bit */
280  avio_wl32(pb, wav->peak_ppv); /* positive and negative */
281  avio_wl32(pb, wav->peak_block_size); /* frames per value */
282  avio_wl32(pb, par->channels); /* number of channels */
283  avio_wl32(pb, wav->peak_num_frames); /* number of peak frames */
284  avio_wl32(pb, -1); /* audio sample frame position (not implemented) */
285  avio_wl32(pb, 128); /* equal to size of header */
286  avio_write(pb, timestamp, 28); /* ASCII time stamp */
287  ffio_fill(pb, 0, 60);
288 
289  avio_write(pb, wav->peak_output, wav->peak_outbuf_bytes);
290 
291  ff_end_tag(pb, peak);
292 
293  if (!wav->data)
294  wav->data = peak;
295 
296  return 0;
297 }
298 
299 static int wav_write_header(AVFormatContext *s)
300 {
301  WAVMuxContext *wav = s->priv_data;
302  AVIOContext *pb = s->pb;
303  int64_t fmt;
304 
305  if (s->nb_streams != 1) {
306  av_log(s, AV_LOG_ERROR, "WAVE files have exactly one stream\n");
307  return AVERROR(EINVAL);
308  }
309 
310  if (wav->rf64 == RF64_ALWAYS) {
311  ffio_wfourcc(pb, "RF64");
312  avio_wl32(pb, -1); /* RF64 chunk size: use size in ds64 */
313  } else {
314  ffio_wfourcc(pb, "RIFF");
315  avio_wl32(pb, -1); /* file length */
316  }
317 
318  ffio_wfourcc(pb, "WAVE");
319 
320  if (wav->rf64 != RF64_NEVER) {
321  /* write empty ds64 chunk or JUNK chunk to reserve space for ds64 */
322  ffio_wfourcc(pb, wav->rf64 == RF64_ALWAYS ? "ds64" : "JUNK");
323  avio_wl32(pb, 28); /* chunk size */
324  wav->ds64 = avio_tell(pb);
325  ffio_fill(pb, 0, 28);
326  }
327 
328  if (wav->write_peak != PEAK_ONLY) {
329  /* format header */
330  fmt = ff_start_tag(pb, "fmt ");
331  if (ff_put_wav_header(s, pb, s->streams[0]->codecpar, 0) < 0) {
332  av_log(s, AV_LOG_ERROR, "Codec %s not supported in WAVE format\n",
333  avcodec_get_name(s->streams[0]->codecpar->codec_id));
334  return AVERROR(ENOSYS);
335  }
336  ff_end_tag(pb, fmt);
337  }
338 
339  if (s->streams[0]->codecpar->codec_tag != 0x01 /* hence for all other than PCM */
340  && (s->pb->seekable & AVIO_SEEKABLE_NORMAL)) {
341  wav->fact_pos = ff_start_tag(pb, "fact");
342  avio_wl32(pb, 0);
343  ff_end_tag(pb, wav->fact_pos);
344  }
345 
346  if (wav->write_bext)
347  bwf_write_bext_chunk(s);
348 
349  if (wav->write_peak) {
350  int ret;
351  if ((ret = peak_init_writer(s)) < 0)
352  return ret;
353  }
354 
355  avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codecpar->sample_rate);
356  wav->maxpts = wav->last_duration = 0;
357  wav->minpts = INT64_MAX;
358 
359  if (wav->write_peak != PEAK_ONLY) {
360  /* info header */
362 
363  /* data header */
364  wav->data = ff_start_tag(pb, "data");
365  }
366 
367  return 0;
368 }
369 
370 static int wav_write_packet(AVFormatContext *s, AVPacket *pkt)
371 {
372  AVIOContext *pb = s->pb;
373  WAVMuxContext *wav = s->priv_data;
374 
375  if (wav->write_peak != PEAK_ONLY)
376  avio_write(pb, pkt->data, pkt->size);
377 
378  if (wav->write_peak) {
379  int c = wav->peak_channel;
380  int i;
381  for (i = 0; i < pkt->size; i += wav->peak_bps) {
382  if (wav->peak_bps == 1) {
383  wav->peak_maxpos[c] = FFMAX(wav->peak_maxpos[c], *(int8_t*)(pkt->data + i));
384  wav->peak_maxneg[c] = FFMIN(wav->peak_maxneg[c], *(int8_t*)(pkt->data + i));
385  } else {
386  wav->peak_maxpos[c] = FFMAX(wav->peak_maxpos[c], (int16_t)AV_RL16(pkt->data + i));
387  wav->peak_maxneg[c] = FFMIN(wav->peak_maxneg[c], (int16_t)AV_RL16(pkt->data + i));
388  }
389  if (++c == s->streams[0]->codecpar->channels) {
390  c = 0;
391  if (++wav->peak_block_pos == wav->peak_block_size) {
392  int ret = peak_write_frame(s);
393  if (ret < 0)
394  return ret;
395  wav->peak_block_pos = 0;
396  }
397  }
398  }
399  wav->peak_channel = c;
400  }
401 
402  if(pkt->pts != AV_NOPTS_VALUE) {
403  wav->minpts = FFMIN(wav->minpts, pkt->pts);
404  wav->maxpts = FFMAX(wav->maxpts, pkt->pts);
405  wav->last_duration = pkt->duration;
406  } else
407  av_log(s, AV_LOG_ERROR, "wav_write_packet: NOPTS\n");
408  return 0;
409 }
410 
411 static int wav_write_trailer(AVFormatContext *s)
412 {
413  AVIOContext *pb = s->pb;
414  WAVMuxContext *wav = s->priv_data;
415  int64_t file_size, data_size;
416  int64_t number_of_samples = 0;
417  int rf64 = 0;
418  int ret = 0;
419 
420  if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
421  if (wav->write_peak != PEAK_ONLY && avio_tell(pb) - wav->data < UINT32_MAX) {
422  ff_end_tag(pb, wav->data);
423  }
424 
425  if (wav->write_peak && wav->peak_output) {
426  ret = peak_write_chunk(s);
427  }
428 
429  /* update file size */
430  file_size = avio_tell(pb);
431  data_size = file_size - wav->data;
432  if (wav->rf64 == RF64_ALWAYS || (wav->rf64 == RF64_AUTO && file_size - 8 > UINT32_MAX)) {
433  rf64 = 1;
434  } else if (file_size - 8 <= UINT32_MAX) {
435  avio_seek(pb, 4, SEEK_SET);
436  avio_wl32(pb, (uint32_t)(file_size - 8));
437  avio_seek(pb, file_size, SEEK_SET);
438  } else {
440  "Filesize %"PRId64" invalid for wav, output file will be broken\n",
441  file_size);
442  }
443  number_of_samples = av_rescale_q(wav->maxpts - wav->minpts + wav->last_duration,
444  s->streams[0]->time_base,
445  av_make_q(1, s->streams[0]->codecpar->sample_rate));
446 
447  if(s->streams[0]->codecpar->codec_tag != 0x01) {
448  /* Update num_samps in fact chunk */
449  avio_seek(pb, wav->fact_pos, SEEK_SET);
450  if (rf64 || (wav->rf64 == RF64_AUTO && number_of_samples > UINT32_MAX)) {
451  rf64 = 1;
452  avio_wl32(pb, -1);
453  } else {
454  avio_wl32(pb, number_of_samples);
455  avio_seek(pb, file_size, SEEK_SET);
456  }
457  }
458 
459  if (rf64) {
460  /* overwrite RIFF with RF64 */
461  avio_seek(pb, 0, SEEK_SET);
462  ffio_wfourcc(pb, "RF64");
463  avio_wl32(pb, -1);
464 
465  /* write ds64 chunk (overwrite JUNK if rf64 == RF64_AUTO) */
466  avio_seek(pb, wav->ds64 - 8, SEEK_SET);
467  ffio_wfourcc(pb, "ds64");
468  avio_wl32(pb, 28); /* ds64 chunk size */
469  avio_wl64(pb, file_size - 8); /* RF64 chunk size */
470  avio_wl64(pb, data_size); /* data chunk size */
471  avio_wl64(pb, number_of_samples); /* fact chunk number of samples */
472  avio_wl32(pb, 0); /* number of table entries for non-'data' chunks */
473 
474  /* write -1 in data chunk size */
475  avio_seek(pb, wav->data - 4, SEEK_SET);
476  avio_wl32(pb, -1);
477 
478  avio_seek(pb, file_size, SEEK_SET);
479  }
480  }
481 
482  return ret;
483 }
484 
485 #define OFFSET(x) offsetof(WAVMuxContext, x)
486 #define ENC AV_OPT_FLAG_ENCODING_PARAM
487 static const AVOption options[] = {
488  { "write_bext", "Write BEXT chunk.", OFFSET(write_bext), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC },
489  { "write_peak", "Write Peak Envelope chunk.", OFFSET(write_peak), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, ENC, "peak" },
490  { "off", "Do not write peak chunk.", 0, AV_OPT_TYPE_CONST, { .i64 = PEAK_OFF }, 0, 0, ENC, "peak" },
491  { "on", "Append peak chunk after wav data.", 0, AV_OPT_TYPE_CONST, { .i64 = PEAK_ON }, 0, 0, ENC, "peak" },
492  { "only", "Write only peak chunk, omit wav data.", 0, AV_OPT_TYPE_CONST, { .i64 = PEAK_ONLY }, 0, 0, ENC, "peak" },
493  { "rf64", "Use RF64 header rather than RIFF for large files.", OFFSET(rf64), AV_OPT_TYPE_INT, { .i64 = RF64_NEVER },-1, 1, ENC, "rf64" },
494  { "auto", "Write RF64 header if file grows large enough.", 0, AV_OPT_TYPE_CONST, { .i64 = RF64_AUTO }, 0, 0, ENC, "rf64" },
495  { "always", "Always write RF64 header regardless of file size.", 0, AV_OPT_TYPE_CONST, { .i64 = RF64_ALWAYS }, 0, 0, ENC, "rf64" },
496  { "never", "Never write RF64 header regardless of file size.", 0, AV_OPT_TYPE_CONST, { .i64 = RF64_NEVER }, 0, 0, ENC, "rf64" },
497  { "peak_block_size", "Number of audio samples used to generate each peak frame.", OFFSET(peak_block_size), AV_OPT_TYPE_INT, { .i64 = 256 }, 0, 65536, ENC },
498  { "peak_format", "The format of the peak envelope data (1: uint8, 2: uint16).", OFFSET(peak_format), AV_OPT_TYPE_INT, { .i64 = PEAK_FORMAT_UINT16 }, PEAK_FORMAT_UINT8, PEAK_FORMAT_UINT16, ENC },
499  { "peak_ppv", "Number of peak points per peak value (1 or 2).", OFFSET(peak_ppv), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, 2, ENC },
500  { NULL },
501 };
502 
503 static const AVClass wav_muxer_class = {
504  .class_name = "WAV muxer",
505  .item_name = av_default_item_name,
506  .option = options,
507  .version = LIBAVUTIL_VERSION_INT,
508 };
509 
511  .name = "wav",
512  .long_name = NULL_IF_CONFIG_SMALL("WAV / WAVE (Waveform Audio)"),
513  .mime_type = "audio/x-wav",
514  .extensions = "wav",
515  .priv_data_size = sizeof(WAVMuxContext),
516  .audio_codec = AV_CODEC_ID_PCM_S16LE,
517  .video_codec = AV_CODEC_ID_NONE,
518  .write_header = wav_write_header,
519  .write_packet = wav_write_packet,
520  .write_trailer = wav_write_trailer,
521  .deinit = wav_deinit,
523  .codec_tag = ff_wav_codec_tags_list,
524  .priv_class = &wav_muxer_class,
525 };
526 #endif /* CONFIG_WAV_MUXER */
527 
528 #if CONFIG_W64_MUXER
529 #include "w64.h"
530 
531 static void start_guid(AVIOContext *pb, const uint8_t *guid, int64_t *pos)
532 {
533  *pos = avio_tell(pb);
534 
535  avio_write(pb, guid, 16);
536  avio_wl64(pb, INT64_MAX);
537 }
538 
539 static void end_guid(AVIOContext *pb, int64_t start)
540 {
541  int64_t end, pos = avio_tell(pb);
542 
543  end = FFALIGN(pos, 8);
544  ffio_fill(pb, 0, end - pos);
545  avio_seek(pb, start + 16, SEEK_SET);
546  avio_wl64(pb, end - start);
547  avio_seek(pb, end, SEEK_SET);
548 }
549 
550 static int w64_write_header(AVFormatContext *s)
551 {
552  WAVMuxContext *wav = s->priv_data;
553  AVIOContext *pb = s->pb;
554  int64_t start;
555  int ret;
556 
558  avio_wl64(pb, -1);
560  start_guid(pb, ff_w64_guid_fmt, &start);
561  if ((ret = ff_put_wav_header(s, pb, s->streams[0]->codecpar, 0)) < 0) {
562  av_log(s, AV_LOG_ERROR, "Codec %s not supported\n",
563  avcodec_get_name(s->streams[0]->codecpar->codec_id));
564  return ret;
565  }
566  end_guid(pb, start);
567 
568  if (s->streams[0]->codecpar->codec_tag != 0x01 /* hence for all other than PCM */
569  && (s->pb->seekable & AVIO_SEEKABLE_NORMAL)) {
570  start_guid(pb, ff_w64_guid_fact, &wav->fact_pos);
571  avio_wl64(pb, 0);
572  end_guid(pb, wav->fact_pos);
573  }
574 
575  start_guid(pb, ff_w64_guid_data, &wav->data);
576 
577  return 0;
578 }
579 
580 static int w64_write_trailer(AVFormatContext *s)
581 {
582  AVIOContext *pb = s->pb;
583  WAVMuxContext *wav = s->priv_data;
584  int64_t file_size;
585 
586  if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
587  end_guid(pb, wav->data);
588 
589  file_size = avio_tell(pb);
590  avio_seek(pb, 16, SEEK_SET);
591  avio_wl64(pb, file_size);
592 
593  if (s->streams[0]->codecpar->codec_tag != 0x01) {
594  int64_t number_of_samples;
595 
596  number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration,
597  s->streams[0]->codecpar->sample_rate * (int64_t)s->streams[0]->time_base.num,
598  s->streams[0]->time_base.den);
599  avio_seek(pb, wav->fact_pos + 24, SEEK_SET);
600  avio_wl64(pb, number_of_samples);
601  }
602 
603  avio_seek(pb, file_size, SEEK_SET);
604  }
605 
606  return 0;
607 }
608 
610  .name = "w64",
611  .long_name = NULL_IF_CONFIG_SMALL("Sony Wave64"),
612  .extensions = "w64",
613  .priv_data_size = sizeof(WAVMuxContext),
614  .audio_codec = AV_CODEC_ID_PCM_S16LE,
615  .video_codec = AV_CODEC_ID_NONE,
616  .write_header = w64_write_header,
617  .write_packet = wav_write_packet,
618  .write_trailer = w64_write_trailer,
620  .codec_tag = ff_wav_codec_tags_list,
621 };
622 #endif /* CONFIG_W64_MUXER */
AVOutputFormat ff_wav_muxer
AVOutputFormat ff_w64_muxer
#define av_cold
Definition: attributes.h:88
uint8_t
Main libavformat public API header.
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1380
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:472
Buffered I/O operations.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:260
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:450
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:382
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:462
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
Definition: aviobuf.c:398
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:557
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:456
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:230
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
Definition: avio_internal.h:58
void ffio_fill(AVIOContext *s, int b, int count)
Definition: aviobuf.c:216
#define AV_RL16
Definition: intreadwrite.h:42
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:101
#define ENC
Definition: caca.c:198
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define s(width, name)
Definition: cbs_vp9.c:257
static void deinit(AVFormatContext *s)
Definition: chromaprint.c:50
common internal and external API header
#define FFMIN(a, b)
Definition: common.h:105
#define FFMAX(a, b)
Definition: common.h:103
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
Public dictionary API.
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:740
const OptionDef options[]
#define OFFSET(x)
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:348
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:497
@ AV_CODEC_ID_PCM_U8
Definition: codec_id.h:318
@ AV_CODEC_ID_PCM_S16LE
Definition: codec_id.h:313
@ AV_CODEC_ID_NONE
Definition: codec_id.h:47
@ AV_CODEC_ID_PCM_S8
Definition: codec_id.h:317
@ AV_CODEC_ID_PCM_U16LE
Definition: codec_id.h:315
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:656
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
Definition: mem.c:478
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
Definition: mem.c:190
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
const char * key
int i
Definition: input.c:407
#define AV_WL16(p, v)
Definition: intreadwrite.h:412
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4944
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
#define FFALIGN(x, a)
Definition: macros.h:48
uint32_t tag
Definition: movenc.c:1611
AVOptions.
internal header for RIFF based (de)muxers do NOT include this in end user applications
void ff_end_tag(AVIOContext *pb, int64_t start)
Definition: riffenc.c:38
void ff_riff_write_info(AVFormatContext *s)
Write all recognized RIFF tags from s->metadata.
Definition: riffenc.c:334
int64_t ff_start_tag(AVIOContext *pb, const char *tag)
Definition: riffenc.c:31
int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int flags)
Write WAVEFORMAT header structure.
Definition: riffenc.c:54
const AVCodecTag *const ff_wav_codec_tags_list[]
unsigned int pos
Definition: spdifenc.c:412
Describe the class of an AVClass context structure.
Definition: log.h:67
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
int channels
Audio only.
Definition: codec_par.h:166
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
char * value
Definition: dict.h:83
Format I/O context.
Definition: avformat.h:1232
Bytestream IO Context.
Definition: avio.h:161
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:260
AVOption.
Definition: opt.h:248
const char * name
Definition: avformat.h:491
This structure stores compressed data.
Definition: packet.h:346
int size
Definition: packet.h:370
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:387
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:362
uint8_t * data
Definition: packet.h:369
int64_t minpts
Definition: wavenc.c:69
int16_t * peak_maxpos
Definition: wavenc.c:71
uint32_t peak_num_frames
Definition: wavenc.c:72
unsigned size_increment
Definition: wavenc.c:75
uint32_t peak_outbuf_bytes
Definition: wavenc.c:74
uint8_t * peak_output
Definition: wavenc.c:76
int rf64
Definition: wavenc.c:80
int write_bext
Definition: wavenc.c:78
int write_peak
Definition: wavenc.c:79
int64_t ds64
Definition: wavenc.c:68
int16_t * peak_maxneg
Definition: wavenc.c:71
int64_t maxpts
Definition: wavenc.c:70
int peak_ppv
Definition: wavenc.c:85
int peak_channel
Definition: wavenc.c:84
int peak_format
Definition: wavenc.c:82
int peak_block_pos
Definition: wavenc.c:83
int64_t data
Definition: wavenc.c:66
int peak_bps
Definition: wavenc.c:86
int64_t fact_pos
Definition: wavenc.c:67
unsigned peak_outbuf_size
Definition: wavenc.c:73
int last_duration
Definition: wavenc.c:77
int peak_block_size
Definition: wavenc.c:81
#define av_freep(p)
#define av_log(a,...)
static uint8_t tmp[11]
Definition: aes_ctr.c:27
AVPacket * pkt
Definition: movenc.c:59
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:39
#define localtime_r
Definition: time_internal.h:46
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:98
int len
static double c[64]
const uint8_t ff_w64_guid_wave[16]
Definition: w64.c:28
const uint8_t ff_w64_guid_riff[16]
Definition: w64.c:23
const uint8_t ff_w64_guid_data[16]
Definition: w64.c:42
const uint8_t ff_w64_guid_fact[16]
Definition: w64.c:38
const uint8_t ff_w64_guid_fmt[16]
Definition: w64.c:33
#define RF64_AUTO
Definition: wavenc.c:49
PeakFormat
Definition: wavenc.c:59
@ PEAK_FORMAT_UINT8
Definition: wavenc.c:60
@ PEAK_FORMAT_UINT16
Definition: wavenc.c:61
#define RF64_NEVER
Definition: wavenc.c:50
PeakType
Definition: wavenc.c:53
@ PEAK_ON
Definition: wavenc.c:55
@ PEAK_OFF
Definition: wavenc.c:54
@ PEAK_ONLY
Definition: wavenc.c:56
#define RF64_ALWAYS
Definition: wavenc.c:51