ffmpeg: remove some asserts in aspect ratio computations
Use a default or undefined aspect ratio when ffmpeg won't tell us the video size, rather than crashing the whole app.
This commit is contained in:
parent
d8c41a8ab0
commit
5dbf9531ea
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <GraphicsDefs.h>
|
#include <GraphicsDefs.h>
|
||||||
|
|
||||||
@ -44,13 +45,15 @@ inline void
|
|||||||
ConvertAVCodecContextToVideoAspectWidthAndHeight(AVCodecContext& contextIn,
|
ConvertAVCodecContextToVideoAspectWidthAndHeight(AVCodecContext& contextIn,
|
||||||
uint16& pixelWidthAspectOut, uint16& pixelHeightAspectOut)
|
uint16& pixelWidthAspectOut, uint16& pixelHeightAspectOut)
|
||||||
{
|
{
|
||||||
assert(contextIn.sample_aspect_ratio.num >= 0);
|
if (contextIn.width <= 0 || contextIn.height <= 0) {
|
||||||
assert(contextIn.width > 0);
|
fprintf(stderr, "Cannot compute video aspect ratio correctly\n");
|
||||||
assert(contextIn.height > 0);
|
pixelWidthAspectOut = 1;
|
||||||
|
pixelHeightAspectOut = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(contextIn.sample_aspect_ratio.num >= 0);
|
||||||
|
|
||||||
// The following code is based on code originally located in
|
|
||||||
// AVFormatReader::Stream::Init() and thus should be copyrighted to Stephan
|
|
||||||
// Aßmus
|
|
||||||
AVRational pixelAspectRatio;
|
AVRational pixelAspectRatio;
|
||||||
|
|
||||||
if (contextIn.sample_aspect_ratio.num == 0
|
if (contextIn.sample_aspect_ratio.num == 0
|
||||||
@ -80,13 +83,15 @@ inline void
|
|||||||
ConvertAVCodecParametersToVideoAspectWidthAndHeight(AVCodecParameters& parametersIn,
|
ConvertAVCodecParametersToVideoAspectWidthAndHeight(AVCodecParameters& parametersIn,
|
||||||
uint16& pixelWidthAspectOut, uint16& pixelHeightAspectOut)
|
uint16& pixelWidthAspectOut, uint16& pixelHeightAspectOut)
|
||||||
{
|
{
|
||||||
assert(parametersIn.sample_aspect_ratio.num >= 0);
|
if (parametersIn.width <= 0 || parametersIn.height <= 0) {
|
||||||
assert(parametersIn.width > 0);
|
fprintf(stderr, "Cannot compute video aspect ratio correctly\n");
|
||||||
assert(parametersIn.height > 0);
|
pixelWidthAspectOut = 1;
|
||||||
|
pixelHeightAspectOut = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(parametersIn.sample_aspect_ratio.num >= 0);
|
||||||
|
|
||||||
// The following code is based on code originally located in
|
|
||||||
// AVFormatReader::Stream::Init() and thus should be copyrighted to Stephan
|
|
||||||
// Aßmus
|
|
||||||
AVRational pixelAspectRatio;
|
AVRational pixelAspectRatio;
|
||||||
|
|
||||||
if (parametersIn.sample_aspect_ratio.num == 0
|
if (parametersIn.sample_aspect_ratio.num == 0
|
||||||
@ -136,10 +141,16 @@ inline void
|
|||||||
ConvertVideoAspectWidthAndHeightToAVCodecContext(uint16 pixelWidthAspectIn,
|
ConvertVideoAspectWidthAndHeightToAVCodecContext(uint16 pixelWidthAspectIn,
|
||||||
uint16 pixelHeightAspectIn, AVCodecContext& contextInOut)
|
uint16 pixelHeightAspectIn, AVCodecContext& contextInOut)
|
||||||
{
|
{
|
||||||
|
if (contextInOut.width <= 0 || contextInOut.height <= 0) {
|
||||||
|
fprintf(stderr, "Cannot compute video aspect ratio correctly\n");
|
||||||
|
// We can't do anything, set the aspect ratio to 'ignore'.
|
||||||
|
contextInOut.sample_aspect_ratio.num = 0;
|
||||||
|
contextInOut.sample_aspect_ratio.den = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
assert(pixelWidthAspectIn > 0);
|
assert(pixelWidthAspectIn > 0);
|
||||||
assert(pixelHeightAspectIn > 0);
|
assert(pixelHeightAspectIn > 0);
|
||||||
assert(contextInOut.width > 0);
|
|
||||||
assert(contextInOut.height > 0);
|
|
||||||
|
|
||||||
AVRational pureVideoDimensionAspectRatio;
|
AVRational pureVideoDimensionAspectRatio;
|
||||||
av_reduce(&pureVideoDimensionAspectRatio.num,
|
av_reduce(&pureVideoDimensionAspectRatio.num,
|
||||||
|
Loading…
Reference in New Issue
Block a user