82 lines
2.6 KiB
C
82 lines
2.6 KiB
C
#include <stdio.h>
|
|
#include <libavformat/avformat.h>
|
|
|
|
int main(int argc, char * argv[])
|
|
{
|
|
if (argc < 2)
|
|
{
|
|
fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
|
|
return 1;
|
|
}
|
|
|
|
AVFormatContext * context = NULL;
|
|
av_register_all();
|
|
if (avformat_open_input(&context, argv[1], NULL, NULL) != 0)
|
|
{
|
|
fprintf(stderr, "Error opening input stream %s\n", argv[1]);
|
|
return 1;
|
|
}
|
|
|
|
if (avformat_find_stream_info(context, NULL) < 0)
|
|
{
|
|
fprintf(stderr, "Error finding stream info\n");
|
|
return 1;
|
|
}
|
|
|
|
av_dump_format(context, 0, argv[1], 0);
|
|
|
|
int video_stream_idx = av_find_best_stream(context, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
|
|
printf("Video stream index: %d\n", video_stream_idx);
|
|
int audio_stream_idx = av_find_best_stream(context, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0);
|
|
printf("Audio stream index: %d\n", audio_stream_idx);
|
|
|
|
if (video_stream_idx >= 0)
|
|
printf("Video stream time_base: %d/%d\n",
|
|
context->streams[video_stream_idx]->time_base.num,
|
|
context->streams[video_stream_idx]->time_base.den);
|
|
if (audio_stream_idx >= 0)
|
|
printf("Audio stream time_base: %d/%d\n",
|
|
context->streams[audio_stream_idx]->time_base.num,
|
|
context->streams[audio_stream_idx]->time_base.den);
|
|
|
|
AVPacket pkt;
|
|
av_init_packet(&pkt);
|
|
|
|
int n_total_frames = 0;
|
|
int n_video_frames = 0;
|
|
int n_audio_frames = 0;
|
|
int max_video_size = 0;
|
|
int total_video_size = 0;
|
|
int max_audio_size = 0;
|
|
int total_audio_size = 0;
|
|
while (av_read_frame(context, &pkt) >= 0)
|
|
{
|
|
n_total_frames++;
|
|
if (pkt.stream_index == video_stream_idx)
|
|
{
|
|
n_video_frames++;
|
|
total_video_size += pkt.size;
|
|
if (pkt.size > max_video_size)
|
|
max_video_size = pkt.size;
|
|
}
|
|
if (pkt.stream_index == audio_stream_idx)
|
|
{
|
|
n_audio_frames++;
|
|
total_audio_size += pkt.size;
|
|
if (pkt.size > max_audio_size)
|
|
max_audio_size = pkt.size;
|
|
}
|
|
}
|
|
printf("There are %d frames: %d video and %d audio (%d other)\n",
|
|
n_total_frames, n_video_frames, n_audio_frames,
|
|
n_total_frames - n_video_frames - n_audio_frames);
|
|
printf("Video size: %d, max: %d, average: %d\n",
|
|
total_video_size, max_video_size, total_video_size / n_video_frames);
|
|
printf("Audio size: %d, max: %d, average: %d\n",
|
|
total_audio_size, max_audio_size, total_audio_size / n_audio_frames);
|
|
|
|
avformat_close_input(&context);
|
|
|
|
return 0;
|
|
}
|