Go to the documentation of this file.
59 fprintf(stderr,
"%s [-split] [-ismf] [-n basename] [-path-prefix prefix] "
60 "[-ismc-prefix prefix] [-output dir] file1 [file2] ...\n", argv0);
97 if (got_tag != expected_tag) {
98 char got_tag_str[4], expected_tag_str[4];
100 AV_WB32(expected_tag_str, expected_tag);
101 fprintf(stderr,
"wanted tag %.4s, got %.4s\n", expected_tag_str,
124 fprintf(stderr,
"short read, wanted %d, got %d\n",
len, got);
154 fprintf(stderr,
"Unable to open %s: %s\n", filename, errbuf);
178 int split,
int ismf,
const char* output_prefix)
180 char dirname[2048], filename[2048], idxname[2048];
181 int i, j,
ret = 0, fragment_ret;
185 snprintf(idxname,
sizeof(idxname),
"%s%s.ismf", output_prefix, basename);
186 out = fopen(idxname,
"w");
196 snprintf(dirname,
sizeof(dirname),
"%sQualityLevels(%d)", output_prefix, track->
bitrate);
198 if (mkdir(dirname, 0777) == -1 && errno != EEXIST) {
204 for (j = 0; j < track->
chunks; j++) {
205 snprintf(filename,
sizeof(filename),
"%s/Fragments(%s=%"PRId64
")",
216 if (fragment_ret != 0) {
217 fprintf(stderr,
"failed fragment %d in track %d (%s)\n", j,
241 fprintf(stderr,
"No sample duration in trun flags\n");
250 for (
i = 0;
i < entries &&
pos < end;
i++) {
251 int sample_duration = default_duration;
257 if (sample_duration < 0) {
258 fprintf(stderr,
"Negative sample duration %d\n", sample_duration);
263 max_pts =
FFMAX(max_pts,
pts + sample_duration);
264 dts += sample_duration;
268 return max_pts - first_pts;
276 int default_duration = 0;
290 while (
pos < traf_pos + traf_size) {
312 fprintf(stderr,
"Couldn't find trun\n");
317 fprintf(stderr,
"Couldn't find traf\n");
336 for (
i = start_index;
i < tracks->
nb_tracks && !track;
i++)
362 for (j = 0; j < ((fieldlength >> 4) & 3) + 1; j++)
364 for (j = 0; j < ((fieldlength >> 2) & 3) + 1; j++)
366 for (j = 0; j < ((fieldlength >> 0) & 3) + 1; j++)
388 fprintf(stderr,
"Calculated last chunk duration for track %d "
389 "was non-positive (%"PRId64
"), probably due to missing "
398 fprintf(stderr,
"corrected to %"PRId64
"\n",
403 fprintf(stderr,
"Track duration corrected to %"PRId64
"\n",
415 const char *file,
int split,
int ismf,
416 const char *basename,
const char* output_prefix)
419 const char* err_str =
"";
430 err_str =
"mfra size mismatch";
435 err_str =
"mfra tag mismatch";
445 err_str =
"error in write_fragments";
451 fprintf(stderr,
"Unable to read the MFRA atom in %s (%s)\n", file, err_str);
469 uint16_t sps_size, pps_size;
498 int ismf,
const char *basename,
499 const char* output_prefix)
502 int err = 0,
i, orig_tracks = tracks->
nb_tracks;
503 char errbuf[50], *ptr;
509 fprintf(stderr,
"Unable to open %s: %s\n", file, errbuf);
516 fprintf(stderr,
"Unable to identify %s: %s\n", file, errbuf);
521 fprintf(stderr,
"No streams found in %s\n", file);
530 fprintf(stderr,
"Skipping track %d in %s as it has zero bitrate\n",
552 if ((ptr = strrchr(file,
'/')))
553 track->
name = ptr + 1;
564 "Track %d in %s is neither video nor audio, skipping\n",
619 const char *output_prefix,
620 const char *path_prefix,
621 const char *ismc_prefix)
627 snprintf(filename,
sizeof(filename),
"%s%s.ism", output_prefix, basename);
628 out = fopen(filename,
"w");
633 fprintf(
out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
634 fprintf(
out,
"<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
635 fprintf(
out,
"\t<head>\n");
636 fprintf(
out,
"\t\t<meta name=\"clientManifestRelativePath\" "
637 "content=\"%s%s.ismc\" />\n", ismc_prefix, basename);
638 fprintf(
out,
"\t</head>\n");
639 fprintf(
out,
"\t<body>\n");
640 fprintf(
out,
"\t\t<switch>\n");
644 fprintf(
out,
"\t\t\t<%s src=\"%s%s\" systemBitrate=\"%d\">\n",
646 fprintf(
out,
"\t\t\t\t<param name=\"trackID\" value=\"%d\" "
647 "valueType=\"data\" />\n", track->
track_id);
648 fprintf(
out,
"\t\t\t</%s>\n",
type);
650 fprintf(
out,
"\t\t</switch>\n");
651 fprintf(
out,
"\t</body>\n");
652 fprintf(
out,
"</smil>\n");
662 int should_print_time_mismatch = 1;
668 fprintf(stderr,
"Mismatched duration of %s chunk %d in %s (%d) and %s (%d)\n",
670 should_print_time_mismatch = 1;
673 if (should_print_time_mismatch)
674 fprintf(stderr,
"Mismatched (start) time of %s chunk %d in %s (%d) and %s (%d)\n",
676 should_print_time_mismatch = 0;
680 fprintf(
out,
"\t\t<c n=\"%d\" d=\"%"PRId64
"\" ",
687 fprintf(
out,
"/>\n");
692 const char *output_prefix,
int split)
699 snprintf(filename,
sizeof(filename),
"%sManifest", output_prefix);
701 snprintf(filename,
sizeof(filename),
"%s%s.ismc", output_prefix, basename);
702 out = fopen(filename,
"w");
707 fprintf(
out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
708 fprintf(
out,
"<SmoothStreamingMedia MajorVersion=\"2\" MinorVersion=\"0\" "
709 "Duration=\"%"PRId64
"\">\n", tracks->
duration * 10);
712 struct Track *first_track = track;
715 "\t<StreamIndex Type=\"video\" QualityLevels=\"%d\" "
717 "Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n",
724 "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
725 "FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" "
726 "CodecPrivateData=\"",
730 fprintf(
out,
"\" />\n");
733 fprintf(stderr,
"Mismatched number of video chunks in %s (id: %d, chunks %d) and %s (id: %d, chunks %d)\n",
737 fprintf(
out,
"\t</StreamIndex>\n");
741 struct Track *first_track = track;
744 "\t<StreamIndex Type=\"audio\" QualityLevels=\"%d\" "
746 "Url=\"QualityLevels({bitrate})/Fragments(audio={start time})\">\n",
753 "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
754 "FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" "
755 "BitsPerSample=\"16\" PacketSize=\"%d\" "
756 "AudioTag=\"%d\" CodecPrivateData=\"",
761 fprintf(
out,
"\" />\n");
764 fprintf(stderr,
"Mismatched number of audio chunks in %s and %s\n",
768 fprintf(
out,
"\t</StreamIndex>\n");
770 fprintf(
out,
"</SmoothStreamingMedia>\n");
786 int main(
int argc,
char **argv)
788 const char *basename =
NULL;
789 const char *path_prefix =
"", *ismc_prefix =
"";
790 const char *output_prefix =
"";
791 char output_prefix_buf[2048];
792 int split = 0, ismf = 0,
i;
793 struct Tracks tracks = { 0, .video_track = -1, .audio_track = -1 };
795 for (
i = 1;
i < argc;
i++) {
796 if (!strcmp(argv[
i],
"-n")) {
797 basename = argv[
i + 1];
799 }
else if (!strcmp(argv[
i],
"-path-prefix")) {
800 path_prefix = argv[
i + 1];
802 }
else if (!strcmp(argv[
i],
"-ismc-prefix")) {
803 ismc_prefix = argv[
i + 1];
805 }
else if (!strcmp(argv[
i],
"-output")) {
806 output_prefix = argv[
i + 1];
808 if (output_prefix[strlen(output_prefix) - 1] !=
'/') {
809 snprintf(output_prefix_buf,
sizeof(output_prefix_buf),
810 "%s/", output_prefix);
811 output_prefix = output_prefix_buf;
813 }
else if (!strcmp(argv[
i],
"-split")) {
815 }
else if (!strcmp(argv[
i],
"-ismf")) {
817 }
else if (argv[
i][0] ==
'-') {
818 return usage(argv[0], 1);
823 basename, output_prefix))
828 return usage(argv[0], 1);
832 path_prefix, ismc_prefix);
@ AV_ROUND_UP
Round toward +infinity.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
#define MOV_TRUN_SAMPLE_FLAGS
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static int64_t read_moof_duration(AVIOContext *in, int64_t offset)
enum AVMediaType codec_type
General type of the encoded data.
This struct describes the properties of an encoded stream.
#define AVERROR_EOF
End of file.
static int write_fragment(const char *filename, AVIOContext *in)
AVStream ** streams
A list of all streams in the file.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
static void output_server_manifest(struct Tracks *tracks, const char *basename, const char *output_prefix, const char *path_prefix, const char *ismc_prefix)
int nb_channels
Number of channels in this layout.
int64_t avio_size(AVIOContext *s)
Get the filesize.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
static int read_mfra(struct Tracks *tracks, int start_index, const char *file, int split, int ismf, const char *basename, const char *output_prefix)
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
static int expect_tag(int32_t got_tag, int32_t expected_tag)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static void output_client_manifest(struct Tracks *tracks, const char *basename, const char *output_prefix, int split)
static int write_fragments(struct Tracks *tracks, int start_index, AVIOContext *in, const char *basename, int split, int ismf, const char *output_prefix)
#define MOV_TRUN_SAMPLE_DURATION
static void clean_tracks(struct Tracks *tracks)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
int64_t duration
Decoding: duration of the stream, in stream time base.
#define MOV_TRUN_DATA_OFFSET
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
unsigned int avio_rb32(AVIOContext *s)
static int skip_tag(AVIOContext *in, int32_t tag_name)
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
#define MOV_TFHD_DEFAULT_DURATION
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
#define MOV_TRUN_FIRST_SAMPLE_FLAGS
#define AVIO_FLAG_WRITE
write-only
static int usage(const char *argv0, int ret)
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
uint64_t avio_rb64(AVIOContext *s)
static int read_tfra(struct Tracks *tracks, int start_index, AVIOContext *f)
AVChannelLayout ch_layout
Audio only.
#define MOV_TFHD_BASE_DATA_OFFSET
int sample_rate
Audio only.
int extradata_size
Size of the extradata content in bytes.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
unsigned int avio_rb24(AVIOContext *s)
int main(int argc, char **argv)
#define MKBETAG(a, b, c, d)
static char * split(char *message, char delim)
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void avio_wb32(AVIOContext *s, unsigned int val)
int avio_r8(AVIOContext *s)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
#define i(width, name, range_min, range_max)
static void print_track_chunks(FILE *out, struct Tracks *tracks, int main, const char *type)
#define AV_TIME_BASE
Internal time base represented as integer.
int block_align
Audio only.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static int get_video_private_data(struct Track *track, AVCodecParameters *codecpar)
void * av_calloc(size_t nmemb, size_t size)
int id
Format-specific stream ID.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
static int get_private_data(struct Track *track, AVCodecParameters *codecpar)
struct MoofOffset * offsets
static int64_t read_trun_duration(AVIOContext *in, int default_duration, int64_t end)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static int skip_fragment(AVIOContext *in)
#define AVIO_FLAG_READ
read-only
int avio_open2(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
static int handle_file(struct Tracks *tracks, const char *file, int split, int ismf, const char *basename, const char *output_prefix)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
#define MOV_TRUN_SAMPLE_SIZE
#define flags(name, subs,...)
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define MOV_TRUN_SAMPLE_CTS
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
static int copy_tag(AVIOContext *in, AVIOContext *out, int32_t tag_name)