38#define FILENAME_BUF_SIZE 4096
39#define PKTFILESUFF "_%08" PRId64 "_%02d_%010" PRId64 "_%06d_%c.bin"
40#define EXTRADATAFILESUFF "_extradata_%02d_%06d.bin"
44 fprintf(stderr,
"Dump (up to maxpkts) AVPackets as they are demuxed by libavformat.\n");
45 fprintf(stderr,
"Each packet is dumped in its own file named like\n");
46 fprintf(stderr,
"$(basename file.ext)_$PKTNUM_$STREAMINDEX_$STAMP_$SIZE_$FLAGS.bin\n");
47 fprintf(stderr,
"pktdumper [-nw] file [maxpkts]\n");
48 fprintf(stderr,
"-n\twrite No file at all, only demux.\n");
49 fprintf(stderr,
"-w\tWait at end of processing instead of quitting.\n");
53int main(
int argc,
char **argv)
66 if ((argc > 1) && !strncmp(argv[1],
"-", 1)) {
67 if (strchr(argv[1],
'w'))
69 if (strchr(argv[1],
'n'))
77 maxpkts = atoi(argv[2]);
78 av_strlcpy(fntemplate, argv[1],
sizeof(fntemplate));
79 if (strrchr(argv[1],
'/'))
80 av_strlcpy(fntemplate, strrchr(argv[1],
'/') + 1,
sizeof(fntemplate));
81 if (strrchr(fntemplate,
'.'))
82 *strrchr(fntemplate,
'.') =
'\0';
83 if (strchr(fntemplate,
'%')) {
84 fprintf(stderr,
"cannot use filenames containing '%%'\n");
87 if (strlen(fntemplate) +
sizeof(
PKTFILESUFF) >=
sizeof(fntemplate) - 1) {
88 fprintf(stderr,
"filename too long\n");
94 fprintf(stderr,
"cannot open input: error %d\n", err);
100 fprintf(stderr,
"avformat_find_stream_info: error %d\n", err);
106 fprintf(stderr,
"av_packet_alloc: error %d\n",
AVERROR(ENOMEM));
110 strcpy(fntemplate2, fntemplate);
120 fd = open(pktfilename, O_WRONLY | O_CREAT, 0644);
123 fprintf(stderr,
"write: error %d\n", err);
132 printf(
"FNTEMPLATE: '%s'\n", fntemplate);
136 snprintf(pktfilename,
sizeof(pktfilename), fntemplate, pktnum,
142 fd = open(pktfilename, O_WRONLY | O_CREAT, 0644);
143 err = write(fd,
pkt->data,
pkt->size);
145 fprintf(stderr,
"write: error %d\n", err);
152 if (maxpkts && (pktnum >= maxpkts))
static av_cold void close(AVCodecParserContext *s)
#define i(width, name, range_min, range_max)
__device__ int printf(const char *,...)
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
#define EXTRADATAFILESUFF
#define FILENAME_BUF_SIZE
This struct describes the properties of an encoded stream.
int extradata_size
Size of the extradata content in bytes.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
AVStream ** streams
A list of all streams in the file.
This structure stores compressed data.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int av_usleep(unsigned usec)
Sleep for a period of time.