count audio and video frames and show some statistics
This commit is contained in:
parent
78a11fb3bf
commit
7de3460728
4
Makefile
4
Makefile
@ -1,7 +1,7 @@
|
||||
TARGET := hello
|
||||
OBJS := hello.o
|
||||
CFLAGS := $$(pkg-config --cflags libavformat) -Wall
|
||||
LDFLAGS := $$(pkg-config --libs libavformat)
|
||||
CFLAGS := $$(pkg-config --cflags libavformat libavcodec) -Wall
|
||||
LDFLAGS := $$(pkg-config --libs libavformat libavcodec)
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
|
41
hello.c
41
hello.c
@ -25,6 +25,47 @@ int main(int argc, char * argv[])
|
||||
|
||||
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);
|
||||
|
||||
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("Saw %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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user