[FFmpeg-devel] [PATCH] lavf: add a real SRT muxer.

Clément Bœsch ubitux at gmail.com
Sun Jun 17 22:02:05 CEST 2012


On Sun, Jun 17, 2012 at 09:23:11PM +0200, Nicolas George wrote:
> This muxer supports CODEC_ID_SRT with the timestamps in the packet data
> and CODEC_ID_TEXT with the timestamps in the packet fields.
> 
> Makes -scodec copy work from Matroska.
> 
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
>  libavformat/Makefile |    2 +-
>  libavformat/rawenc.c |   12 ------
>  libavformat/srtenc.c |   99 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 100 insertions(+), 13 deletions(-)
>  create mode 100644 libavformat/srtenc.c
> 
[...]
> +
> +/* TODO: add options for:
> +   - character encoding;
> +   - LF / CRLF;
> +   - byte order mark.
> + */
> +
> +typedef struct SRTContext{
> +    unsigned index;
> +} SRTContext;
> +
> +static int srt_write_header(AVFormatContext *avf)
> +{
> +    if (avf->nb_streams != 1 ||
> +        avf->streams[0]->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) {
> +        av_log(avf, AV_LOG_ERROR,
> +               "SRT supports only a single subtitles stream.\n");
> +        return AVERROR(EINVAL);
> +    }
> +    if (avf->streams[0]->codec->codec_id != CODEC_ID_TEXT &&
> +        avf->streams[0]->codec->codec_id != CODEC_ID_SRT) {
> +        av_log(avf, AV_LOG_ERROR,
> +               "Unsupported subtitles codec: %s\n",
> +               avcodec_get_name(avf->streams[0]->codec->codec_id));
> +        return AVERROR(EINVAL);
> +    }
> +    avpriv_set_pts_info(avf->streams[0], 64, 1, 1000);
> +    return 0;
> +}
> +
> +static int srt_write_packet(AVFormatContext *avf, AVPacket *pkt)
> +{
> +    SRTContext *srt = avf->priv_data;
> +    int write_ts = avf->streams[0]->codec->codec_id != CODEC_ID_SRT;
> +

Can't this be moved to the SRTContext?

> +    srt->index++;

This could be in the write ts scope.

The rest LGTM. Another approach would be to try to detect the mode
according to the received packet.

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120617/a24bcedb/attachment.asc>


More information about the ffmpeg-devel mailing list