[vlc-devel] [PATCH 2/2] mp4 mux: encode video orientation

Rémi Denis-Courmont remi at remlab.net
Tue Apr 1 19:59:31 CEST 2014


On Tue,  1 Apr 2014 17:58:05 +0200, Rafaël Carré <funman at videolan.org>
wrote:
> ---
>  modules/mux/mp4.c | 26 ++++++++++++++++++++++++--
>  1 file changed, 24 insertions(+), 2 deletions(-)
> 
> diff --git a/modules/mux/mp4.c b/modules/mux/mp4.c
> index 197254f..39a1e1f 100644
> --- a/modules/mux/mp4.c
> +++ b/modules/mux/mp4.c
> @@ -1451,8 +1451,26 @@ static bo_t *GetStblBox(sout_mux_t *p_mux,
> mp4_stream_t *p_stream)
>  
>  static int64_t get_timestamp(void);
>  
> -static const uint32_t mvhd_matrix[9] =
> -    { 0x10000, 0, 0, 0, 0x10000, 0, 0, 0, 0x40000000 };
> +static void matrix_apply_rotation(es_format_t *fmt, uint32_t
> mvhd_matrix[9])

In principles, this should be int32_t.

> +{
> +    enum video_orientation_t orientation = ORIENT_NORMAL;
> +    if (fmt->i_cat == VIDEO_ES)
> +        orientation = fmt->video.orientation;
> +
> +#define ATAN(a, b) do { mvhd_matrix[1] = (a) << 16; \
> +    mvhd_matrix[0] = (b) << 16; \
> +    } while(0)
> +
> +    switch (orientation) {
> +    case ORIENT_ROTATED_90:  ATAN( 1,  0); break;
> +    case ORIENT_ROTATED_180: ATAN( 0, -1); break;
> +    case ORIENT_ROTATED_270: ATAN( -1, 0); break;

The matrix allows encoding the indirect transforms too and the values are
already found in the OpenGL output for the lazies.

Even the pixel aspect ratio could presumably be coded there, though I'm
not sure that makes any practical sense.

> +    default:                 ATAN( 0,  1); break;
> +    }
> +
> +    mvhd_matrix[3] = mvhd_matrix[0] ? 0 : 0x10000;
> +    mvhd_matrix[4] = mvhd_matrix[1] ? 0 : 0x10000;
> +}
>  
>  static bo_t *GetMoovBox(sout_mux_t *p_mux)
>  {
> @@ -1494,6 +1512,9 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux)
>      bo_add_16be(mvhd, 0);                 // reserved
>      for (int i = 0; i < 2; i++)
>          bo_add_32be(mvhd, 0);             // reserved
> +
> +    uint32_t mvhd_matrix[9] = { 0x10000, 0, 0, 0, 0x10000, 0, 0, 0,
> 0x40000000 };
> +
>      for (int i = 0; i < 9; i++)
>          bo_add_32be(mvhd, mvhd_matrix[i]);// matrix
>      for (int i = 0; i < 6; i++)
> @@ -1551,6 +1572,7 @@ static bo_t *GetMoovBox(sout_mux_t *p_mux)
>          // volume
>          bo_add_16be(tkhd, p_stream->fmt.i_cat == AUDIO_ES ? 0x100 : 0);
>          bo_add_16be(tkhd, 0);                     // reserved
> +        matrix_apply_rotation(&p_stream->fmt, mvhd_matrix);
>          for (int i = 0; i < 9; i++)
>              bo_add_32be(tkhd, mvhd_matrix[i]);    // matrix
>          if (p_stream->fmt.i_cat == AUDIO_ES) {

-- 
Rémi Denis-Courmont
Sent from my collocated server



More information about the vlc-devel mailing list