Skip to content

Commit

Permalink
Write our own comptime to deal with ffmpeg 6
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Jul 31, 2024
1 parent 7988387 commit eabf491
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ jobs:
. $CONDA/etc/profile.d/conda.sh
conda activate pyav
python scripts\\fetch-vendor.py --config-file scripts\\ffmpeg-${{ matrix.config.ffmpeg }}.json $CONDA_PREFIX\\Library
python scripts\\comptime.py ${{ matrix.config.ffmpeg }}
python setup.py build_ext --inplace --ffmpeg-dir=$CONDA_PREFIX\\Library
- name: Test
Expand Down
2 changes: 1 addition & 1 deletion av/audio/frame.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ cdef class AudioFrame(Frame):
self.ptr.nb_samples = nb_samples
self.ptr.format = <int>format
self.ptr.ch_layout = layout
self.ptr.channels = layout.nb_channels
# [FFMPEG6] self.ptr.channels = layout.nb_channels # ffmpeg 6 only

# Sometimes this is called twice. Oh well.
self._init_user_attributes()
Expand Down
3 changes: 2 additions & 1 deletion include/libavcodec/avcodec.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ cdef extern from "libavcodec/avcodec.h" nogil:

int nb_samples # Audio samples
int sample_rate # Audio Sample rate
int channels
# [FFMPEG6] int channels

AVChannelLayout ch_layout

int64_t pts
Expand Down
1 change: 1 addition & 0 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ which ffmpeg || exit 2
ffmpeg -version || exit 3
echo

"$PYAV_PYTHON" scripts/comptime.py
"$PYAV_PYTHON" setup.py config build_ext --inplace || exit 1
28 changes: 28 additions & 0 deletions scripts/comptime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import sys

def replace_in_file(file_path):
try:
with open(file_path, "r", encoding="utf-8") as file:
content = file.read()

modified_content = content.replace("# [FFMPEG6] ", "")

with open(file_path, "w") as file:
file.write(modified_content)
except UnicodeDecodeError:
pass


def process_directory(directory):
for root, dirs, files in os.walk(directory):
for file in files:
file_path = os.path.join(root, file)
replace_in_file(file_path)

if sys.platform == "win32" and sys.argv[1].startswith("6"):
process_directory("av")
process_directory("include")
elif os.environ.get("PYAV_LIBRARY").startswith("ffmpeg-6"):
process_directory("av")
process_directory("include")

0 comments on commit eabf491

Please sign in to comment.