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
15 15
16API changes, most recent first:16API changes, most recent first:
17 17
182012-05-07 - xxxxxxx - lavf 54.5.100
19 Add av_guess_sample_aspect_ratio() function.
20
182012-04-20 - xxxxxxx - lavfi 2.70.100212012-04-20 - xxxxxxx - lavfi 2.70.100
19 Add avfilter_unref_bufferp() to avfilter.h.22 Add avfilter_unref_bufferp() to avfilter.h.
20 23
libavformat/avformat.h+20−0
@@ -1911,6 +1911,26 @@ const struct AVCodecTag *avformat_get_riff_video_tags(void); · 1910 unmodified lines
1911 * @return the table mapping RIFF FourCCs for audio to CodecID.1911 * @return the table mapping RIFF FourCCs for audio to CodecID.
1912 */1912 */
1913const struct AVCodecTag *avformat_get_riff_audio_tags(void);1913const 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 */
1932AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame);
1933
1914/**1934/**
1915 * @}1935 * @}
1916 */1936 */
libavformat/utils.c+22−0
@@ -4414,3 +4414,25 @@ const struct AVCodecTag *avformat_get_riff_audio_tags(void) · 4413 unmodified lines
4414{4414{
4415 return ff_codec_wav_tags;4415 return ff_codec_wav_tags;
4416}4416}
4417
4418AVRational 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
30#include "libavutil/avutil.h"30#include "libavutil/avutil.h"
31 31
32#define LIBAVFORMAT_VERSION_MAJOR 5432#define LIBAVFORMAT_VERSION_MAJOR 54
33#define LIBAVFORMAT_VERSION_MINOR 433#define LIBAVFORMAT_VERSION_MINOR 5
34#define LIBAVFORMAT_VERSION_MICRO 10034#define LIBAVFORMAT_VERSION_MICRO 100
35 35
36#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \36#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