History

lavf: add av_guess_frame_sample_aspect_ratio function

Guesses the sample aspect ratio of a frame, based on both the stream and the frame aspect ratio. Since the frame aspect ratio is set by the codec but the stream aspect ratio is set by the demuxer, these two may not be equal. This function tries to return the value that you should use if you would like to display the frame. Basic logic is to use the stream aspect ratio if it is set to something sane otherwise use the frame aspect ratio. This way a container setting, which is usually easy to modify can override the coded value in the frames.

Marton Balint committed 14 years ago

Commit 94a9ac11 parent 9cf5bcd4 files · +46 −1Browse files

Unified · Split

4 files
  1. doc/APIchanges +3 −0
  2. libavformat/avformat.h +20 −0
  3. libavformat/utils.c +22 −0
  4. libavformat/version.h +1 −1
doc/APIchanges+3−0
@@ -15,6 +15,9 @@ libavutil: 2011-04-18 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2012-05-07 - xxxxxxx - lavf 54.5.100
19+ Add av_guess_sample_aspect_ratio() function.
20+
1821 2012-04-20 - xxxxxxx - lavfi 2.70.100
1922 Add avfilter_unref_bufferp() to avfilter.h.
2023
libavformat/avformat.h+20−0
@@ -1911,6 +1911,26 @@ const struct AVCodecTag *avformat_get_riff_video_tags(void); · 1910 unmodified lines
19111911 * @return the table mapping RIFF FourCCs for audio to CodecID.
19121912 */
19131913 const struct AVCodecTag *avformat_get_riff_audio_tags(void);
1914+
1915+/**
1916+ * Guesses the sample aspect ratio of a frame, based on both the stream and the
1917+ * frame aspect ratio.
1918+ *
1919+ * Since the frame aspect ratio is set by the codec but the stream aspect ratio
1920+ * is set by the demuxer, these two may not be equal. This function tries to
1921+ * return the value that you should use if you would like to display the frame.
1922+ *
1923+ * Basic logic is to use the stream aspect ratio if it is set to something sane
1924+ * otherwise use the frame aspect ratio. This way a container setting, which is
1925+ * usually easy to modify can override the coded value in the frames.
1926+ *
1927+ * @param format the format context which the stream is part of
1928+ * @param stream the stream which the frame is part of
1929+ * @param frame the frame with the aspect ratio to be determined
1930+ * @return the guessed (valid) sample_aspect_ratio, 0/1 if no idea
1931+ */
1932+AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame);
1933+
19141934 /**
19151935 * @}
19161936 */
libavformat/utils.c+22−0
@@ -4414,3 +4414,25 @@ const struct AVCodecTag *avformat_get_riff_audio_tags(void) · 4413 unmodified lines
44144414 {
44154415 return ff_codec_wav_tags;
44164416 }
4417+
4418+AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame)
4419+{
4420+ AVRational undef = {0, 1};
4421+ AVRational stream_sample_aspect_ratio = stream ? stream->sample_aspect_ratio : undef;
4422+ AVRational frame_sample_aspect_ratio = frame ? frame->sample_aspect_ratio : undef;
4423+
4424+ av_reduce(&stream_sample_aspect_ratio.num, &stream_sample_aspect_ratio.den,
4425+ stream_sample_aspect_ratio.num, stream_sample_aspect_ratio.den, INT_MAX);
4426+ if (stream_sample_aspect_ratio.num <= 0 || stream_sample_aspect_ratio.den <= 0)
4427+ stream_sample_aspect_ratio = undef;
4428+
4429+ av_reduce(&frame_sample_aspect_ratio.num, &frame_sample_aspect_ratio.den,
4430+ frame_sample_aspect_ratio.num, frame_sample_aspect_ratio.den, INT_MAX);
4431+ if (frame_sample_aspect_ratio.num <= 0 || frame_sample_aspect_ratio.den <= 0)
4432+ frame_sample_aspect_ratio = undef;
4433+
4434+ if (stream_sample_aspect_ratio.num)
4435+ return stream_sample_aspect_ratio;
4436+ else
4437+ return frame_sample_aspect_ratio;
4438+}
libavformat/version.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
3030 #include "libavutil/avutil.h"
3131
3232 #define LIBAVFORMAT_VERSION_MAJOR 54
33−#define LIBAVFORMAT_VERSION_MINOR 4
33+#define LIBAVFORMAT_VERSION_MINOR 5
3434 #define LIBAVFORMAT_VERSION_MICRO 100
3535
3636 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t