Skip to content

About GPU decoding and encoding #132

@mojie126

Description

@mojie126

#99
According to the description in this issue, the device supports cuda, and cuda is also used during encoding and decoding, but it fails.
cuda code

#include <iostream>
#include <set>
#include <map>
#include <memory>
#include <functional>

#include "../include/avcpp/av.h"
#include "../include/avcpp/ffmpeg.h"
#include "../include/avcpp/codec.h"
#include "../include/avcpp/packet.h"
#include "../include/avcpp/videorescaler.h"
#include "../include/avcpp/audioresampler.h"
#include "../include/avcpp/avutils.h"

// API2
#include "../include/avcpp/format.h"
#include "../include/avcpp/formatcontext.h"
#include "../include/avcpp/codec.h"
#include "../include/avcpp/codeccontext.h"

using namespace std;
using namespace av;


// 检测CUDA是否可用
bool isCudaAvailable() {
	AVHWDeviceType type = av_hwdevice_find_type_by_name("cuda");
	return type != AV_HWDEVICE_TYPE_NONE;
}

// 检测QSV是否可用
bool isQsvAvailable() {
	AVHWDeviceType type = av_hwdevice_find_type_by_name("qsv");
	return type != AV_HWDEVICE_TYPE_NONE;
}

// 获取编码器
const AVCodec *getEncoder(bool use_cuda, bool use_qsv) {
	if (use_cuda) {
		const AVCodec *cuda_encoder = avcodec_find_encoder_by_name("h264_nvenc");
		if (cuda_encoder)
			return cuda_encoder;
	}
	if (use_qsv) {
		const AVCodec *qsv_encoder = avcodec_find_encoder_by_name("h264_qsv");
		if (qsv_encoder)
			return qsv_encoder;
	}
	return avcodec_find_encoder_by_name("libx264"); // 使用软编码器
}

// 获取硬件上下文类型
AVHWDeviceType getHwDeviceType(bool use_cuda, bool use_qsv) {
	if (use_cuda)
		return av_hwdevice_find_type_by_name("cuda");
	if (use_qsv)
		return av_hwdevice_find_type_by_name("qsv");
	return AV_HWDEVICE_TYPE_NONE;
}

int main(int argc, char **argv) {
	if (argc < 3)
		return 1;

	av::init();
	av::setFFmpegLoggingLevel(AV_LOG_DEBUG);

	string uri{argv[1]};
	string out{argv[2]};

	error_code ec;

	//
	// INPUT
	//
	FormatContext ictx;
	ssize_t videoStream = -1;
	// VideoDecoderContext vdec;
	Stream vst;

	int count = 0;

	ictx.openInput(uri, ec);
	if (ec) {
		cerr << "Can't open input\n";
		return 1;
	}

	ictx.findStreamInfo();

	for (size_t i = 0; i < ictx.streamsCount(); ++i) {
		auto st = ictx.stream(i);
		if (st.mediaType() == AVMEDIA_TYPE_VIDEO) {
			videoStream = i;
			vst = st;
			break;
		}
	}
	bool use_cuda = isCudaAvailable();
	bool use_qsv = isQsvAvailable();
	// 获取编码器和硬件上下文类型
	const AVCodec *_encoder = getEncoder(use_cuda, use_qsv);
	AVHWDeviceType hw_type = getHwDeviceType(use_cuda, use_qsv);
	clog << "test hw: " << av_hwdevice_get_type_name(hw_type) << endl;

	if (vst.isNull()) {
		cerr << "Video stream not found\n";
		return 1;
	}
	av::VideoDecoderContext vdec(vst, av::findDecodingCodec("h264_cuvid"));
	clog << "decoder: " << av::findDecodingCodec("h264_cuvid").longName() << endl;

	if (vst.isValid()) {
		vdec = VideoDecoderContext(vst);
		vdec.setRefCountedFrames(true);

		vdec.open(Codec(), ec);
		if (ec) {
			cerr << "Can't open codec\n";
			return 1;
		}
	}


	//
	// OUTPUT
	//
	OutputFormat ofrmt;
	FormatContext octx;

	ofrmt.setFormat(string(), out);
	octx.setFormat(ofrmt);

	Codec ocodec = findEncodingCodec(ofrmt);
	ocodec.reset(_encoder);
	clog << "can encode: " << ocodec.canEncode() << endl;

	VideoEncoderContext encoder{ocodec};

	// Settings
	encoder.setWidth(vdec.width());
	encoder.setHeight(vdec.height());
	if (vdec.pixelFormat() > -1)
		encoder.setPixelFormat(vdec.pixelFormat());
	encoder.setTimeBase(Rational{1, 1000});
	encoder.setBitRate(vdec.bitRate());

	encoder.open(Codec(), ec);
	if (ec) {
		cerr << "Can't opent encodec\n";
		return 1;
	}

	Stream ost = octx.addStream(encoder);
	ost.setFrameRate(vst.frameRate());

	octx.openOutput(out, ec);
	if (ec) {
		cerr << "Can't open output\n";
		return 1;
	}

	octx.dump();
	octx.writeHeader();
	octx.flush();


	//
	// PROCESS
	//
	while (true) {
		// READING
		Packet pkt = ictx.readPacket(ec);
		if (ec) {
			clog << "Packet reading error: " << ec << ", " << ec.message() << endl;
			break;
		}

		bool flushDecoder = false;
		// !EOF
		if (pkt) {
			if (pkt.streamIndex() != videoStream) {
				continue;
			}

			clog << "Read packet: pts=" << pkt.pts() << ", dts=" << pkt.dts() << " / " << pkt.pts().seconds() << " / " << pkt.timeBase() << " / st: " << pkt.streamIndex() << endl;
		} else {
			flushDecoder = true;
		}

		do {
			// DECODING
			auto frame = vdec.decode(pkt, ec);

			count++;
			//if (count > 200)
			//    break;

			bool flushEncoder = false;

			if (ec) {
				cerr << "Decoding error: " << ec << endl;
				return 1;
			} else if (!frame) {
				//cerr << "Empty frame\n";
				//flushDecoder = false;
				//continue;

				if (flushDecoder) {
					flushEncoder = true;
				}
			}

			if (frame) {
				clog << "Frame: pts=" << frame.pts() << " / " << frame.pts().seconds() << " / " << frame.timeBase() << ", " << frame.width() << "x" << frame.height() << ", size=" << frame.size() << ", ref=" << frame.isReferenced() << ":" << frame.refCount() << " / type: " << frame.pictureType() << endl;

				// Change timebase
				frame.setTimeBase(encoder.timeBase());
				frame.setStreamIndex(0);
				frame.setPictureType();

				clog << "Frame: pts=" << frame.pts() << " / " << frame.pts().seconds() << " / " << frame.timeBase() << ", " << frame.width() << "x" << frame.height() << ", size=" << frame.size() << ", ref=" << frame.isReferenced() << ":" << frame.refCount() << " / type: " << frame.pictureType() << endl;
			}

			if (frame || flushEncoder) {
				do {
					// Encode
					Packet opkt = frame ? encoder.encode(frame, ec) : encoder.encode(ec);
					if (ec) {
						cerr << "Encoding error: " << ec << endl;
						return 1;
					} else if (!opkt) {
						//cerr << "Empty packet\n";
						//continue;
						break;
					}

					// Only one output stream
					opkt.setStreamIndex(0);

					clog << "Write packet: pts=" << opkt.pts() << ", dts=" << opkt.dts() << " / " << opkt.pts().seconds() << " / " << opkt.timeBase() << " / st: " << opkt.streamIndex() << endl;

					octx.writePacket(opkt, ec);
					if (ec) {
						cerr << "Error write packet: " << ec << ", " << ec.message() << endl;
						return 1;
					}
				} while (flushEncoder);
			}

			if (flushEncoder)
				break;
		} while (flushDecoder);

		if (flushDecoder)
			break;
	}

	octx.writeTrailer();
}

log

D:\CLionProjects\AssRocket\hwFFmpeg.exe mod/222.mp4 mod/333.mp4
[AVFormatContext @ 0000000000645340] Opening 'mod/222.mp4' for reading
[file @ 0000000000646780] Setting default whitelist 'file,crypto,data'
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000000645340] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000000645340] ISO: File Type Major Brand: isom
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000000645340] Unknown dref type 0x206c7275 size 12
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000000645340] Processing st: 0, edit list 0 - media time: 1024, duration: 2999296
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000000645340] Offset DTS by 1024 to make first pts zero.
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000000645340] Setting codecpar->delay to 2 for stream st: 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000000645340] Unknown dref type 0x206c7275 size 12
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000000645340] Processing st: 1, edit list 0 - media time: 1024, duration: 10332145
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000000645340] drop a frame at curr_cts: 0 @ 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000000645340] Before avformat_find_stream_info() pos: 110126 bytes read:131072 seeks:0 nb_streams:2
[h264 @ 0000000000647a00] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0000000000647a00] Decoding VUI
[h264 @ 0000000000647a00] nal_unit_type: 8(PPS), nal_ref_idc: 3
For transform of length 64, inverse, mdct_float, flags: [aligned, out_of_place], found 3 matches:
    1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
    2: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
    3: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
For transform of length 32, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 2 matches:
    1: fft32_asm_float_fma3 - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 512
    2: fft32_asm_float_avx - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 480
Transform tree:
    mdct_inv_float_avx2 - type: mdct_float, len: 64, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
        fft32_asm_float_fma3 - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
For transform of length 64, inverse, mdct_float, flags: [aligned, out_of_place], found 3 matches:
    1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
    2: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
    3: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
For transform of length 32, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 2 matches:
    1: fft32_asm_float_fma3 - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 512
    2: fft32_asm_float_avx - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 480
Transform tree:
    mdct_inv_float_avx2 - type: mdct_float, len: 64, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
        fft32_asm_float_fma3 - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
For transform of length 120, inverse, mdct_float, flags: [aligned, out_of_place], found 6 matches:
    1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
    2: mdct_pfa_15xM_inv_float_c - type: mdct_float, len: [30, ∞], factors[2]: [15, any], flags: [unaligned, out_of_place, inv_only], prio: 304
    3: mdct_pfa_5xM_inv_float_c - type: mdct_float, len: [10, ∞], factors[2]: [5, any], flags: [unaligned, out_of_place, inv_only], prio: 144
    4: mdct_pfa_3xM_inv_float_c - type: mdct_float, len: [6, ∞], factors[2]: [3, any], flags: [unaligned, out_of_place, inv_only], prio: 112
    5: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
    6: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
For transform of length 60, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 1 matches:
    1: fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: [60, ∞], factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 688
For transform of length 4, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 1 matches:
    1: fft4_fwd_asm_float_sse2 - type: fft_float, len: 4, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 352
Transform tree:
    mdct_inv_float_avx2 - type: mdct_float, len: 120, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
        fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: 60, factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call]
            fft4_fwd_asm_float_sse2 - type: fft_float, len: 4, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
For transform of length 128, inverse, mdct_float, flags: [aligned, out_of_place], found 3 matches:
    1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
    2: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
    3: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
For transform of length 64, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 3 matches:
    1: fft_sr_asm_float_avx2 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 480
    2: fft_sr_asm_float_fma3 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 448
    3: fft_sr_asm_float_avx - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 416
Transform tree:
    mdct_inv_float_avx2 - type: mdct_float, len: 128, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
        fft_sr_asm_float_avx2 - type: fft_float, len: 64, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
For transform of length 480, inverse, mdct_float, flags: [aligned, out_of_place], found 6 matches:
    1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
    2: mdct_pfa_15xM_inv_float_c - type: mdct_float, len: [30, ∞], factors[2]: [15, any], flags: [unaligned, out_of_place, inv_only], prio: 304
    3: mdct_pfa_5xM_inv_float_c - type: mdct_float, len: [10, ∞], factors[2]: [5, any], flags: [unaligned, out_of_place, inv_only], prio: 144
    4: mdct_pfa_3xM_inv_float_c - type: mdct_float, len: [6, ∞], factors[2]: [3, any], flags: [unaligned, out_of_place, inv_only], prio: 112
    5: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
    6: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
For transform of length 240, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 1 matches:
    1: fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: [60, ∞], factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 688
For transform of length 16, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 2 matches:
    1: fft16_asm_float_fma3 - type: fft_float, len: 16, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 512
    2: fft16_asm_float_avx - type: fft_float, len: 16, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 480
Transform tree:
    mdct_inv_float_avx2 - type: mdct_float, len: 480, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
        fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: 240, factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call]
            fft16_asm_float_fma3 - type: fft_float, len: 16, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
For transform of length 512, inverse, mdct_float, flags: [aligned, out_of_place], found 3 matches:
    1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
    2: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
    3: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
For transform of length 256, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 3 matches:
    1: fft_sr_asm_float_avx2 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 480
    2: fft_sr_asm_float_fma3 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 448
    3: fft_sr_asm_float_avx - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 416
Transform tree:
    mdct_inv_float_avx2 - type: mdct_float, len: 512, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
        fft_sr_asm_float_avx2 - type: fft_float, len: 256, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
For transform of length 960, inverse, mdct_float, flags: [aligned, out_of_place], found 6 matches:
    1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
    2: mdct_pfa_15xM_inv_float_c - type: mdct_float, len: [30, ∞], factors[2]: [15, any], flags: [unaligned, out_of_place, inv_only], prio: 304
    3: mdct_pfa_5xM_inv_float_c - type: mdct_float, len: [10, ∞], factors[2]: [5, any], flags: [unaligned, out_of_place, inv_only], prio: 144
    4: mdct_pfa_3xM_inv_float_c - type: mdct_float, len: [6, ∞], factors[2]: [3, any], flags: [unaligned, out_of_place, inv_only], prio: 112
    5: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
    6: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
For transform of length 480, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 1 matches:
    1: fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: [60, ∞], factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 688
For transform of length 32, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 2 matches:
    1: fft32_asm_float_fma3 - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 512
    2: fft32_asm_float_avx - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 480
Transform tree:
    mdct_inv_float_avx2 - type: mdct_float, len: 960, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
        fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: 480, factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call]
            fft32_asm_float_fma3 - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
For transform of length 1024, inverse, mdct_float, flags: [aligned, out_of_place], found 3 matches:
    1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
    2: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
    3: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
For transform of length 512, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 3 matches:
    1: fft_sr_asm_float_avx2 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 480
    2: fft_sr_asm_float_fma3 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 448
    3: fft_sr_asm_float_avx - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 416
Transform tree:
    mdct_inv_float_avx2 - type: mdct_float, len: 1024, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
        fft_sr_asm_float_avx2 - type: fft_float, len: 512, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
For transform of length 1024, forward, mdct_float, flags: [aligned, out_of_place], found 2 matches:
    1: mdct_fwd_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, fwd_only], prio: 96
    2: mdct_naive_fwd_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, fwd_only], prio: -130976
For transform of length 512, forward, fft_float, flags: [aligned, inplace, preshuf], found 5 matches:
    1: fft_sr_ns_float_avx2 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf], prio: 480
    2: fft_sr_ns_float_fma3 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf], prio: 448
    3: fft_sr_ns_float_avx - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf], prio: 416
    4: fft_pfa_ns_float_c - type: fft_float, len: [6, ∞], factors[2]: [7, 5, 3, 2, any], flags: [unaligned, inplace, out_of_place, preshuf], prio: 112
    5: fft512_ns_float_c - type: fft_float, len: 512, factor: 2, flags: [unaligned, inplace, out_of_place, preshuf], prio: 96
Transform tree:
    mdct_fwd_float_c - type: mdct_float, len: 1024, factors[2]: [2, any], flags: [unaligned, out_of_place, fwd_only]
        fft_sr_ns_float_avx2 - type: fft_float, len: 512, factor: 2, flags: [aligned, inplace, out_of_place, preshuf]
[h264 @ 0000000000647a00] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0000000000647a00] Decoding VUI
[h264 @ 0000000000647a00] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0000000000647a00] nal_unit_type: 6(SEI), nal_ref_idc: 0
[h264 @ 0000000000647a00] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0000000000647a00] Format yuv420p chosen by get_format().
[h264 @ 0000000000647a00] Reinit context to 1280x720, pix_fmt: yuv420p
[h264 @ 0000000000647a00] no picture 
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000000645340] demuxer injecting skip 1024 / discard 0
[aac @ 0000000000649540] skip 1024 / discard 0 samples due to side data
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000000645340] All info found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000000645340] After avformat_find_stream_info() pos: 139930 bytes read:163840 seeks:0 frames:11
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'mod/222.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Multimedia Cloud Transcode (cloud.baidu.com)
  Duration: 00:03:54.32, start: 0.000000, bitrate: 1842 kb/s
  Stream #0:0[0x1](und), 10, 1/12800: Video: h264 (High), 1 reference frame (avc1 / 0x31637661), yuv420p(tv, bt709, progressive, left), 1280x720 [SAR 1:1 DAR 16:9], 0/1, 1774 kb/s, 25 fps, 25 tbr, 12800 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und), 1, 1/44100: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 64 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
test hw: cuda
decoder: Nvidia CUVID H264 decoder
[h264 @ 000000000064a980] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 000000000064a980] Decoding VUI
[h264 @ 000000000064a980] nal_unit_type: 8(PPS), nal_ref_idc: 3
can encode: 1
[h264_nvenc @ 00000000006df7c0] Loaded lib: nvcuda.dll
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuInit
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDriverGetVersion
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDeviceGetCount
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDeviceGet
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDeviceGetAttribute
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDeviceGetName
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDeviceComputeCapability
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuCtxCreate_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuCtxGetCurrent
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuCtxSetLimit
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuCtxPushCurrent_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuCtxPopCurrent_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuCtxDestroy_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMemAlloc_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMemAllocPitch_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMemAllocManaged
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMemsetD8Async
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMemFree_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMemcpy
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMemcpyAsync
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMemcpy2D_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMemcpy2DAsync_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMemcpyHtoD_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMemcpyHtoDAsync_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMemcpyDtoH_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMemcpyDtoHAsync_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMemcpyDtoD_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMemcpyDtoDAsync_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuGetErrorName
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuGetErrorString
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuCtxGetDevice
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDevicePrimaryCtxRetain
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDevicePrimaryCtxRelease
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDevicePrimaryCtxSetFlags
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDevicePrimaryCtxGetState
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDevicePrimaryCtxReset
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuStreamCreate
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuStreamQuery
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuStreamSynchronize
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuStreamDestroy_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuStreamAddCallback
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuStreamWaitEvent
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuEventCreate
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuEventDestroy_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuEventSynchronize
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuEventQuery
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuEventRecord
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuLaunchKernel
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuLinkCreate
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuLinkAddData
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuLinkComplete
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuLinkDestroy
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuModuleLoadData
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuModuleUnload
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuModuleGetFunction
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuModuleGetGlobal
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuTexObjectCreate
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuTexObjectDestroy
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuGLGetDevices_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuGraphicsGLRegisterImage
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuGraphicsUnregisterResource
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuGraphicsMapResources
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuGraphicsUnmapResources
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuGraphicsSubResourceGetMappedArray
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuGraphicsResourceGetMappedPointer_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDeviceGetUuid
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDeviceGetUuid_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDeviceGetLuid
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDeviceGetByPCIBusId
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDeviceGetPCIBusId
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuImportExternalMemory
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDestroyExternalMemory
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuExternalMemoryGetMappedBuffer
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuExternalMemoryGetMappedMipmappedArray
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMipmappedArrayGetLevel
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuMipmappedArrayDestroy
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuImportExternalSemaphore
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuDestroyExternalSemaphore
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuSignalExternalSemaphoresAsync
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuWaitExternalSemaphoresAsync
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuArrayCreate_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuArray3DCreate_v2
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuArrayDestroy
[h264_nvenc @ 00000000006df7c0] Cannot load optional cuEGLStreamProducerConnect
[h264_nvenc @ 00000000006df7c0] Cannot load optional cuEGLStreamProducerDisconnect
[h264_nvenc @ 00000000006df7c0] Cannot load optional cuEGLStreamConsumerDisconnect
[h264_nvenc @ 00000000006df7c0] Cannot load optional cuEGLStreamProducerPresentFrame
[h264_nvenc @ 00000000006df7c0] Cannot load optional cuEGLStreamProducerReturnFrame
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuD3D11GetDevice
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuD3D11GetDevices
[h264_nvenc @ 00000000006df7c0] Loaded sym: cuGraphicsD3D11RegisterResource
[h264_nvenc @ 00000000006df7c0] Loaded lib: nvEncodeAPI64.dll
[h264_nvenc @ 00000000006df7c0] Loaded sym: NvEncodeAPICreateInstance
[h264_nvenc @ 00000000006df7c0] Loaded sym: NvEncodeAPIGetMaxSupportedVersion
[h264_nvenc @ 00000000006df7c0] Loaded Nvenc version 12.2
[h264_nvenc @ 00000000006df7c0] Nvenc initialized successfully
[h264_nvenc @ 00000000006df7c0] 1 CUDA capable devices found
[h264_nvenc @ 00000000006df7c0] [ GPU #0 - < NVIDIA GeForce RTX 4060 Laptop GPU > has Compute SM 8.9 ]
[h264_nvenc @ 00000000006df7c0] supports NVENC
[file @ 00000000006e27c0] Setting default whitelist 'file,crypto,data'
Output #0, mp4, to 'mod/333.mp4':
  Stream #0:0, 0, 0/0: Video: h264 (Main), 1 reference frame, yuv420p, 1280x720 (0x0), 0/1, q=2-31, 1774 kb/s, 25 tbr
    Side data:
      cpb: bitrate max/min/avg: 0/0/1774942 buffer size: 3549884 vbv_delay: N/A
Read packet: pts=0*1/12800, dts=-1024*1/12800 / 0 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 6(SEI), nal_ref_idc: 0
[h264 @ 000000000064a980] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 000000000064a980] Format yuv420p chosen by get_format().
[h264 @ 000000000064a980] Reinit context to 1280x720, pix_fmt: yuv420p
[h264 @ 000000000064a980] no picture 
Read packet: pts=512*1/12800, dts=-512*1/12800 / 0.04 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[h264 @ 000000000064a980] no picture 
Read packet: pts=1024*1/12800, dts=0*1/12800 / 0.08 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
Frame: pts=0*1/12800 / 0 / 1/12800, 1280x720, size=1417197, ref=1:2 / type: 1
Frame: pts=0*1/1000 / 0 / 1/1000, 1280x720, size=1417197, ref=1:2 / type: 0
Read packet: pts=3584*1/12800, dts=512*1/12800 / 0.28 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
Frame: pts=512*1/12800 / 0.04 / 1/12800, 1280x720, size=1417197, ref=1:2 / type: 1
Frame: pts=40*1/1000 / 0.04 / 1/1000, 1280x720, size=1417197, ref=1:2 / type: 0
Read packet: pts=2048*1/12800, dts=1024*1/12800 / 0.16 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
Frame: pts=1024*1/12800 / 0.08 / 1/12800, 1280x720, size=1417197, ref=1:2 / type: 1
Frame: pts=80*1/1000 / 0.08 / 1/1000, 1280x720, size=1417197, ref=1:2 / type: 0
Read packet: pts=1536*1/12800, dts=1536*1/12800 / 0.12 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
Frame: pts=1536*1/12800 / 0.12 / 1/12800, 1280x720, size=1417197, ref=1:3 / type: 1
Frame: pts=120*1/1000 / 0.12 / 1/1000, 1280x720, size=1417197, ref=1:3 / type: 0
Read packet: pts=2560*1/12800, dts=2048*1/12800 / 0.2 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
Frame: pts=2048*1/12800 / 0.16 / 1/12800, 1280x720, size=1417197, ref=1:2 / type: 1
Frame: pts=160*1/1000 / 0.16 / 1/1000, 1280x720, size=1417197, ref=1:2 / type: 0
Read packet: pts=3072*1/12800, dts=2560*1/12800 / 0.24 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
Frame: pts=2560*1/12800 / 0.2 / 1/12800, 1280x720, size=1417197, ref=1:2 / type: 1
Frame: pts=200*1/1000 / 0.2 / 1/1000, 1280x720, size=1417197, ref=1:2 / type: 0
Read packet: pts=6656*1/12800, dts=3072*1/12800 / 0.52 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
Frame: pts=3072*1/12800 / 0.24 / 1/12800, 1280x720, size=1417197, ref=1:2 / type: 1
Frame: pts=240*1/1000 / 0.24 / 1/1000, 1280x720, size=1417197, ref=1:2 / type: 0
Read packet: pts=5120*1/12800, dts=3584*1/12800 / 0.4 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
Frame: pts=3584*1/12800 / 0.28 / 1/12800, 1280x720, size=1417197, ref=1:2 / type: 1
Frame: pts=280*1/1000 / 0.28 / 1/1000, 1280x720, size=1417197, ref=1:2 / type: 0
Read packet: pts=4096*1/12800, dts=4096*1/12800 / 0.32 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
Frame: pts=4096*1/12800 / 0.32 / 1/12800, 1280x720, size=1417197, ref=1:3 / type: 1
Frame: pts=320*1/1000 / 0.32 / 1/1000, 1280x720, size=1417197, ref=1:3 / type: 0
Read packet: pts=4608*1/12800, dts=4608*1/12800 / 0.36 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
Frame: pts=4608*1/12800 / 0.36 / 1/12800, 1280x720, size=1417197, ref=1:3 / type: 1
Frame: pts=360*1/1000 / 0.36 / 1/1000, 1280x720, size=1417197, ref=1:3 / type: 0
Read packet: pts=5632*1/12800, dts=5120*1/12800 / 0.44 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
Frame: pts=5120*1/12800 / 0.4 / 1/12800, 1280x720, size=1417197, ref=1:2 / type: 1
Frame: pts=400*1/1000 / 0.4 / 1/1000, 1280x720, size=1417197, ref=1:2 / type: 0
Read packet: pts=6144*1/12800, dts=5632*1/12800 / 0.48 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
Frame: pts=5632*1/12800 / 0.44 / 1/12800, 1280x720, size=1417197, ref=1:2 / type: 1
Frame: pts=440*1/1000 / 0.44 / 1/1000, 1280x720, size=1417197, ref=1:2 / type: 0
Read packet: pts=9728*1/12800, dts=6144*1/12800 / 0.76 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
Frame: pts=6144*1/12800 / 0.48 / 1/12800, 1280x720, size=1417197, ref=1:2 / type: 1
Frame: pts=480*1/1000 / 0.48 / 1/1000, 1280x720, size=1417197, ref=1:2 / type: 0
Read packet: pts=8192*1/12800, dts=6656*1/12800 / 0.64 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
Frame: pts=6656*1/12800 / 0.52 / 1/12800, 1280x720, size=1417197, ref=1:2 / type: 1
Frame: pts=520*1/1000 / 0.52 / 1/1000, 1280x720, size=1417197, ref=1:2 / type: 0
Read packet: pts=7168*1/12800, dts=7168*1/12800 / 0.56 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
Frame: pts=7168*1/12800 / 0.56 / 1/12800, 1280x720, size=1417197, ref=1:3 / type: 1
Frame: pts=560*1/1000 / 0.56 / 1/1000, 1280x720, size=1417197, ref=1:3 / type: 0
Write packet: pts=0*1/1000, dts=-3*1/1000 / 0 / 1/1000 / st: 0
Read packet: pts=7680*1/12800, dts=7680*1/12800 / 0.6 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
Frame: pts=7680*1/12800 / 0.6 / 1/12800, 1280x720, size=1417197, ref=1:3 / type: 1
Frame: pts=600*1/1000 / 0.6 / 1/1000, 1280x720, size=1417197, ref=1:3 / type: 0
Write packet: pts=160*1/1000, dts=37*1/1000 / 0.16 / 1/1000 / st: 0
Read packet: pts=8704*1/12800, dts=8192*1/12800 / 0.68 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
Frame: pts=8192*1/12800 / 0.64 / 1/12800, 1280x720, size=1417197, ref=1:2 / type: 1
Frame: pts=640*1/1000 / 0.64 / 1/1000, 1280x720, size=1417197, ref=1:2 / type: 0
Write packet: pts=80*1/1000, dts=77*1/1000 / 0.08 / 1/1000 / st: 0
Read packet: pts=9216*1/12800, dts=8704*1/12800 / 0.72 / 1/12800 / st: 0
[h264 @ 000000000064a980] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
Frame: pts=8704*1/12800 / 0.68 / 1/12800, 1280x720, size=1417197, ref=1:2 / type: 1
Frame: pts=680*1/1000 / 0.68 / 1/1000, 1280x720, size=1417197, ref=1:2 / type: 0
Write packet: pts=40*1/1000, dts=117*1/1000 / 0.04 / 1/1000 / st: 0
[mp4 @ 00000000006df4c0] pts (3600) < dts (10530) in stream 0
Error write packet: FFmpegError:-22, Invalid argument
[h264_nvenc @ 00000000006df7c0] Nvenc unloaded
[AVIOContext @ 0000000000681540] Statistics: 1278 bytes written, 0 seeks, 2 writeouts
[AVIOContext @ 0000000000646980] Statistics: 163840 bytes read, 0 seeks

进程已结束,退出代码为 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions