ffmpeg_compat.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. #pragma once
  2. /**
  3. * FFmpeg Version Compatibility Header
  4. * This file provides compatibility macros and functions for different FFmpeg versions
  5. * Supports FFmpeg 3.x, 4.x, 5.x, 6.x, and 7.x
  6. */
  7. extern "C" {
  8. #include <libavcodec/avcodec.h>
  9. #include <libavcodec/bsf.h>
  10. #include <libavdevice/avdevice.h>
  11. #include <libavformat/avformat.h>
  12. #include <libavutil/channel_layout.h>
  13. #include <libavutil/frame.h>
  14. #include <libavutil/imgutils.h>
  15. #include <libavutil/pixfmt.h>
  16. #include <libavutil/time.h>
  17. #include <libswresample/swresample.h>
  18. #include <libswscale/swscale.h>
  19. }
  20. // FFmpeg version detection
  21. #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58, 9, 100)
  22. #define FFMPEG_VERSION_MAJOR 3
  23. #elif LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
  24. #define FFMPEG_VERSION_MAJOR 4
  25. #elif LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(60, 0, 100)
  26. #define FFMPEG_VERSION_MAJOR 5
  27. #elif LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(61, 0, 100)
  28. #define FFMPEG_VERSION_MAJOR 6
  29. #else
  30. #define FFMPEG_VERSION_MAJOR 7
  31. #endif
  32. // Compatibility functions for deprecated functions
  33. inline void ffmpeg_register_all() {
  34. #if FFMPEG_VERSION_MAJOR < 4
  35. av_register_all();
  36. #endif
  37. // No-op in FFmpeg 4.0+
  38. }
  39. inline void ffmpeg_register_devices() {
  40. #if FFMPEG_VERSION_MAJOR < 4
  41. avdevice_register_all();
  42. #endif
  43. // No-op in FFmpeg 4.0+
  44. }
  45. // Compatibility for AVInputFormat/AVOutputFormat
  46. #if FFMPEG_VERSION_MAJOR >= 4
  47. using FFmpegInputFormat = const AVInputFormat;
  48. using FFmpegOutputFormat = const AVOutputFormat;
  49. #else
  50. using FFmpegInputFormat = AVInputFormat;
  51. using FFmpegOutputFormat = AVOutputFormat;
  52. #endif
  53. // Compatibility for AVCodec pointer
  54. #if FFMPEG_VERSION_MAJOR >= 7
  55. using FFmpegCodec = const AVCodec;
  56. #else
  57. using FFmpegCodec = AVCodec;
  58. #endif
  59. // Compatibility for av_err2str macro (C++ safe version)
  60. #ifdef __cplusplus
  61. #undef av_err2str
  62. #ifdef _MSC_VER
  63. #include <malloc.h>
  64. #define av_err2str(errnum) av_make_error_string((char*)_alloca(AV_ERROR_MAX_STRING_SIZE), AV_ERROR_MAX_STRING_SIZE, errnum)
  65. #else
  66. #define av_err2str(errnum) av_make_error_string((char*)__builtin_alloca(AV_ERROR_MAX_STRING_SIZE), AV_ERROR_MAX_STRING_SIZE, errnum)
  67. #endif
  68. #endif
  69. // Compatibility for bitstream filter context
  70. #if FFMPEG_VERSION_MAJOR >= 4
  71. using AVBitStreamFilterContext = AVBSFContext;
  72. #else
  73. // For FFmpeg 3.x, AVBitStreamFilterContext is already defined
  74. // No need to redefine it
  75. #endif
  76. // Compatibility functions for codec context access
  77. inline AVMediaType ffmpeg_get_codec_type(AVStream* stream) {
  78. #if FFMPEG_VERSION_MAJOR >= 4
  79. return stream->codecpar->codec_type;
  80. #else
  81. return stream->codec->codec_type;
  82. #endif
  83. }
  84. inline AVCodecID ffmpeg_get_codec_id(AVStream* stream) {
  85. #if FFMPEG_VERSION_MAJOR >= 4
  86. return stream->codecpar->codec_id;
  87. #else
  88. return stream->codec->codec_id;
  89. #endif
  90. }
  91. inline int ffmpeg_get_codec_width(AVStream* stream) {
  92. #if FFMPEG_VERSION_MAJOR >= 4
  93. return stream->codecpar->width;
  94. #else
  95. return stream->codec->width;
  96. #endif
  97. }
  98. inline int ffmpeg_get_codec_height(AVStream* stream) {
  99. #if FFMPEG_VERSION_MAJOR >= 4
  100. return stream->codecpar->height;
  101. #else
  102. return stream->codec->height;
  103. #endif
  104. }
  105. inline AVPixelFormat ffmpeg_get_codec_pix_fmt(AVStream* stream) {
  106. #if FFMPEG_VERSION_MAJOR >= 4
  107. return static_cast<AVPixelFormat>(stream->codecpar->format);
  108. #else
  109. return stream->codec->pix_fmt;
  110. #endif
  111. }
  112. inline int ffmpeg_get_codec_sample_rate(AVStream* stream) {
  113. #if FFMPEG_VERSION_MAJOR >= 4
  114. return stream->codecpar->sample_rate;
  115. #else
  116. return stream->codec->sample_rate;
  117. #endif
  118. }
  119. inline int ffmpeg_get_codec_channels(AVStream* stream) {
  120. #if FFMPEG_VERSION_MAJOR >= 7
  121. return stream->codecpar->ch_layout.nb_channels;
  122. #elif FFMPEG_VERSION_MAJOR >= 4
  123. return stream->codecpar->channels;
  124. #else
  125. return stream->codec->channels;
  126. #endif
  127. }
  128. inline uint64_t ffmpeg_get_codec_channel_layout(AVStream* stream) {
  129. #if FFMPEG_VERSION_MAJOR >= 7
  130. // In FFmpeg 7, use ch_layout.u.mask directly if it's a mask layout
  131. if (stream->codecpar->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) {
  132. return stream->codecpar->ch_layout.u.mask;
  133. } else {
  134. // For non-mask layouts, return a default stereo layout
  135. return AV_CH_LAYOUT_STEREO;
  136. }
  137. #elif FFMPEG_VERSION_MAJOR >= 4
  138. return stream->codecpar->channel_layout;
  139. #else
  140. return stream->codec->channel_layout;
  141. #endif
  142. }
  143. inline AVSampleFormat ffmpeg_get_codec_sample_fmt(AVStream* stream) {
  144. #if FFMPEG_VERSION_MAJOR >= 4
  145. return static_cast<AVSampleFormat>(stream->codecpar->format);
  146. #else
  147. return stream->codec->sample_fmt;
  148. #endif
  149. }
  150. // Compatibility for channel layout functions
  151. inline uint64_t ffmpeg_get_default_channel_layout(int channels) {
  152. #if FFMPEG_VERSION_MAJOR >= 7
  153. AVChannelLayout ch_layout;
  154. av_channel_layout_default(&ch_layout, channels);
  155. if (ch_layout.order == AV_CHANNEL_ORDER_NATIVE) {
  156. return ch_layout.u.mask;
  157. } else {
  158. // Fallback for common channel counts
  159. switch (channels) {
  160. case 1: return AV_CH_LAYOUT_MONO;
  161. case 2: return AV_CH_LAYOUT_STEREO;
  162. case 6: return AV_CH_LAYOUT_5POINT1;
  163. case 8: return AV_CH_LAYOUT_7POINT1;
  164. default: return AV_CH_LAYOUT_STEREO;
  165. }
  166. }
  167. #else
  168. return av_get_default_channel_layout(channels);
  169. #endif
  170. }
  171. // Compatibility for filter registration
  172. inline void ffmpeg_register_filters() {
  173. #if FFMPEG_VERSION_MAJOR < 4
  174. avfilter_register_all();
  175. #endif
  176. // No-op in FFmpeg 4.0+
  177. }
  178. // Compatibility for channel layout string functions
  179. inline int ffmpeg_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout) {
  180. #if FFMPEG_VERSION_MAJOR >= 7
  181. (void)nb_channels; // Suppress unused parameter warning
  182. AVChannelLayout ch_layout;
  183. av_channel_layout_from_mask(&ch_layout, channel_layout);
  184. return av_channel_layout_describe(&ch_layout, buf, buf_size);
  185. #else
  186. av_get_channel_layout_string(buf, buf_size, nb_channels, channel_layout);
  187. return strlen(buf);
  188. #endif
  189. }
  190. // Compatibility for AVFrame channels access
  191. inline int ffmpeg_get_frame_channels(AVFrame* frame) {
  192. #if FFMPEG_VERSION_MAJOR >= 7
  193. return frame->ch_layout.nb_channels;
  194. #else
  195. return frame->channels;
  196. #endif
  197. }
  198. // Compatibility for AVFrame channel_layout access
  199. inline uint64_t ffmpeg_get_frame_channel_layout(AVFrame* frame) {
  200. #if FFMPEG_VERSION_MAJOR >= 7
  201. if (frame->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) {
  202. return frame->ch_layout.u.mask;
  203. } else {
  204. return AV_CH_LAYOUT_STEREO;
  205. }
  206. #else
  207. return frame->channel_layout;
  208. #endif
  209. }
  210. // Compatibility for av_samples_get_buffer_size
  211. inline int ffmpeg_get_buffer_size(enum AVSampleFormat sample_fmt, int nb_channels, int nb_samples, int align) {
  212. #if FFMPEG_VERSION_MAJOR >= 7
  213. return av_samples_get_buffer_size(nullptr, nb_channels, nb_samples, sample_fmt, align);
  214. #else
  215. return av_samples_get_buffer_size(nullptr, nb_channels, nb_samples, sample_fmt, align);
  216. #endif
  217. }
  218. // Compatibility for codec context creation from stream
  219. inline AVCodecContext* ffmpeg_get_codec_context(AVStream* stream) {
  220. #if FFMPEG_VERSION_MAJOR >= 4
  221. const AVCodec* codec = avcodec_find_decoder(stream->codecpar->codec_id);
  222. if (!codec) return nullptr;
  223. AVCodecContext* ctx = avcodec_alloc_context3(codec);
  224. if (!ctx) return nullptr;
  225. if (avcodec_parameters_to_context(ctx, stream->codecpar) < 0) {
  226. avcodec_free_context(&ctx);
  227. return nullptr;
  228. }
  229. return ctx;
  230. #else
  231. return stream->codec;
  232. #endif
  233. }
  234. // Compatibility for setting stream codec parameters
  235. inline void ffmpeg_set_stream_codec_id(AVStream* stream, enum AVCodecID codec_id) {
  236. #if FFMPEG_VERSION_MAJOR >= 4
  237. stream->codecpar->codec_id = codec_id;
  238. #else
  239. stream->codec->codec_id = codec_id;
  240. #endif
  241. }
  242. inline void ffmpeg_set_stream_codec_type(AVStream* stream, enum AVMediaType codec_type) {
  243. #if FFMPEG_VERSION_MAJOR >= 4
  244. stream->codecpar->codec_type = codec_type;
  245. #else
  246. stream->codec->codec_type = codec_type;
  247. #endif
  248. }
  249. inline void ffmpeg_set_stream_bit_rate(AVStream* stream, int64_t bit_rate) {
  250. #if FFMPEG_VERSION_MAJOR >= 4
  251. stream->codecpar->bit_rate = bit_rate;
  252. #else
  253. stream->codec->bit_rate = bit_rate;
  254. #endif
  255. }
  256. inline void ffmpeg_set_stream_pix_fmt(AVStream* stream, enum AVPixelFormat pix_fmt) {
  257. #if FFMPEG_VERSION_MAJOR >= 4
  258. stream->codecpar->format = pix_fmt;
  259. #else
  260. stream->codec->pix_fmt = pix_fmt;
  261. #endif
  262. }
  263. inline void ffmpeg_set_stream_dimensions(AVStream* stream, int width, int height) {
  264. #if FFMPEG_VERSION_MAJOR >= 4
  265. stream->codecpar->width = width;
  266. stream->codecpar->height = height;
  267. #else
  268. stream->codec->width = width;
  269. stream->codec->height = height;
  270. #endif
  271. }
  272. // Compatibility for stream codec parameters
  273. inline int ffmpeg_copy_codec_params_to_stream(AVStream* stream, AVCodecContext* codec_ctx) {
  274. #if FFMPEG_VERSION_MAJOR >= 4
  275. return avcodec_parameters_from_context(stream->codecpar, codec_ctx);
  276. #else
  277. return 0; // No-op for older versions
  278. #endif
  279. }
  280. // Compatibility for extradata access
  281. inline uint8_t* ffmpeg_get_extradata(AVStream* stream) {
  282. #if FFMPEG_VERSION_MAJOR >= 4
  283. return stream->codecpar->extradata;
  284. #else
  285. return stream->codec->extradata;
  286. #endif
  287. }
  288. inline int ffmpeg_get_extradata_size(AVStream* stream) {
  289. #if FFMPEG_VERSION_MAJOR >= 4
  290. return stream->codecpar->extradata_size;
  291. #else
  292. return stream->codec->extradata_size;
  293. #endif
  294. }
  295. inline void ffmpeg_set_stream_extradata(AVStream* stream, uint8_t* data, int size) {
  296. #if FFMPEG_VERSION_MAJOR >= 4
  297. stream->codecpar->extradata = data;
  298. stream->codecpar->extradata_size = size;
  299. #else
  300. stream->codec->extradata = data;
  301. stream->codec->extradata_size = size;
  302. #endif
  303. }
  304. // Compatibility for AVCodecContext channels and channel_layout
  305. inline void ffmpeg_set_codec_channels(AVCodecContext* ctx, int channels) {
  306. #if FFMPEG_VERSION_MAJOR >= 7
  307. av_channel_layout_default(&ctx->ch_layout, channels);
  308. #else
  309. ctx->channels = channels;
  310. #endif
  311. }
  312. inline void ffmpeg_set_codec_channel_layout(AVCodecContext* ctx, uint64_t channel_layout) {
  313. #if FFMPEG_VERSION_MAJOR >= 7
  314. av_channel_layout_from_mask(&ctx->ch_layout, channel_layout);
  315. #else
  316. ctx->channel_layout = channel_layout;
  317. #endif
  318. }
  319. inline int ffmpeg_get_codec_context_channels(AVCodecContext* ctx) {
  320. #if FFMPEG_VERSION_MAJOR >= 7
  321. return ctx->ch_layout.nb_channels;
  322. #else
  323. return ctx->channels;
  324. #endif
  325. }
  326. // Compatibility for swr_alloc_set_opts
  327. inline SwrContext* ffmpeg_swr_alloc_set_opts(SwrContext *s,
  328. int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
  329. int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate,
  330. int log_offset, void *log_ctx) {
  331. #if FFMPEG_VERSION_MAJOR >= 7
  332. SwrContext *swr_ctx = swr_alloc();
  333. if (!swr_ctx) return NULL;
  334. AVChannelLayout out_ch_layout_new, in_ch_layout_new;
  335. av_channel_layout_from_mask(&out_ch_layout_new, out_ch_layout);
  336. av_channel_layout_from_mask(&in_ch_layout_new, in_ch_layout);
  337. av_opt_set_chlayout(swr_ctx, "ochl", &out_ch_layout_new, 0);
  338. av_opt_set_int(swr_ctx, "osf", out_sample_fmt, 0);
  339. av_opt_set_int(swr_ctx, "osr", out_sample_rate, 0);
  340. av_opt_set_chlayout(swr_ctx, "ichl", &in_ch_layout_new, 0);
  341. av_opt_set_int(swr_ctx, "isf", in_sample_fmt, 0);
  342. av_opt_set_int(swr_ctx, "isr", in_sample_rate, 0);
  343. av_channel_layout_uninit(&out_ch_layout_new);
  344. av_channel_layout_uninit(&in_ch_layout_new);
  345. return swr_ctx;
  346. #else
  347. return swr_alloc_set_opts(s, out_ch_layout, out_sample_fmt, out_sample_rate,
  348. in_ch_layout, in_sample_fmt, in_sample_rate,
  349. log_offset, log_ctx);
  350. #endif
  351. }
  352. // Compatibility for codec parameters setting
  353. inline int ffmpeg_av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
  354. int nb_samples, enum AVSampleFormat sample_fmt, int align) {
  355. #if FFMPEG_VERSION_MAJOR >= 7
  356. return av_samples_alloc_array_and_samples(&audio_data, linesize, nb_channels, nb_samples, sample_fmt, align);
  357. #else
  358. return av_samples_alloc(audio_data, linesize, nb_channels, nb_samples, sample_fmt, align);
  359. #endif
  360. }
  361. inline void ffmpeg_set_frame_channel_layout(AVFrame* frame, AVCodecContext* codec_ctx) {
  362. #if FFMPEG_VERSION_MAJOR >= 7
  363. av_channel_layout_copy(&frame->ch_layout, &codec_ctx->ch_layout);
  364. #else
  365. frame->channel_layout = codec_ctx->channel_layout;
  366. #endif
  367. }
  368. inline void ffmpeg_set_stream_codec_params(AVStream* stream, AVCodecContext* codec_ctx) {
  369. #if FFMPEG_VERSION_MAJOR >= 7
  370. stream->codecpar->codec_id = codec_ctx->codec_id;
  371. stream->codecpar->bit_rate = codec_ctx->bit_rate;
  372. stream->codecpar->width = codec_ctx->width;
  373. stream->codecpar->height = codec_ctx->height;
  374. stream->codecpar->format = codec_ctx->pix_fmt;
  375. stream->codecpar->sample_rate = codec_ctx->sample_rate;
  376. av_channel_layout_copy(&stream->codecpar->ch_layout, &codec_ctx->ch_layout);
  377. stream->time_base = codec_ctx->time_base;
  378. #elif FFMPEG_VERSION_MAJOR >= 4
  379. stream->codecpar->codec_id = codec_ctx->codec_id;
  380. stream->codecpar->bit_rate = codec_ctx->bit_rate;
  381. stream->codecpar->width = codec_ctx->width;
  382. stream->codecpar->height = codec_ctx->height;
  383. stream->codecpar->format = codec_ctx->pix_fmt;
  384. stream->codecpar->sample_rate = codec_ctx->sample_rate;
  385. stream->codecpar->channels = codec_ctx->channels;
  386. stream->codecpar->channel_layout = codec_ctx->channel_layout;
  387. stream->time_base = codec_ctx->time_base;
  388. #else
  389. *(stream->codec) = *codec_ctx;
  390. #endif
  391. }
  392. // Additional compatibility functions for missing identifiers
  393. inline int ffmpeg_get_channels(AVCodecContext* ctx) {
  394. #if FFMPEG_VERSION_MAJOR >= 7
  395. return ctx->ch_layout.nb_channels;
  396. #else
  397. return ctx->channels;
  398. #endif
  399. }
  400. inline void ffmpeg_set_channels(AVCodecContext* ctx, int channels) {
  401. #if FFMPEG_VERSION_MAJOR >= 7
  402. av_channel_layout_default(&ctx->ch_layout, channels);
  403. #else
  404. ctx->channels = channels;
  405. #endif
  406. }
  407. inline void ffmpeg_set_channel_layout(AVCodecContext* ctx, uint64_t channel_layout) {
  408. #if FFMPEG_VERSION_MAJOR >= 7
  409. av_channel_layout_from_mask(&ctx->ch_layout, channel_layout);
  410. #else
  411. ctx->channel_layout = channel_layout;
  412. #endif
  413. }
  414. inline void ffmpeg_set_frame_channels(AVFrame* frame, int channels) {
  415. #if FFMPEG_VERSION_MAJOR >= 7
  416. av_channel_layout_default(&frame->ch_layout, channels);
  417. #else
  418. frame->channels = channels;
  419. #endif
  420. }
  421. inline void ffmpeg_set_frame_channel_layout(AVFrame* frame, uint64_t channel_layout) {
  422. #if FFMPEG_VERSION_MAJOR >= 7
  423. av_channel_layout_from_mask(&frame->ch_layout, channel_layout);
  424. #else
  425. frame->channel_layout = channel_layout;
  426. #endif
  427. }
  428. inline void ffmpeg_set_frame_pkt_pts(AVFrame* frame, int64_t pts) {
  429. #if FFMPEG_VERSION_MAJOR >= 4
  430. frame->pts = pts;
  431. #else
  432. frame->pkt_pts = pts;
  433. #endif
  434. }
  435. // Compatibility for bitstream filter initialization
  436. #if FFMPEG_VERSION_MAJOR >= 4
  437. inline AVBitStreamFilterContext* ffmpeg_bitstream_filter_init(const char* name)
  438. {
  439. const AVBitStreamFilter* bsf = av_bsf_get_by_name(name);
  440. if (!bsf) return nullptr;
  441. AVBSFContext* ctx = nullptr;
  442. if (av_bsf_alloc(bsf, &ctx) < 0) return nullptr;
  443. return ctx;
  444. }
  445. #else
  446. inline AVBitStreamFilterContext* ffmpeg_bitstream_filter_init(const char* name) {
  447. // For FFmpeg 3.x, use the old API
  448. return av_bitstream_filter_init(name);
  449. }
  450. #endif
  451. #if FFMPEG_VERSION_MAJOR >= 4
  452. inline void ffmpeg_bitstream_filter_close(AVBitStreamFilterContext* ctx) {
  453. if (ctx) {
  454. av_bsf_free(&ctx);
  455. }
  456. }
  457. #else
  458. inline void ffmpeg_bitstream_filter_close(AVBitStreamFilterContext* ctx) {
  459. if (ctx) {
  460. av_bitstream_filter_close(ctx);
  461. }
  462. }
  463. #endif
  464. #if FFMPEG_VERSION_MAJOR >= 4
  465. inline int ffmpeg_bitstream_filter_filter(AVBitStreamFilterContext* ctx, AVPacket* packet) {
  466. if (!ctx || !packet) return -1;
  467. // 对于新版本FFmpeg,需要先初始化BSF上下文
  468. if (ctx->par_in && ctx->par_in->codec_type == AVMEDIA_TYPE_UNKNOWN) {
  469. // 从packet推断参数
  470. ctx->par_in->codec_type = AVMEDIA_TYPE_AUDIO;
  471. ctx->par_in->codec_id = AV_CODEC_ID_AAC;
  472. if (avcodec_parameters_copy(ctx->par_out, ctx->par_in) < 0) {
  473. return -1;
  474. }
  475. if (av_bsf_init(ctx) < 0) {
  476. return -1;
  477. }
  478. }
  479. int ret = av_bsf_send_packet(ctx, packet);
  480. if (ret < 0) return ret;
  481. ret = av_bsf_receive_packet(ctx, packet);
  482. return ret;
  483. }
  484. #else
  485. inline int ffmpeg_bitstream_filter_filter(AVBitStreamFilterContext* ctx, AVPacket* packet) {
  486. if (!ctx || !packet) return -1;
  487. uint8_t* output_data = nullptr;
  488. int output_size = 0;
  489. int ret = av_bitstream_filter_filter(ctx, nullptr, nullptr, &output_data, &output_size,
  490. packet->data, packet->size, packet->flags & AV_PKT_FLAG_KEY);
  491. if (ret >= 0 && output_data && output_size > 0) {
  492. av_packet_unref(packet);
  493. packet->data = output_data;
  494. packet->size = output_size;
  495. packet->buf = av_buffer_create(output_data, output_size, av_buffer_default_free, nullptr, 0);
  496. }
  497. return ret;
  498. }
  499. #endif