[FFmpeg-devel] [PATCH 1/4] lavf: add write_uncoded_frame() API.

Michael Niedermayer michaelni at gmx.at
Tue Jan 14 06:17:20 CET 2014


On Mon, Jan 13, 2014 at 10:23:43AM +0100, Nicolas George wrote:
> Signed-off-by: Nicolas George <george at nsup.org>
> ---
>  libavformat/avformat.h | 46 +++++++++++++++++++++++++++++++++++
>  libavformat/internal.h | 14 +++++++++++
>  libavformat/mux.c      | 65 +++++++++++++++++++++++++++++++++++++++++++++++++-
>  3 files changed, 124 insertions(+), 1 deletion(-)
> 
> 
> Split the API into av_write_uncoded_frame() /
> av_interleaved_write_uncoded_frame() / av_write_uncoded_frame_query().
> The QUERY flag stays for internal use in the muxers callback.
> 
> Also use a more robust magic number as the packet size.
> 
> 
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 6d719d7..4c03985 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -453,6 +453,14 @@ typedef struct AVOutputFormat {
>  
>      void (*get_output_timestamp)(struct AVFormatContext *s, int stream,
>                                   int64_t *dts, int64_t *wall);
> +
> +    /**
> +     * Write an uncoded AVFrame.
> +     *
> +     * See av_write_uncoded_frame() for details.
> +     */
> +    int (*write_uncoded_frame)(struct AVFormatContext *, int stream_index,
> +                               AVFrame *frame, unsigned flags);
>  } AVOutputFormat;
>  /**
>   * @}
> @@ -1908,6 +1916,44 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt);
>  int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
>  
>  /**
> + * Write a uncoded frame to an output media file.
> + *
> + * The frame must be correctly interleaved according to the container
> + * specification; if not, then av_interleaved_write_frame() must be used.
> + *
> + * See av_interleaved_write_frame() for details.
> + */
> +int av_write_uncoded_frame(AVFormatContext *s, int stream_index,
> +                           AVFrame *frame);
> +
> +/**
> + * Write a uncoded frame to an output media file.
> + *
> + * If the muxer supports it, this function allows to write an AVFrame
> + * structure directly, without encoding it into a packet.
> + * It is mostly useful for devices and similar special muxers that use raw
> + * video or PCM data and will not serialize it into a byte stream.
> + *
> + * To test whether it is possible to use it with a given muxer and stream,
> + * use av_write_uncoded_frame_query().
> + *

> + * The caller keeps ownership of the frame and is responsible for freeing
> + * it.

this mismatches what we do with packets
besides this consider a device that wants to display subtitles
if the AVFrame to be output has its memory still owned by the caller
then the device cannot write into the buffer but if the caller gave
up ownership (unless he has a explicit 2nd reference to the memory)
then the device could render subtitles into the AVFrame before
display


[...]
> @@ -871,3 +886,51 @@ int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
>                                            dst->streams[dst_stream]->time_base);
>      return av_write_frame(dst, &local_pkt);
>  }
> +
> +static int av_write_uncoded_frame_internal(AVFormatContext *s, int stream_index,
> +                                           AVFrame *frame, int interleaved)
> +{
> +    AVPacket pkt, *pktp;
> +
> +    av_assert0(s->oformat);
> +    if (!s->oformat->write_uncoded_frame)
> +        return AVERROR(ENOSYS);
> +
> +    if (!frame) {
> +        pktp = NULL;
> +    } else {
> +        pktp = &pkt;
> +        av_init_packet(&pkt);
> +        pkt.data = (void *)frame;
> +        pkt.size         = UNCODED_FRAME_PACKET_SIZE;

> +        pkt.pts          = frame->pts != AV_NOPTS_VALUE ? frame->pts : frame->pkt_pts;
> +        pkt.dts          = frame->pkt_dts;

this looks too convoluted
a uncoded frame should always have pkt.pts = pkt.dts i think
the pts != dts is a artfact of frame reordering and B frames which
are all specific to compressed frames

patch LGTM except these


[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The bravest are surely those who have the clearest vision
of what is before them, glory and danger alike, and yet
notwithstanding go out to meet it. -- Thucydides
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140114/8f4288ba/attachment.asc>


More information about the ffmpeg-devel mailing list