[FFmpeg-devel] [PATCH] movenc: Add support for writing st3d and sv3d boxes.

James Almer jamrial at gmail.com
Mon Mar 27 20:00:30 EEST 2017


On 3/27/2017 1:02 PM, Aaron Colwell wrote:
> 
> 0001-movenc-Add-support-for-writing-st3d-andsv3d-boxes.patch
> 
> 
> From 8654212c2f2a3ee404020cf5b948d7db3e6270f2 Mon Sep 17 00:00:00 2001
> From: Aaron Colwell <acolwell at google.com>
> Date: Mon, 27 Mar 2017 08:00:12 -0700
> Subject: [PATCH] movenc: Add support for writing st3d and sv3d boxes.
> 
> ---
>  libavformat/movenc.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 105 insertions(+)
> 
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 3b4e3b519c..4f408b20fa 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -1603,6 +1603,101 @@ static int mov_write_subtitle_tag(AVIOContext *pb, MOVTrack *track)
>      return update_size(pb, pos);
>  }
>  
> +static int mov_write_st3d_tag(AVIOContext *pb, AVStereo3D *stereo_3d)
> +{
> +    int8_t stereo_mode;
> +
> +    if (stereo_3d->flags != 0) {
> +        av_log(pb, AV_LOG_WARNING, "Unsupported stereo_3d flags %x. st3d not written.\n", stereo_3d->flags);
> +        return 0;
> +    }
> +
> +    switch (stereo_3d->type) {
> +    case AV_STEREO3D_2D:
> +        stereo_mode = 0;
> +        break;
> +    case AV_STEREO3D_TOPBOTTOM:
> +        stereo_mode = 1;
> +        break;
> +    case AV_STEREO3D_SIDEBYSIDE:
> +        stereo_mode = 2;
> +        break;
> +    default:
> +        av_log(pb, AV_LOG_WARNING, "Unsupported stereo_3d type %d. st3d not written.\n", stereo_3d->type);

You could use av_stereo3d_type_name(stereo_3d->type) here.

> +        return 0;
> +    }
> +    avio_wb32(pb, 13); /* size */
> +    ffio_wfourcc(pb, "st3d");
> +    avio_wb32(pb, 0); /* version = 0 & flags = 0 */
> +    avio_w8(pb, stereo_mode);
> +    return 13;
> +}
> +
> +static int mov_write_sv3d_tag(AVIOContext *pb, AVSphericalMapping *spherical_mapping)
> +{
> +    int64_t sv3d_pos, svhd_pos, proj_pos;
> +
> +    if (spherical_mapping->projection != AV_SPHERICAL_EQUIRECTANGULAR &&
> +        spherical_mapping->projection != AV_SPHERICAL_EQUIRECTANGULAR_TILE &&
> +        spherical_mapping->projection != AV_SPHERICAL_CUBEMAP) {
> +        av_log(pb, AV_LOG_WARNING, "Unsupported projection %d. sv3d not written.\n", spherical_mapping->projection);
> +        return 0;
> +    }
> +
> +    sv3d_pos = avio_tell(pb);
> +    avio_wb32(pb, 0);  /* size */
> +    ffio_wfourcc(pb, "sv3d");
> +
> +    svhd_pos = avio_tell(pb);
> +    avio_wb32(pb, 0);  /* size */
> +    ffio_wfourcc(pb, "svhd");
> +    avio_wb32(pb, 0); /* version = 0 & flags = 0 */
> +    avio_put_str(pb, LIBAVFORMAT_IDENT); /* metadata_source */

You need to use some hardcoded string like "Lavf" or nothing at all if
AVFMT_FLAG_BITEXACT is set in (AVFormatContext*)->flags.

> +    update_size(pb, svhd_pos);
> +
> +    proj_pos = avio_tell(pb);
> +    avio_wb32(pb, 0); /* size */
> +    ffio_wfourcc(pb, "proj");
> +
> +    avio_wb32(pb, 24); /* size */
> +    ffio_wfourcc(pb, "prhd");
> +    avio_wb32(pb, 0); /* version = 0 & flags = 0 */
> +    avio_wb32(pb, spherical_mapping->yaw);
> +    avio_wb32(pb, spherical_mapping->pitch);
> +    avio_wb32(pb, spherical_mapping->roll);
> +
> +    switch (spherical_mapping->projection) {
> +    case AV_SPHERICAL_EQUIRECTANGULAR:
> +        avio_wb32(pb, 28);    /* size */
> +        ffio_wfourcc(pb, "equi");
> +        avio_wb32(pb, 0); /* version = 0 & flags = 0 */
> +        avio_wb32(pb, 0); /* projection_bounds_top */
> +        avio_wb32(pb, 0); /* projection_bounds_bottom */
> +        avio_wb32(pb, 0); /* projection_bounds_left */
> +        avio_wb32(pb, 0); /* projection_bounds_right */
> +        break;
> +    case AV_SPHERICAL_EQUIRECTANGULAR_TILE:
> +        avio_wb32(pb, 28);    /* size */
> +        ffio_wfourcc(pb, "equi");
> +        avio_wb32(pb, 0); /* version = 0 & flags = 0 */
> +        avio_wb32(pb, spherical_mapping->bound_top);
> +        avio_wb32(pb, spherical_mapping->bound_bottom);
> +        avio_wb32(pb, spherical_mapping->bound_left);
> +        avio_wb32(pb, spherical_mapping->bound_right);
> +        break;

The bound_ fields are going to be zero in the AV_SPHERICAL_EQUIRECTANGULAR
case, so just use the AV_SPHERICAL_EQUIRECTANGULAR_TILE code for both cases.

> +    case AV_SPHERICAL_CUBEMAP:
> +        avio_wb32(pb, 20);    /* size */
> +        ffio_wfourcc(pb, "cbmp");
> +        avio_wb32(pb, 0); /* version = 0 & flags = 0 */
> +        avio_wb32(pb, 0); /* layout */
> +        avio_wb32(pb, spherical_mapping->padding); /* padding */
> +        break;
> +    }
> +    update_size(pb, proj_pos);
> +
> +    return update_size(pb, sv3d_pos);
> +}
> +
>  static int mov_write_pasp_tag(AVIOContext *pb, MOVTrack *track)
>  {
>      AVRational sar;
> @@ -1873,6 +1968,16 @@ static int mov_write_video_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *tr
>              av_log(mov->fc, AV_LOG_WARNING, "Not writing 'colr' atom. Format is not MOV or MP4.\n");
>      }
>  
> +    if (mov->fc->strict_std_compliance <= FF_COMPLIANCE_EXPERIMENTAL) {
> +      AVStereo3D* stereo_3d = (AVStereo3D*) av_stream_get_side_data(track->st, AV_PKT_DATA_STEREO3D, NULL);
> +      AVSphericalMapping* spherical_mapping = (AVSphericalMapping*)av_stream_get_side_data(track->st, AV_PKT_DATA_SPHERICAL, NULL);
> +
> +      if (stereo_3d)
> +          mov_write_st3d_tag(pb, stereo_3d);
> +      if (spherical_mapping)
> +          mov_write_sv3d_tag(pb, spherical_mapping);
> +    }
> +
>      if (track->par->sample_aspect_ratio.den && track->par->sample_aspect_ratio.num) {
>          mov_write_pasp_tag(pb, track);
>      }
> -- 2.12.1.578.ge9c3154ca4-goog
> 
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 



More information about the ffmpeg-devel mailing list