【iOS】FFmpeg更改文件名
FFmpeg更改文件名, 文件名最终格式:libavutil_avutil.h
脚本存放目录:
目录:
change_name.sh
thin
include
libavcodec
libavfilter
libavformat
.....
libs
#!/bin/sh
THIN=$(pwd)/"thin"
echo "Renaming header files and updating includes"
INCLUDE_DIR="$THIN/include"
MODULES="libavcodec libavfilter libavformat libavutil libswresample libswscale"
# 临时存储重命名文件映射
RENAME_MAP=$(mktemp)
# Step 1: Rename header files
for MODULE in $MODULES
do
if [ -d "$INCLUDE_DIR/$MODULE" ]; then
cd "$INCLUDE_DIR/$MODULE"
for HEADER in *.h
do
if [ -f "$HEADER" ]; then
# Skip if file is already renamed
if [[ "$HEADER" != ${MODULE}_* ]]; then
NEW_NAME="${MODULE}_${HEADER}"
mv "$HEADER" "$NEW_NAME"
echo "$MODULE/$HEADER,$NEW_NAME" >> "$RENAME_MAP"
echo "Renamed $HEADER to $NEW_NAME"
fi
fi
done
fi
done
# Step 2: Scan and update includes
for MODULE in $MODULES
do
if [ -d "$INCLUDE_DIR/$MODULE" ]; then
cd "$INCLUDE_DIR/$MODULE"
for FILE in *.h
do
if [ -f "$FILE" ]; then
# Read file and replace #include directives
TEMP_FILE="${FILE}.tmp"
while IFS= read -r LINE
do
if echo "$LINE" | grep -qE '^#include ".*"'; then
INCLUDE_PATH=$(echo "$LINE" | sed -E 's/^#include "(.*)"/\1/')
if echo "$INCLUDE_PATH" | grep -q "/"; then
# 包含路径的 #include
MODULE_PATH=$(dirname "$INCLUDE_PATH")
BASE_NAME=$(basename "$INCLUDE_PATH")
RENAMED_FILE=$(grep "^$MODULE_PATH/$BASE_NAME," "$RENAME_MAP" | cut -d',' -f2)
if [ -n "$RENAMED_FILE" ]; then
NEW_INCLUDE="$MODULE_PATH/$RENAMED_FILE"
LINE=$(printf '%s' "$LINE" | sed "s#\"$INCLUDE_PATH\"#\"$NEW_INCLUDE\"#")
echo "Updated include with path in $FILE: $INCLUDE_PATH -> $NEW_INCLUDE"
fi
else
# 不包含路径的 #include
RENAMED_FILE=$(grep "^$MODULE/$INCLUDE_PATH," "$RENAME_MAP" | cut -d',' -f2)
if [ -n "$RENAMED_FILE" ]; then
NEW_INCLUDE="$RENAMED_FILE"
LINE=$(printf '%s' "$LINE" | sed "s#\"$INCLUDE_PATH\"#\"$NEW_INCLUDE\"#")
echo "Updated local include in $FILE: $INCLUDE_PATH -> $NEW_INCLUDE"
fi
fi
fi
echo "$LINE" >> "$TEMP_FILE"
done < "$FILE"
mv "$TEMP_FILE" "$FILE"
fi
done
fi
done
# 清理临时文件
rm "$RENAME_MAP"
echo "Header renaming and include updates complete!"