[Libav-user] Incorrect Display Aspect Ratio
Lyndon Hill
emptystate at yahoo.co.uk
Wed Aug 19 09:03:16 CEST 2015
Hi,
I'm having trouble finding the correct aspect for displaying anamorphic video from an MTS.
If I use ffprobe I get the result (truncated):
Stream #0:0[0x515]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv), 720x576 [SAR 64:45 DAR 16:9], max. 2972 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
So the DAR is 16:9. Using my code, I get a SAR of 0:1 which the docs say means unknown.
My code:
// testdar.cc
// clang++ testdar.cc -o testdar (pkg-config --cflags ffmpeg) (pkg-config --libs ffmpeg)
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
#include <iostream>
int main(int argc, char *argv[])
{
avcodec_register_all();
av_register_all();
AVFormatContext *format;
if(avformat_open_input(&format,
"2015071421565301.mts",
NULL, NULL) < 0)
return(1);
if(avformat_find_stream_info(format, NULL) < 0)
{
avformat_close_input(&format);
return(1);
}
AVCodec *video_codec;
int stream = av_find_best_stream(format,
AVMEDIA_TYPE_VIDEO,
-1, -1,
&video_codec,
0);
if(stream < 0)
{
avformat_close_input(&format);
return(1);
}
AVCodecContext *codec_ctx;
codec_ctx = format->streams[stream]->codec;
if(avcodec_open2(codec_ctx, video_codec, NULL) < 0)
{
avformat_close_input(&format);
return(1);
}
std::cout << "Aspect ratio = "
<< format->streams[stream]->sample_aspect_ratio.num
<< ":" << format->streams[stream]->sample_aspect_ratio.den << "\n";
return(0);
}
Result (truncated):
$ ./testdar
Aspect ratio = 0:1
thanks in advance
L. Hill
More information about the Libav-user
mailing list