GET_HW_PIXFMT(vdpau, AV_PIX_FMT_VDPAU)
GET_HW_PIXFMT(cuda, AV_PIX_FMT_CUDA)
GET_HW_PIXFMT(nv12, AV_PIX_FMT_NV12)
+GET_HW_PIXFMT(vulkan, AV_PIX_FMT_VULKAN)
static enum AVPixelFormat get_hw_format(AVCodecContext *ctx,
const enum AVPixelFormat *pix_fmts)
case AV_PIX_FMT_VDPAU: ctx->get_format = get_hw_vdpau; return *p;
case AV_PIX_FMT_CUDA: ctx->get_format = get_hw_cuda; return *p;
case AV_PIX_FMT_NV12: ctx->get_format = get_hw_nv12; return *p;
+ case AV_PIX_FMT_VULKAN: ctx->get_format = get_hw_vulkan; return *p;
default:
fprintf(stderr, "Unknown HW surface format: %s\n",
av_get_pix_fmt_name(*p));
if ( ret == AVERROR(EAGAIN) && !frame ) continue;
FFPacket opkt;
ret = avcodec_receive_packet(avctx, opkt);
- if( !frame && ret == AVERROR_EOF ) return pkts;
- if( ret < 0 ) break;
+ if( !frame && (ret == AVERROR_EOF || ret == AVERROR(EAGAIN) )) return pkts;
+ //if( ret < 0 ) break;
ret = write_packet(opkt);
if( ret < 0 ) break;
++pkts;
swr_ichs = ichs; swr_ifmt = ifmt; swr_irate = irate;
if( ichs == channels && ifmt == AV_SAMPLE_FMT_FLT && irate == sample_rate )
return;
- uint64_t ilayout = av_get_default_channel_layout(ichs);
- if( !ilayout ) ilayout = ((uint64_t)1<<ichs) - 1;
- uint64_t olayout = av_get_default_channel_layout(channels);
- if( !olayout ) olayout = ((uint64_t)1<<channels) - 1;
- resample_context = swr_alloc_set_opts(NULL,
- olayout, AV_SAMPLE_FMT_FLT, sample_rate,
- ilayout, (AVSampleFormat)ifmt, irate,
+ //uint64_t ilayout = av_get_default_channel_layout(ichs);
+ AVChannelLayout ilayout, olayout;
+ av_channel_layout_default(&ilayout, ichs);
+ //if( !ilayout ) ilayout = ((uint64_t)1<<ichs) - 1;
+ //uint64_t olayout = av_get_default_channel_layout(channels);
+ av_channel_layout_default(&olayout, channels);
+ //if( !olayout ) olayout = ((uint64_t)1<<channels) - 1;
+
+ swr_alloc_set_opts2(&resample_context,
+ &olayout, AV_SAMPLE_FMT_FLT, sample_rate,
+ &ilayout, (AVSampleFormat)ifmt, irate,
0, NULL);
if( resample_context )
swr_init(resample_context);
int64_t FFAudioStream::load_buffer(double ** const sp, int len)
{
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61,3,100)
+ reserve(len+1, st->codecpar->ch_layout.nb_channels);
+#else
reserve(len+1, st->codecpar->channels);
+#endif
for( int ch=0; ch<nch; ++ch )
write(sp[ch], len, ch);
return put_inp(len);
{
frame->nb_samples = frame_sz;
frame->format = avctx->sample_fmt;
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61,3,100)
+ frame->ch_layout.u.mask = avctx->ch_layout.u.mask;
+ av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
+#else
frame->channel_layout = avctx->channel_layout;
+#endif
frame->sample_rate = avctx->sample_rate;
int ret = av_frame_get_buffer(frame, 0);
if (ret < 0)
while( ret>=0 && !flushed && curr_pos<end_pos && --i>=0 ) {
ret = read_frame(frame);
if( ret > 0 && frame->nb_samples > 0 ) {
- init_swr(frame->channels, frame->format, frame->sample_rate);
+ init_swr(frame->ch_layout.nb_channels, frame->format, frame->sample_rate);
load_history(&frame->extended_data[0], frame->nb_samples);
curr_pos += frame->nb_samples;
}
return ret;
}
-AVHWDeviceType FFVideoStream::encode_hw_activate(const char *hw_dev)
+AVHWDeviceType FFVideoStream::encode_hw_activate(const char *hw_dev, const char *hw_sformat)
{
const char *drm_node_enc = getenv("CIN_DRM_ENC");
AVBufferRef *hw_device_ctx = 0;
AVHWFramesContext *frames_ctx = (AVHWFramesContext *)(hw_frames_ref->data);
frames_ctx->format = AV_PIX_FMT_VAAPI;
frames_ctx->sw_format = AV_PIX_FMT_NV12;
+ if (strcmp(hw_sformat, "vaapi")) frames_ctx->sw_format = av_get_pix_fmt(hw_sformat);
frames_ctx->width = width;
frames_ctx->height = height;
frames_ctx->initial_pool_size = 0; // 200;
const char *rg = av_color_range_name(range);
report("/ range:%s\n", rg ? rg : unkn);
+ enum AVColorPrimaries primaries = st->codecpar->color_primaries;
+ const char *pr = av_color_primaries_name(primaries);
+ report(" color primaries:%s", pr ? pr : unkn);
+ enum AVColorTransferCharacteristic trc = st->codecpar->color_trc;
+ const char *transfer = av_color_transfer_name(trc);
+ report("/ transfer characteristics:%s\n", transfer ? transfer : unkn);
+
+
AVRational sar = av_guess_sample_aspect_ratio(fmt_ctx, st, NULL);
AVRational display_aspect_ratio;
if(sar.num) {
ret = vid->create_filter(opt_video_filter);
break; }
case AVMEDIA_TYPE_AUDIO: {
- if( avpar->channels < 1 ) continue;
+ if( avpar->ch_layout.nb_channels < 1 ) continue;
if( avpar->sample_rate < 1 ) continue;
has_audio = 1;
int aidx = ffaudio.size();
FFAudioStream *aud = new FFAudioStream(this, st, aidx, i);
ffaudio.append(aud);
aud->channel0 = astrm_index.size();
- aud->channels = avpar->channels;
+ aud->channels = avpar->ch_layout.nb_channels;
for( int ch=0; ch<aud->channels; ++ch )
astrm_index.append(ffidx(aidx, ch));
aud->sample_rate = avpar->sample_rate;
FFStream *fst = 0;
AVStream *st = 0;
AVCodecContext *ctx = 0;
+
+ /* some encoders dislike ildct flag in ffmpeg 7.0/7.1 */
+ int is_no_ildct;
+ if (!strcmp (codec_name, "av1_qsv") ||
+ !strcmp(codec_name, "h264_qsv") ||
+ !strcmp(codec_name, "vp9_qsv"))
+ is_no_ildct=1;
+ else
+ is_no_ildct=0;
+
const AVCodecDescriptor *codec_desc = 0;
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
FFAudioStream *aud = new FFAudioStream(this, st, aidx, fidx);
aud->avctx = ctx; ffaudio.append(aud); fst = aud;
aud->sample_rate = asset->sample_rate;
- ctx->channels = aud->channels = asset->channels;
+ ctx->ch_layout.nb_channels = aud->channels = asset->channels;
for( int ch=0; ch<aud->channels; ++ch )
astrm_index.append(ffidx(aidx, ch));
- ctx->channel_layout = av_get_default_channel_layout(ctx->channels);
+ AVChannelLayout ch_layout;
+ av_channel_layout_default(&ch_layout, ctx->ch_layout.nb_channels);
+ ctx->ch_layout.u.mask = ch_layout.u.mask;
+ av_channel_layout_copy(&ctx->ch_layout, &ch_layout);
ctx->sample_rate = check_sample_rate(codec, asset->sample_rate);
if( !ctx->sample_rate ) {
eprintf(_("check_sample_rate failed %s\n"), filename);
if( sample_fmt == AV_SAMPLE_FMT_NONE )
sample_fmt = codec->sample_fmts ? codec->sample_fmts[0] : AV_SAMPLE_FMT_S16;
ctx->sample_fmt = sample_fmt;
- uint64_t layout = av_get_default_channel_layout(ctx->channels);
- aud->resample_context = swr_alloc_set_opts(NULL,
- layout, ctx->sample_fmt, aud->sample_rate,
- layout, AV_SAMPLE_FMT_FLT, ctx->sample_rate,
+ //uint64_t layout = av_get_default_channel_layout(ctx->ch_layout.nb_channels);
+ AVChannelLayout layout;
+ av_channel_layout_default(&layout, ctx->ch_layout.nb_channels);
+ swr_alloc_set_opts2(&aud->resample_context,
+ &layout, ctx->sample_fmt, aud->sample_rate,
+ &layout, AV_SAMPLE_FMT_FLT, ctx->sample_rate,
0, NULL);
swr_init(aud->resample_context);
aud->writing = -1;
}
AVPixelFormat pix_fmt = av_get_pix_fmt(asset->ff_pixel_format);
if( opt_hw_dev != 0 ) {
- AVHWDeviceType hw_type = vid->encode_hw_activate(opt_hw_dev);
+ AVHWDeviceType hw_type = vid->encode_hw_activate(opt_hw_dev, asset->ff_pixel_format);
switch( hw_type ) {
case AV_HWDEVICE_TYPE_VAAPI:
pix_fmt = AV_PIX_FMT_VAAPI;
av_dict_set(&sopts, "field_order", "tt", 0);
else
av_dict_set(&sopts, "field_order", "tb", 0);
- if (ctx->codec_id != AV_CODEC_ID_MJPEG)
+ if (ctx->codec_id != AV_CODEC_ID_MJPEG && !is_no_ildct)
av_dict_set(&sopts, "flags", "+ilme+ildct", 0);
break;
case ILACE_MODE_BOTTOM_FIRST:
av_dict_set(&sopts, "field_order", "bb", 0);
else
av_dict_set(&sopts, "field_order", "bt", 0);
- if (ctx->codec_id != AV_CODEC_ID_MJPEG)
+ if (ctx->codec_id != AV_CODEC_ID_MJPEG && !is_no_ildct)
av_dict_set(&sopts, "flags", "+ilme+ildct", 0);
break;
case ILACE_MODE_NOTINTERLACED: av_dict_set(&sopts, "field_order", "progressive", 0); break;
snprintf(args, sizeof(args),
"time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%jx",
st->time_base.num, st->time_base.den, avpar->sample_rate,
- av_get_sample_fmt_name(sample_fmt), avpar->channel_layout);
+ av_get_sample_fmt_name(sample_fmt), avpar->ch_layout.u.mask);
if( ret >= 0 ) {
filt_ctx = 0;
ret = insert_filter("abuffer", args, "in");
AV_OPT_SEARCH_CHILDREN);
if( ret >= 0 )
ret = av_opt_set_bin(buffersink_ctx, "channel_layouts",
- (uint8_t*)&avpar->channel_layout,
- sizeof(avpar->channel_layout), AV_OPT_SEARCH_CHILDREN);
+ (uint8_t*)&avpar->ch_layout.u.mask,
+ sizeof(avpar->ch_layout.u.mask), AV_OPT_SEARCH_CHILDREN);
if( ret >= 0 )
ret = av_opt_set_bin(buffersink_ctx, "sample_rates",
(uint8_t*)&sample_rate, sizeof(sample_rate),
}
while( (ret=aud->decode_frame(frame)) > 0 ) {
//if( frame->channels != nch ) break;
- aud->init_swr(frame->channels, frame->format, frame->sample_rate);
+ aud->init_swr(frame->ch_layout.nb_channels, frame->format, frame->sample_rate);
float *samples;
int len = aud->get_samples(samples,
&frame->extended_data[0], frame->nb_samples);