Skip to content

Commit d12c4ea

Browse files
committed
quit if no video stream is found
If a video stream is found we can stop examining other streams and codecs. If no stream is found processing all the packets does not make much sense so terminate
1 parent ae1ba05 commit d12c4ea

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

0_hello_world.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ int main(int argc, const char *argv[])
115115
video_stream_index = i;
116116
pCodec = pLocalCodec;
117117
pCodecParameters = pLocalCodecParameters;
118+
break;
118119
}
119120

120121
logging("Video Codec: resolution %d x %d", pLocalCodecParameters->width, pLocalCodecParameters->height);
@@ -125,6 +126,12 @@ int main(int argc, const char *argv[])
125126
// print its name, id and bitrate
126127
logging("\tCodec %s ID %d bit_rate %lld", pLocalCodec->name, pLocalCodec->id, pLocalCodecParameters->bit_rate);
127128
}
129+
130+
if (video_stream_index == -1) {
131+
logging("File %s does not contain a video stream!", argv[1]);
132+
return -1;
133+
}
134+
128135
// https://ffmpeg.org/doxygen/trunk/structAVCodecContext.html
129136
AVCodecContext *pCodecContext = avcodec_alloc_context3(pCodec);
130137
if (!pCodecContext)

0 commit comments

Comments
 (0)