Skip to content

Add libswresample to FFmpeg source build #560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packaging/build_ffmpeg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ tar -xf ffmpeg.tar.gz --strip-components 1
--enable-avfilter \
--enable-avformat \
--enable-avutil \
--enable-swscale
--enable-swscale \
--enable-swresample

make -j install
ls ${prefix}/*
Expand All @@ -78,27 +79,31 @@ if [[ "$(uname)" == Darwin ]]; then
avdevice=libavdevice.58
avfilter=libavfilter.7
swscale=libswscale.5
swresample=libswresample.3
elif [[ ${major_ver} == 5 ]]; then
avutil=libavutil.57
avcodec=libavcodec.59
avformat=libavformat.59
avdevice=libavdevice.59
avfilter=libavfilter.8
swscale=libswscale.6
swresample=libswresample.4
elif [[ ${major_ver} == 6 ]]; then
avutil=libavutil.58
avcodec=libavcodec.60
avformat=libavformat.60
avdevice=libavdevice.60
avfilter=libavfilter.9
swscale=libswscale.7
swresample=libswresample.4
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, it's version 4 twice in a row, this isn't a typo (logs were previously failing)!

elif [[ ${major_ver} == 7 ]]; then
avutil=libavutil.59
avcodec=libavcodec.61
avformat=libavformat.61
avdevice=libavdevice.61
avfilter=libavfilter.10
swscale=libswscale.8
swresample=libswresample.5
else
printf "Error: unexpected FFmpeg major version: %s\n" ${major_ver}
exit 1;
Expand All @@ -120,7 +125,7 @@ if [[ "$(uname)" == Darwin ]]; then
fi

# list up the paths to fix
for lib in ${avcodec} ${avdevice} ${avfilter} ${avformat} ${avutil} ${swscale}; do
for lib in ${avcodec} ${avdevice} ${avfilter} ${avformat} ${avutil} ${swscale} ${swresample}; do
${otool} -l ${prefix}/lib/${lib}.dylib | grep -B2 ${prefix}
done

Expand Down Expand Up @@ -155,6 +160,13 @@ if [[ "$(uname)" == Darwin ]]; then
${prefix}/lib/${swscale}.dylib
${otool} -l ${prefix}/lib/${swscale}.dylib | grep -B2 ${prefix}

${install_name_tool} \
-change ${prefix}/lib/${avutil}.dylib @rpath/${avutil}.dylib \
-delete_rpath ${prefix}/lib \
-id @rpath/${swresample}.dylib \
${prefix}/lib/${swresample}.dylib
${otool} -l ${prefix}/lib/${swresample}.dylib | grep -B2 ${prefix}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is only a dependency on avutil:

~/dev/torchcodec (add_swresample*) » ldd $CONDA_PREFIX/lib/libswresample.so | grep av                                                                              nicolashug@nicolashug-fedora-PF2MMKSN
	libavutil.so.58 => /home/nicolashug/.miniconda3/envs/codec/lib/./libavutil.so.58 (0x00007f2924800000)

I don't have access to a mac so I cannot provide the output of otool on the actual dylib as requested on #219 (comment), but that should be fine?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Mac wheel builds work on CI, we should be good.

${install_name_tool} \
-change ${prefix}/lib/${avcodec}.dylib @rpath/${avcodec}.dylib \
-change ${prefix}/lib/${avutil}.dylib @rpath/${avutil}.dylib \
Expand Down
Loading