Skip to content

Commit

Permalink
[FFMPEG] support ffmpeg 7 (#2987)
Browse files Browse the repository at this point in the history
* support ffmpeg 7

* you need assembler

---------

Co-authored-by: pfeatherstone <pfeatherstone@pf>
  • Loading branch information
pfeatherstone and pfeatherstone authored Aug 1, 2024
1 parent 58b5055 commit 3ca155d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/build_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,39 @@ jobs:
- name: Build examples, etc
run: cmake --build build --config Release --parallel 2

ubuntu-latest-ffmpeg7:
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt update
sudo apt install make yasm
- name: Cache FFmpeg 7
uses: actions/cache@v3
id: cache-ffmpeg7
with:
path: /home/runner/ffmpeg-n7.0.1_installation
key: ffmpeg-n7.0.1_try2

- name: Build FFmpeg 7
if: steps.cache-ffmpeg7.outputs.cache-hit != 'true'
run: |
wget https://github.com/FFmpeg/FFmpeg/archive/refs/tags/n7.0.1.tar.gz
tar -xf n7.0.1.tar.gz
cd FFmpeg-n7.0.1
./configure --prefix=/home/runner/ffmpeg-n7.0.1_installation --disable-doc --disable-programs
make -j4
make install
cd ..
- name: Configure
run: cmake . -B build -DCMAKE_PREFIX_PATH=/home/runner/ffmpeg-n7.0.1_installation
- name: Build ffmpeg example
run: cmake --build build --config Release --target ffmpeg_video_muxing_ex --parallel 4

windows-latest:
runs-on: 'windows-latest'
steps:
Expand Down
6 changes: 5 additions & 1 deletion dlib/media/ffmpeg_details.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ extern "C" {
#include <memory>
#include "../logger.h"

#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 24, 100)
#define FFMPEG_HAS_CH_LAYOUT 1
#endif

namespace dlib { namespace ffmpeg { namespace details
{

Expand Down Expand Up @@ -156,7 +160,7 @@ namespace dlib { namespace ffmpeg { namespace details
}
}

#if FF_API_OLD_CHANNEL_LAYOUT
#if FFMPEG_HAS_CH_LAYOUT

inline AVChannelLayout convert_layout(const uint64_t channel_layout)
{
Expand Down
2 changes: 1 addition & 1 deletion dlib/media/ffmpeg_muxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ namespace dlib
}
}

#if FF_API_OLD_CHANNEL_LAYOUT
#if FFMPEG_HAS_CH_LAYOUT
if (pCodec->ch_layouts)
{
bool channel_layout_supported = false;
Expand Down
2 changes: 1 addition & 1 deletion dlib/media/ffmpeg_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ namespace dlib
if (std::tie(src_sample_rate, src_channel_layout, src_fmt) !=
std::tie(dst_sample_rate, dst_channel_layout, dst_fmt))
{
#if FF_API_OLD_CHANNEL_LAYOUT
#if LIBSWRESAMPLE_VERSION_INT >= AV_VERSION_INT(4, 5, 100)
AVChannelLayout layout_src = convert_layout(src_channel_layout);
AVChannelLayout layout_dst = convert_layout(dst_channel_layout);

Expand Down

1 comment on commit 3ca155d

@KellaEric
Copy link

Choose a reason for hiding this comment

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

Modularize logic: Wrap the functionality into a function to improve reusability.
Add debug logs: Provide clarity during execution for debugging purposes.
Ensure compatibility: Check for necessary libraries and environment conditions.

def handle_channel_layout_conversion(src_channel_layout, dst_channel_layout, lib_version):
"""
Convert source and destination channel layouts if conditions are met.

Args:
    src_channel_layout (str): The source channel layout.
    dst_channel_layout (str): The destination channel layout.
    lib_version (tuple): Library version as a tuple (major, minor, patch).

Returns:
    tuple: Converted source and destination layouts, or None if conditions are not met.
"""
try:
    # Check if old channel layout API is enabled
    if FF_API_OLD_CHANNEL_LAYOUT:
        # Check if the library version is at least 4.5.100
        if lib_version >= (4, 5, 100):
            # Validate input channel layouts
            if not src_channel_layout or not dst_channel_layout:
                raise ValueError("Source or destination channel layout is invalid.")
            
            # Convert layouts and log the operation
            layout_src = convert_layout(src_channel_layout)
            layout_dst = convert_layout(dst_channel_layout)
            
            print(f"Converted layouts: {layout_src}, {layout_dst}")
            return layout_src, layout_dst
        else:
            print("Library version is too low for conversion.")
    else:
        print("Old channel layout API is disabled.")
except Exception as e:
    print(f"Error during channel layout conversion: {e}")

return None

Example usage

FF_API_OLD_CHANNEL_LAYOUT = True # Assume this is defined elsewhere
LIBSWRESAMPLE_VERSION_INT = (4, 5, 100) # Example version
AV_VERSION_INT = lambda major, minor, patch: (major, minor, patch) # Simplified version comparator

Example inputs

src_channel_layout = "stereo"
dst_channel_layout = "5.1"

Call the function

handle_channel_layout_conversion(src_channel_layout, dst_channel_layout, LIBSWRESAMPLE_VERSION_INT)

Please # to comment.