1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Merge commit '5e9c6ef8f3beb9ed7b271654a82349ac90fe43f2'

* commit '5e9c6ef8f3beb9ed7b271654a82349ac90fe43f2':
  x86: h264_weight_10bit: port to cpuflags
  libtheoraenc: add missing pixdesc.h header
  avcodec: remove ff_is_hwaccel_pix_fmt
  pixdesc: add av_pix_fmt_get_chroma_sub_sample
  hlsenc: stand alone hls segmenter

Conflicts:
	doc/muxers.texi
	libavcodec/ffv1enc.c
	libavcodec/imgconvert.c
	libavcodec/mpegvideo_enc.c
	libavcodec/tiffenc.c
	libavformat/Makefile
	libavformat/allformats.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2012-11-14 11:22:40 +01:00
commit e13d5e9a4b
15 changed files with 465 additions and 89 deletions

View File

@ -129,6 +129,27 @@ ffmpeg -i INPUT -f framemd5 -
See also the @ref{md5} muxer.
@anchor{hls}
@section hls
Apple HTTP Live Streaming muxer that segments MPEG-TS according to
the HTTP Live Streaming specification.
It creates a playlist file and numbered segment files. The output
filename specifies the playlist filename; the segment filenames
receive the same basename as the playlist, a sequential number and
a .ts extension.
@example
ffmpeg -i in.nut out.m3u8
@end example
@table @option
@item -hls_time segment length in seconds
@item -hls_list_size maximum number of playlist entries
@item -hls_wrap number after which index wraps
@end table
@anchor{ico}
@section ico

View File

@ -4579,7 +4579,11 @@ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width,
* @{
*/
void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift);
/**
* @deprecated Use av_pix_fmt_get_chroma_sub_sample
*/
void attribute_deprecated avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift);
/**
* Return a value representing the fourCC code associated to the

View File

@ -431,12 +431,6 @@ void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int
*v_shift = desc->log2_chroma_h;
}
int ff_is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
return desc->flags & PIX_FMT_HWACCEL;
}
int avpicture_fill(AVPicture *picture, const uint8_t *ptr,
enum AVPixelFormat pix_fmt, int width, int height)
{

View File

@ -98,11 +98,6 @@ struct AVCodecDefault {
const uint8_t *value;
};
/**
* Determine whether pix_fmt is a hardware accelerated format.
*/
int ff_is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt);
/**
* Return the hardware accelerated codec for codec codec_id and
* pixel format pix_fmt.

View File

@ -33,6 +33,7 @@
/* FFmpeg includes */
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/pixdesc.h"
#include "libavutil/log.h"
#include "libavutil/base64.h"
#include "avcodec.h"

View File

@ -839,9 +839,8 @@ av_cold int ff_MPV_common_init(MpegEncContext *s)
s->flags = s->avctx->flags;
s->flags2 = s->avctx->flags2;
/* set chroma shifts */
avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &s->chroma_x_shift,
&s->chroma_y_shift);
/* set chroma shifts */
avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &s->chroma_x_shift, &s->chroma_y_shift);
/* convert fourcc to upper case */
s->codec_tag = avpriv_toupper4(s->avctx->codec_tag);
@ -1762,8 +1761,8 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict)
(s->codec_id == AV_CODEC_ID_H264 ? 0 : 1);
s->low_delay = 0; // needed to see the vectors without trashing the buffers
avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,
&h_chroma_shift, &v_chroma_shift);
avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift);
for (i = 0; i < 3; i++) {
size_t size= (i == 0) ? pict->linesize[i] * FFALIGN(height, 16):
pict->linesize[i] * FFALIGN(height, 16) >> v_chroma_shift;

View File

@ -29,6 +29,7 @@
#include "libavutil/intmath.h"
#include "libavutil/mathematics.h"
#include "libavutil/pixdesc.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "dsputil.h"
@ -687,8 +688,7 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
av_log(avctx, AV_LOG_DEBUG, "intra_quant_bias = %d inter_quant_bias = %d\n",s->intra_quant_bias,s->inter_quant_bias);
avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift,
&chroma_v_shift);
avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, &chroma_v_shift);
if (avctx->codec_id == AV_CODEC_ID_MPEG4 &&
s->avctx->time_base.den > (1 << 16) - 1) {
@ -1074,8 +1074,7 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg)
// empty
} else {
int h_chroma_shift, v_chroma_shift;
avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift,
&v_chroma_shift);
avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift);
for (i = 0; i < 3; i++) {
int src_stride = pic_arg->linesize[i];

View File

@ -293,8 +293,7 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt,
case AV_PIX_FMT_YUV410P:
case AV_PIX_FMT_YUV411P:
s->photometric_interpretation = 6;
avcodec_get_chroma_sub_sample(avctx->pix_fmt,
&shift_h, &shift_v);
avcodec_get_chroma_sub_sample(avctx->pix_fmt, &shift_h, &shift_v);
s->subsampling[0] = 1 << shift_h;
s->subsampling[1] = 1 << shift_v;
is_yuv = 1;

View File

@ -491,7 +491,8 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);
const int pixel_size = desc->comp[0].step_minus1 + 1;
avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
av_pix_fmt_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift,
&v_chroma_shift);
avcodec_align_dimensions2(s, &w, &h, stride_align);
@ -689,9 +690,15 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2,
return 0;
}
static int is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
return desc->flags & PIX_FMT_HWACCEL;
}
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
{
while (*fmt != AV_PIX_FMT_NONE && ff_is_hwaccel_pix_fmt(*fmt))
while (*fmt != AV_PIX_FMT_NONE && is_hwaccel_pix_fmt(*fmt))
++fmt;
return fmt[0];
}

View File

@ -48,7 +48,7 @@ SECTION .text
movifnidn r5d, r5m
%endmacro
%macro WEIGHT_SETUP 1
%macro WEIGHT_SETUP 0
mova m0, [pw_1]
movd m2, r3m
pslld m0, m2 ; 1<<log2_denom
@ -59,19 +59,19 @@ SECTION .text
pshufd m3, m3, 0
mova m4, [pw_pixel_max]
paddw m2, [sq_1] ; log2_denom+1
%ifnidn %1, sse4
%if notcpuflag(sse4)
pxor m7, m7
%endif
%endmacro
%macro WEIGHT_OP 2-3
%if %0==2
mova m5, [r0+%2]
%macro WEIGHT_OP 1-2
%if %0==1
mova m5, [r0+%1]
punpckhwd m6, m5, m0
punpcklwd m5, m0
%else
movq m5, [r0+%2]
movq m6, [r0+%3]
movq m5, [r0+%1]
movq m6, [r0+%2]
punpcklwd m5, m0
punpcklwd m6, m0
%endif
@ -79,7 +79,7 @@ SECTION .text
pmaddwd m6, m3
psrad m5, m2
psrad m6, m2
%ifidn %1, sse4
%if cpuflag(sse4)
packusdw m5, m6
pminsw m5, m4
%else
@ -88,14 +88,14 @@ SECTION .text
%endif
%endmacro
%macro WEIGHT_FUNC_DBL 1
cglobal h264_weight_16_10_%1
%macro WEIGHT_FUNC_DBL 0
cglobal h264_weight_16_10
WEIGHT_PROLOGUE
WEIGHT_SETUP %1
WEIGHT_SETUP
.nextrow:
WEIGHT_OP %1, 0
WEIGHT_OP 0
mova [r0 ], m5
WEIGHT_OP %1, 16
WEIGHT_OP 16
mova [r0+16], m5
add r0, r1
dec r2d
@ -103,17 +103,18 @@ cglobal h264_weight_16_10_%1
REP_RET
%endmacro
INIT_XMM
WEIGHT_FUNC_DBL sse2
WEIGHT_FUNC_DBL sse4
INIT_XMM sse2
WEIGHT_FUNC_DBL
INIT_XMM sse4
WEIGHT_FUNC_DBL
%macro WEIGHT_FUNC_MM 1
cglobal h264_weight_8_10_%1
%macro WEIGHT_FUNC_MM 0
cglobal h264_weight_8_10
WEIGHT_PROLOGUE
WEIGHT_SETUP %1
WEIGHT_SETUP
.nextrow:
WEIGHT_OP %1, 0
WEIGHT_OP 0
mova [r0], m5
add r0, r1
dec r2d
@ -121,19 +122,20 @@ cglobal h264_weight_8_10_%1
REP_RET
%endmacro
INIT_XMM
WEIGHT_FUNC_MM sse2
WEIGHT_FUNC_MM sse4
INIT_XMM sse2
WEIGHT_FUNC_MM
INIT_XMM sse4
WEIGHT_FUNC_MM
%macro WEIGHT_FUNC_HALF_MM 1
cglobal h264_weight_4_10_%1
%macro WEIGHT_FUNC_HALF_MM 0
cglobal h264_weight_4_10
WEIGHT_PROLOGUE
sar r2d, 1
WEIGHT_SETUP %1
WEIGHT_SETUP
lea r3, [r1*2]
.nextrow:
WEIGHT_OP %1, 0, r1
WEIGHT_OP 0, r1
movh [r0], m5
movhps [r0+r1], m5
add r0, r3
@ -142,9 +144,10 @@ cglobal h264_weight_4_10_%1
REP_RET
%endmacro
INIT_XMM
WEIGHT_FUNC_HALF_MM sse2
WEIGHT_FUNC_HALF_MM sse4
INIT_XMM sse2
WEIGHT_FUNC_HALF_MM
INIT_XMM sse4
WEIGHT_FUNC_HALF_MM
;-----------------------------------------------------------------------------
@ -168,7 +171,7 @@ DECLARE_REG_TMP 7
movifnidn t0d, r7m
%endmacro
%macro BIWEIGHT_SETUP 1
%macro BIWEIGHT_SETUP 0
lea t0, [t0*4+1] ; (offset<<2)+1
or t0, 1
shl r6, 16
@ -182,23 +185,23 @@ DECLARE_REG_TMP 7
pshufd m5, m5, 0
mova m3, [pw_pixel_max]
movifnidn r3d, r3m
%ifnidn %1, sse4
%if notcpuflag(sse4)
pxor m7, m7
%endif
%endmacro
%macro BIWEIGHT 2-3
%if %0==2
mova m0, [r0+%2]
mova m1, [r1+%2]
%macro BIWEIGHT 1-2
%if %0==1
mova m0, [r0+%1]
mova m1, [r1+%1]
punpckhwd m2, m0, m1
punpcklwd m0, m1
%else
movq m0, [r0+%2]
movq m1, [r1+%2]
movq m0, [r0+%1]
movq m1, [r1+%1]
punpcklwd m0, m1
movq m2, [r0+%3]
movq m1, [r1+%3]
movq m2, [r0+%2]
movq m1, [r1+%2]
punpcklwd m2, m1
%endif
pmaddwd m0, m4
@ -207,7 +210,7 @@ DECLARE_REG_TMP 7
paddd m2, m5
psrad m0, m6
psrad m2, m6
%ifidn %1, sse4
%if cpuflag(sse4)
packusdw m0, m2
pminsw m0, m3
%else
@ -216,14 +219,14 @@ DECLARE_REG_TMP 7
%endif
%endmacro
%macro BIWEIGHT_FUNC_DBL 1
cglobal h264_biweight_16_10_%1
%macro BIWEIGHT_FUNC_DBL 0
cglobal h264_biweight_16_10
BIWEIGHT_PROLOGUE
BIWEIGHT_SETUP %1
BIWEIGHT_SETUP
.nextrow:
BIWEIGHT %1, 0
BIWEIGHT 0
mova [r0 ], m0
BIWEIGHT %1, 16
BIWEIGHT 16
mova [r0+16], m0
add r0, r2
add r1, r2
@ -232,16 +235,17 @@ cglobal h264_biweight_16_10_%1
REP_RET
%endmacro
INIT_XMM
BIWEIGHT_FUNC_DBL sse2
BIWEIGHT_FUNC_DBL sse4
INIT_XMM sse2
BIWEIGHT_FUNC_DBL
INIT_XMM sse4
BIWEIGHT_FUNC_DBL
%macro BIWEIGHT_FUNC 1
cglobal h264_biweight_8_10_%1
%macro BIWEIGHT_FUNC 0
cglobal h264_biweight_8_10
BIWEIGHT_PROLOGUE
BIWEIGHT_SETUP %1
BIWEIGHT_SETUP
.nextrow:
BIWEIGHT %1, 0
BIWEIGHT 0
mova [r0], m0
add r0, r2
add r1, r2
@ -250,18 +254,19 @@ cglobal h264_biweight_8_10_%1
REP_RET
%endmacro
INIT_XMM
BIWEIGHT_FUNC sse2
BIWEIGHT_FUNC sse4
INIT_XMM sse2
BIWEIGHT_FUNC
INIT_XMM sse4
BIWEIGHT_FUNC
%macro BIWEIGHT_FUNC_HALF 1
cglobal h264_biweight_4_10_%1
%macro BIWEIGHT_FUNC_HALF 0
cglobal h264_biweight_4_10
BIWEIGHT_PROLOGUE
BIWEIGHT_SETUP %1
BIWEIGHT_SETUP
sar r3d, 1
lea r4, [r2*2]
.nextrow:
BIWEIGHT %1, 0, r2
BIWEIGHT 0, r2
movh [r0 ], m0
movhps [r0+r2], m0
add r0, r4
@ -271,6 +276,7 @@ cglobal h264_biweight_4_10_%1
REP_RET
%endmacro
INIT_XMM
BIWEIGHT_FUNC_HALF sse2
BIWEIGHT_FUNC_HALF sse4
INIT_XMM sse2
BIWEIGHT_FUNC_HALF
INIT_XMM sse4
BIWEIGHT_FUNC_HALF

View File

@ -125,6 +125,7 @@ OBJS-$(CONFIG_H263_MUXER) += rawenc.o
OBJS-$(CONFIG_H264_DEMUXER) += h264dec.o rawdec.o
OBJS-$(CONFIG_H264_MUXER) += rawenc.o
OBJS-$(CONFIG_HLS_DEMUXER) += hls.o
OBJS-$(CONFIG_HLS_MUXER) += hlsenc.o mpegtsenc.o
OBJS-$(CONFIG_ICO_DEMUXER) += icodec.o
OBJS-$(CONFIG_ICO_MUXER) += icoenc.o
OBJS-$(CONFIG_IDCIN_DEMUXER) += idcin.o

View File

@ -114,7 +114,7 @@ void av_register_all(void)
REGISTER_MUXDEMUX (H261, h261);
REGISTER_MUXDEMUX (H263, h263);
REGISTER_MUXDEMUX (H264, h264);
REGISTER_DEMUXER (HLS, hls);
REGISTER_MUXDEMUX (HLS, hls);
REGISTER_MUXDEMUX (ICO, ico);
REGISTER_DEMUXER (IDCIN, idcin);
REGISTER_DEMUXER (IDF, idf);

324
libavformat/hlsenc.c Normal file
View File

@ -0,0 +1,324 @@
/*
* Apple HTTP Live Streaming segmenter
* Copyright (c) 2012, Luca Barbato
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <float.h>
#include "libavutil/mathematics.h"
#include "libavutil/parseutils.h"
#include "libavutil/avstring.h"
#include "libavutil/opt.h"
#include "libavutil/log.h"
#include "avformat.h"
#include "internal.h"
typedef struct ListEntry {
char name[1024];
int duration;
struct ListEntry *next;
} ListEntry;
typedef struct HLSContext {
const AVClass *class; // Class for private options.
int number;
AVOutputFormat *oformat;
AVFormatContext *avf;
float time; // Set by a private option.
int size; // Set by a private option.
int wrap; // Set by a private option.
int64_t recording_time;
int has_video;
int64_t start_pts;
int64_t end_pts;
ListEntry *list;
ListEntry *end_list;
char *basename;
AVIOContext *pb;
} HLSContext;
static int hls_mux_init(AVFormatContext *s)
{
HLSContext *hls = s->priv_data;
AVFormatContext *oc;
int i;
hls->avf = oc = avformat_alloc_context();
if (!oc)
return AVERROR(ENOMEM);
oc->oformat = hls->oformat;
oc->interrupt_callback = s->interrupt_callback;
for (i = 0; i < s->nb_streams; i++) {
AVStream *st;
if (!(st = avformat_new_stream(oc, NULL)))
return AVERROR(ENOMEM);
avcodec_copy_context(st->codec, s->streams[i]->codec);
st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
}
return 0;
}
static int append_entry(HLSContext *hls, uint64_t duration)
{
ListEntry *en = av_malloc(sizeof(*en));
if (!en)
return AVERROR(ENOMEM);
av_get_frame_filename(en->name, sizeof(en->name), hls->basename,
hls->number -1);
en->duration = duration;
en->next = NULL;
if (!hls->list)
hls->list = en;
else
hls->end_list->next = en;
hls->end_list = en;
if (hls->number >= hls->size) {
en = hls->list;
hls->list = en->next;
av_free(en);
}
return 0;
}
static void free_entries(HLSContext *hls)
{
ListEntry *p = hls->list, *en;
while(p) {
en = p;
p = p->next;
av_free(en);
}
}
static int hls_window(AVFormatContext *s, int last)
{
HLSContext *hls = s->priv_data;
ListEntry *en;
int ret = 0;
if ((ret = avio_open2(&hls->pb, s->filename, AVIO_FLAG_WRITE,
&s->interrupt_callback, NULL)) < 0)
goto fail;
avio_printf(hls->pb, "#EXTM3U\n");
avio_printf(hls->pb, "#EXT-X-VERSION:3\n");
avio_printf(hls->pb, "#EXT-X-TARGETDURATION:%d\n", (int)hls->time);
avio_printf(hls->pb, "#EXT-X-MEDIA-SEQUENCE:%d\n",
FFMAX(0, hls->number - hls->size));
for (en = hls->list; en; en = en->next) {
avio_printf(hls->pb, "#EXTINF:%d,\n", en->duration);
avio_printf(hls->pb, "%s\n", en->name);
}
if (last)
avio_printf(hls->pb, "#EXT-X-ENDLIST\n");
fail:
avio_closep(&hls->pb);
return ret;
}
static int hls_start(AVFormatContext *s)
{
HLSContext *c = s->priv_data;
AVFormatContext *oc = c->avf;
int err = 0;
if (c->wrap)
c->number %= c->wrap;
if (av_get_frame_filename(oc->filename, sizeof(oc->filename),
c->basename, c->number++) < 0)
return AVERROR(EINVAL);
if ((err = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,
&s->interrupt_callback, NULL)) < 0)
return err;
if (oc->oformat->priv_class && oc->priv_data)
av_opt_set(oc->priv_data, "mpegts_flags", "resend_headers", 0);
return 0;
}
static int hls_write_header(AVFormatContext *s)
{
HLSContext *hls = s->priv_data;
int ret, i;
char *p;
const char *pattern = "%d.ts";
int basename_size = strlen(s->filename) + strlen(pattern);
hls->number = 0;
hls->recording_time = hls->time * 1000000;
hls->start_pts = AV_NOPTS_VALUE;
for (i = 0; i < s->nb_streams; i++)
hls->has_video +=
s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO;
if (hls->has_video > 1)
av_log(s, AV_LOG_WARNING,
"More than a single video stream present, "
"expect issues decoding it.\n");
hls->oformat = av_guess_format("mpegts", NULL, NULL);
if (!hls->oformat) {
ret = AVERROR_MUXER_NOT_FOUND;
goto fail;
}
hls->basename = av_malloc(basename_size);
if (!hls->basename) {
ret = AVERROR(ENOMEM);
goto fail;
}
strcpy(hls->basename, s->filename);
p = strrchr(hls->basename, '.');
if (p)
*p = '\0';
av_strlcat(hls->basename, "%d.ts", basename_size);
if ((ret = hls_mux_init(s)) < 0)
goto fail;
if ((ret = hls_start(s)) < 0)
goto fail;
if ((ret = avformat_write_header(hls->avf, NULL)) < 0)
return ret;
fail:
if (ret) {
av_free(hls->basename);
if (hls->avf)
avformat_free_context(hls->avf);
}
return ret;
}
static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
{
HLSContext *hls = s->priv_data;
AVFormatContext *oc = hls->avf;
AVStream *st = s->streams[pkt->stream_index];
int64_t end_pts = hls->recording_time * hls->number;
int ret;
if (hls->start_pts == AV_NOPTS_VALUE) {
hls->start_pts = pkt->pts;
hls->end_pts = pkt->pts;
}
end_pts += hls->start_pts;
if ((hls->has_video && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&
av_compare_ts(pkt->pts, st->time_base, end_pts, AV_TIME_BASE_Q) >= 0 &&
pkt->flags & AV_PKT_FLAG_KEY) {
append_entry(hls, av_rescale(pkt->pts - hls->end_pts,
st->time_base.num,
st->time_base.den));
hls->end_pts = pkt->pts;
av_write_frame(oc, NULL); /* Flush any buffered data */
avio_close(oc->pb);
ret = hls_start(s);
if (ret)
return ret;
oc = hls->avf;
if ((ret = hls_window(s, 0)) < 0)
return ret;
}
ret = ff_write_chained(oc, pkt->stream_index, pkt, s);
return ret;
}
static int hls_write_trailer(struct AVFormatContext *s)
{
HLSContext *hls = s->priv_data;
AVFormatContext *oc = hls->avf;
av_write_trailer(oc);
avio_closep(&oc->pb);
avformat_free_context(oc);
av_free(hls->basename);
hls_window(s, 1);
free_entries(hls);
avio_close(hls->pb);
return 0;
}
#define OFFSET(x) offsetof(HLSContext, x)
#define E AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
{"hls_time", "segment length in seconds", OFFSET(time), AV_OPT_TYPE_FLOAT, {.dbl = 2}, 0, FLT_MAX, E},
{"hls_list_size", "maximum number of playlist entries", OFFSET(size), AV_OPT_TYPE_INT, {.i64 = 5}, 0, INT_MAX, E},
{"hls_wrap", "number after which the index wraps", OFFSET(wrap), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E},
{ NULL },
};
static const AVClass hls_class = {
.class_name = "hls muxer",
.item_name = av_default_item_name,
.option = options,
.version = LIBAVUTIL_VERSION_INT,
};
AVOutputFormat ff_hls_muxer = {
.name = "hls",
.long_name = NULL_IF_CONFIG_SMALL("hls"),
.extensions = "m3u8",
.priv_data_size = sizeof(HLSContext),
.audio_codec = AV_CODEC_ID_MP2,
.video_codec = AV_CODEC_ID_MPEG2VIDEO,
.flags = AVFMT_NOFILE | AVFMT_ALLOW_FLUSH,
.write_header = hls_write_header,
.write_packet = hls_write_packet,
.write_trailer = hls_write_trailer,
.priv_class = &hls_class,
};

View File

@ -1749,3 +1749,15 @@ enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
return desc - av_pix_fmt_descriptors;
}
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt,
int *h_shift, int *v_shift)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
if (!desc)
return AVERROR(ENOSYS);
*h_shift = desc->log2_chroma_w;
*v_shift = desc->log2_chroma_h;
return 0;
}

View File

@ -206,4 +206,18 @@ const AVPixFmtDescriptor *av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev);
*/
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc);
/**
* Utility function to access log2_chroma_w log2_chroma_h from
* the pixel format AVPixFmtDescriptor.
*
* @param[in] pix_fmt the pixel format
* @param[out] h_shift store log2_chroma_h
* @param[out] v_shift store log2_chroma_w
*
* @return 0 on success, AVERROR(ENOSYS) on invalid or unknown pixel format
*/
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt,
int *h_shift, int *v_shift);
#endif /* AVUTIL_PIXDESC_H */