Skip to content

Commit 0d2153a

Browse files
pfeatherstoneme
andauthored
FFMpeg 7.1 API (davisking#3105)
* Support new FFMpeg 7.1 API when applicable * extra job --------- Co-authored-by: me <me@me>
1 parent fb0865b commit 0d2153a

File tree

2 files changed

+99
-28
lines changed

2 files changed

+99
-28
lines changed

.github/workflows/build_cpp.yml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ jobs:
141141
- name: Build examples, etc
142142
run: cmake --build build --config Release --parallel 2
143143

144-
ubuntu-22-04-ffmpeg7:
144+
ubuntu-22-04-ffmpeg701:
145145
runs-on: 'ubuntu-22.04'
146146
steps:
147147
- uses: actions/checkout@v2
@@ -174,6 +174,39 @@ jobs:
174174
- name: Build ffmpeg example
175175
run: cmake --build build --config Release --target ffmpeg_video_muxing_ex --parallel 4
176176

177+
ubuntu-22-04-ffmpeg711:
178+
runs-on: 'ubuntu-22.04'
179+
steps:
180+
- uses: actions/checkout@v2
181+
182+
- name: Install dependencies
183+
run: |
184+
sudo apt update
185+
sudo apt install make yasm
186+
187+
- name: Cache FFmpeg 7
188+
uses: actions/cache@v3
189+
id: cache-ffmpeg7
190+
with:
191+
path: /home/runner/ffmpeg-n7.1.1_installation
192+
key: ffmpeg-n7.1.1_try1
193+
194+
- name: Build FFmpeg 7
195+
if: steps.cache-ffmpeg7.outputs.cache-hit != 'true'
196+
run: |
197+
wget https://github.com/FFmpeg/FFmpeg/archive/refs/tags/n7.1.1.tar.gz
198+
tar -xf n7.1.1.tar.gz
199+
cd FFmpeg-n7.1.1
200+
./configure --prefix=/home/runner/ffmpeg-n7.1.1_installation --disable-doc --disable-programs
201+
make -j4
202+
make install
203+
cd ..
204+
205+
- name: Configure
206+
run: cmake . -B build -DCMAKE_PREFIX_PATH=/home/runner/ffmpeg-n7.1.1_installation
207+
- name: Build ffmpeg example
208+
run: cmake --build build --config Release --target ffmpeg_video_muxing_ex --parallel 4
209+
177210
windows-latest:
178211
runs-on: 'windows-latest'
179212
steps:

dlib/media/ffmpeg_muxer.h

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -688,13 +688,21 @@ namespace dlib
688688
)
689689
{
690690
// Video properties
691-
if (pCodec->supported_framerates && pCodecCtx->framerate != 0)
691+
const AVRational* supported_framerates{nullptr};
692+
int nsupported_framerates{0};
693+
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100)
694+
avcodec_get_supported_config(pCodecCtx, NULL, AV_CODEC_CONFIG_FRAME_RATE, 0, (const void**)&supported_framerates, &nsupported_framerates);
695+
#else
696+
supported_framerates = pCodec->supported_framerates;
697+
for (; supported_framerates != nullptr && supported_framerates[nsupported_framerates] != AVRational{0,0} ; ++nsupported_framerates) {}
698+
#endif
699+
if (supported_framerates && nsupported_framerates > 0 && pCodecCtx->framerate != 0)
692700
{
693701
bool framerate_supported = false;
694702

695-
for (int i = 0 ; pCodec->supported_framerates[i] != AVRational{0,0} ; i++)
703+
for (int i = 0 ; i < nsupported_framerates ; ++i)
696704
{
697-
if (pCodecCtx->framerate == pCodec->supported_framerates[i])
705+
if (pCodecCtx->framerate == supported_framerates[i])
698706
{
699707
framerate_supported = true;
700708
break;
@@ -707,19 +715,26 @@ namespace dlib
707715
<< "Requested framerate "
708716
<< pCodecCtx->framerate.num / pCodecCtx->framerate.den
709717
<< " not supported. Changing to default "
710-
<< pCodec->supported_framerates[0].num / pCodec->supported_framerates[0].den;
718+
<< supported_framerates[0].num / supported_framerates[0].den;
711719

712-
pCodecCtx->framerate = pCodec->supported_framerates[0];
720+
pCodecCtx->framerate = supported_framerates[0];
713721
}
714722
}
715-
716-
if (pCodec->pix_fmts)
723+
const enum AVPixelFormat* pix_fmts{nullptr};
724+
int npix_fmts{0};
725+
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100)
726+
avcodec_get_supported_config(pCodecCtx, NULL, AV_CODEC_CONFIG_PIX_FORMAT, 0, (const void**)&pix_fmts, &npix_fmts);
727+
#else
728+
pix_fmts = pCodec->pix_fmts;
729+
for (; pix_fmts != nullptr && pix_fmts[npix_fmts] != AV_PIX_FMT_NONE ; ++npix_fmts) {}
730+
#endif
731+
if (pix_fmts && npix_fmts > 0)
717732
{
718733
bool pix_fmt_supported = false;
719734

720-
for (int i = 0 ; pCodec->pix_fmts[i] != AV_PIX_FMT_NONE ; i++)
735+
for (int i = 0 ; i < npix_fmts; ++i)
721736
{
722-
if (pCodecCtx->pix_fmt == pCodec->pix_fmts[i])
737+
if (pCodecCtx->pix_fmt == pix_fmts[i])
723738
{
724739
pix_fmt_supported = true;
725740
break;
@@ -732,20 +747,28 @@ namespace dlib
732747
<< "Requested pixel format "
733748
<< av_get_pix_fmt_name(pCodecCtx->pix_fmt)
734749
<< " not supported. Changing to default "
735-
<< av_get_pix_fmt_name(pCodec->pix_fmts[0]);
750+
<< av_get_pix_fmt_name(pix_fmts[0]);
736751

737-
pCodecCtx->pix_fmt = pCodec->pix_fmts[0];
752+
pCodecCtx->pix_fmt = pix_fmts[0];
738753
}
739754
}
740755

741756
// Audio properties
742-
if (pCodec->supported_samplerates)
757+
const int* supported_samplerates{nullptr};
758+
int nsupported_samplerates{0};
759+
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100)
760+
avcodec_get_supported_config(pCodecCtx, NULL, AV_CODEC_CONFIG_SAMPLE_RATE, 0, (const void**)&supported_samplerates, &nsupported_samplerates);
761+
#else
762+
supported_samplerates = pCodec->supported_samplerates;
763+
for (; supported_samplerates != nullptr && supported_samplerates[nsupported_samplerates] != 0 ; ++nsupported_samplerates) {}
764+
#endif
765+
if (supported_samplerates && nsupported_samplerates > 0)
743766
{
744767
bool sample_rate_supported = false;
745768

746-
for (int i = 0 ; pCodec->supported_samplerates[i] != 0 ; i++)
769+
for (int i = 0 ; i < nsupported_samplerates ; ++i)
747770
{
748-
if (pCodecCtx->sample_rate == pCodec->supported_samplerates[i])
771+
if (pCodecCtx->sample_rate == supported_samplerates[i])
749772
{
750773
sample_rate_supported = true;
751774
break;
@@ -758,19 +781,26 @@ namespace dlib
758781
<< "Requested sample rate "
759782
<< pCodecCtx->sample_rate
760783
<< " not supported. Changing to default "
761-
<< pCodec->supported_samplerates[0];
784+
<< supported_samplerates[0];
762785

763-
pCodecCtx->sample_rate = pCodec->supported_samplerates[0];
786+
pCodecCtx->sample_rate = supported_samplerates[0];
764787
}
765788
}
766-
767-
if (pCodec->sample_fmts)
789+
const AVSampleFormat* sample_fmts{nullptr};
790+
int nsample_fmts{0};
791+
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100)
792+
avcodec_get_supported_config(pCodecCtx, NULL, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, (const void**)&sample_fmts, &nsample_fmts);
793+
#else
794+
sample_fmts = pCodec->sample_fmts;
795+
for (; sample_fmts != nullptr && sample_fmts[nsample_fmts] != AV_SAMPLE_FMT_NONE ; ++nsample_fmts) {}
796+
#endif
797+
if (sample_fmts && nsample_fmts > 0)
768798
{
769799
bool sample_fmt_supported = false;
770800

771-
for (int i = 0 ; pCodec->sample_fmts[i] != AV_SAMPLE_FMT_NONE ; i++)
801+
for (int i = 0 ; i < nsample_fmts ; ++i)
772802
{
773-
if (pCodecCtx->sample_fmt == pCodec->sample_fmts[i])
803+
if (pCodecCtx->sample_fmt == sample_fmts[i])
774804
{
775805
sample_fmt_supported = true;
776806
break;
@@ -783,20 +813,28 @@ namespace dlib
783813
<< "Requested sample format "
784814
<< av_get_sample_fmt_name(pCodecCtx->sample_fmt)
785815
<< " not supported. Changing to default "
786-
<< av_get_sample_fmt_name(pCodec->sample_fmts[0]);
816+
<< av_get_sample_fmt_name(sample_fmts[0]);
787817

788-
pCodecCtx->sample_fmt = pCodec->sample_fmts[0];
818+
pCodecCtx->sample_fmt = sample_fmts[0];
789819
}
790820
}
791821

792822
#if FFMPEG_HAS_CH_LAYOUT
793-
if (pCodec->ch_layouts)
823+
const AVChannelLayout* ch_layouts{nullptr};
824+
int nch_layouts{0};
825+
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100)
826+
avcodec_get_supported_config(pCodecCtx, NULL, AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0, (const void**)&ch_layouts, &nch_layouts);
827+
#else
828+
ch_layouts = pCodec->ch_layouts;
829+
for (; ch_layouts != nullptr && av_channel_layout_check(&ch_layouts[nch_layouts]) ; ++nch_layouts) {}
830+
#endif
831+
if (ch_layouts && nch_layouts > 0)
794832
{
795833
bool channel_layout_supported = false;
796834

797-
for (int i = 0 ; av_channel_layout_check(&pCodec->ch_layouts[i]) ; ++i)
835+
for (int i = 0 ; i < nch_layouts ; ++i)
798836
{
799-
if (av_channel_layout_compare(&pCodecCtx->ch_layout, &pCodec->ch_layouts[i]) == 0)
837+
if (av_channel_layout_compare(&pCodecCtx->ch_layout, &ch_layouts[i]) == 0)
800838
{
801839
channel_layout_supported = true;
802840
break;
@@ -809,9 +847,9 @@ namespace dlib
809847
<< "Channel layout "
810848
<< details::get_channel_layout_str(pCodecCtx)
811849
<< " not supported. Changing to default "
812-
<< details::get_channel_layout_str(pCodec->ch_layouts[0]);
850+
<< details::get_channel_layout_str(ch_layouts[0]);
813851

814-
av_channel_layout_copy(&pCodecCtx->ch_layout, &pCodec->ch_layouts[0]);
852+
av_channel_layout_copy(&pCodecCtx->ch_layout, &ch_layouts[0]);
815853
}
816854
}
817855
#else

0 commit comments

Comments
 (0)