Skip to content
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

Diff #7

Draft
wants to merge 15 commits into
base: base
Choose a base branch
from
Draft
Show file tree
Hide file tree
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: 16 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM ubuntu:20.04

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Configure apt and install packages
RUN apt-get update \
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
&& apt-get -y install git iproute2 procps lsb-release \
&& apt-get -y install libx265-dev mingw-w64 nasm build-essential gdb \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog
21 changes: 21 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "FFmpeg Dev Container",
"dockerFile": "Dockerfile",
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [
"ms-vscode.cpptools-extension-pack",
"foxundermoon.shell-format",
"github.vscode-github-actions"
]
}
},
"forwardPorts": [],
"mounts": [
"source=${localEnv:USERPROFILE}/.ssh,target=/root/.ssh,type=bind,consistency=cached"
],
"postCreateCommand": "chmod 600 /root/.ssh/*"
}
120 changes: 120 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Build FFmpeg

on:
workflow_dispatch:
inputs:
doRelease:
description: 'Publish new release'
type: boolean
default: false
required: false
buildOnly:
description: 'Only build ffmpeg'
type: boolean
default: false
required: false

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macos-14
target: macos-arm64
configure_args: --enable-pthreads --enable-neon
- os: macos-13
target: macos-x64
configure_args: --enable-pthreads
- os: ubuntu-latest
target: linux-x64
configure_args: --enable-pthreads
- os: ubuntu-latest
target: windows-x64
configure_args: --enable-w32threads --target-os=mingw32 --cross-prefix=x86_64-w64-mingw32- --arch=x86_64
- os: ubuntu-latest
target: linux-arm64
configure_args: --enable-pthreads --enable-neon

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare build script
run: |
chmod +x ./xlive/configure_script.sh
echo "CONFIGURE_ARGS=--enable-small --disable-debug ${{ matrix.configure_args }}" >> $GITHUB_ENV

- name: Install dependencies linux-x64
if: matrix.target == 'linux-x64'
run: |
sudo apt update
sudo apt install nasm

- name: Install dependencies windows-x64
if: matrix.target == 'windows-x64'
run: |
sudo apt update
sudo apt install mingw-w64 nasm

- name: Build macos-arm64
if: matrix.target == 'macos-arm64' || matrix.target == 'macos-x64'
run: |
brew install nasm

- name: Build linux-arm64
if: matrix.target == 'linux-arm64'
run: |
docker run --rm dockcross/linux-arm64 > ./dockcross-linux-arm64
chmod +x ./dockcross-linux-arm64
./dockcross-linux-arm64 xlive/configure_script.sh ${{ env.CONFIGURE_ARGS }}
./dockcross-linux-arm64 make -j$(nproc)

- name: Build general
if: matrix.target != 'linux-arm64'
run: |
xlive/configure_script.sh ${{ env.CONFIGURE_ARGS }}
make -j$(nproc)

- name: Upload FFmpeg as artifact
uses: actions/upload-artifact@v4
with:
name: ffmpeg-${{ matrix.target }}
path: |
./ffmpeg
./ffmpeg.exe
if-no-files-found: error

publish_release:
name: Publish release
if: ${{ !cancelled() && github.event.inputs.doRelease == 'true' && needs.build.result == 'success' }}
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download FFmpeg artifacts
uses: actions/download-artifact@v4
with:
pattern: ffmpeg*
merge-multiple: false
path: artifacts

- name: Zip artifacts
run: |
for dir in artifacts/*; do
zip -j -r "artifacts/${dir##*/}.zip" "$dir"
done

- name: Create release
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -xe
shopt -s nullglob
RELDATE=$(date +'%Y-%m-%d %H:%M:%S')
RELEASE_NAME="FFmpeg $RELDATE"
TAGNAME="autobuild-$(date +'%Y-%m-%d-%H-%M-%S')"
gh release create "$TAGNAME" --target "${{ github.ref }}" --title "$RELEASE_NAME" artifacts/*.zip

33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug ffmpeg",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/ffmpeg_g",
"args": [
"-i",
"xlive/split-test2.flv",
// "xlive/standard.flv",
"-c",
"copy",
"xlive/out4.mp4"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build ffmpeg linux x64 if not exist"
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnSave": false
}
16 changes: 16 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build ffmpeg linux x64 if not exist",
"type": "shell",
"command": [
"./xlive/dev_build.sh"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
1 change: 1 addition & 0 deletions libavformat/flv.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ enum {
FLV_CODECID_H264 = 7,
FLV_CODECID_REALH263= 8,
FLV_CODECID_MPEG4 = 9,
FLV_CODECID_HEVC = 12,
};

enum {
Expand Down
14 changes: 13 additions & 1 deletion libavformat/flvdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ static int flv_same_video_codec(AVCodecParameters *vpar, uint32_t flv_codecid)

switch (flv_codecid) {
case MKBETAG('h', 'v', 'c', '1'):
case FLV_CODECID_HEVC:
return vpar->codec_id == AV_CODEC_ID_HEVC;
case MKBETAG('a', 'v', '0', '1'):
return vpar->codec_id == AV_CODEC_ID_AV1;
Expand Down Expand Up @@ -342,6 +343,7 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream,

switch (flv_codecid) {
case MKBETAG('h', 'v', 'c', '1'):
case FLV_CODECID_HEVC:
par->codec_id = AV_CODEC_ID_HEVC;
vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
break;
Expand Down Expand Up @@ -1288,7 +1290,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
}

if (st->codecpar->codec_id == AV_CODEC_ID_H264 || st->codecpar->codec_id == AV_CODEC_ID_MPEG4 ||
(st->codecpar->codec_id == AV_CODEC_ID_HEVC && type == PacketTypeCodedFrames)) {
(st->codecpar->codec_id == AV_CODEC_ID_HEVC && (!enhanced_flv || type == PacketTypeCodedFrames))) {
// sign extension
int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000;
pts = av_sat_add64(dts, cts);
Expand All @@ -1309,6 +1311,16 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
st->codecpar->codec_id == AV_CODEC_ID_AV1 || st->codecpar->codec_id == AV_CODEC_ID_VP9)) {
AVDictionaryEntry *t;

// abort program when meeting the second sequence header
if (stream_type == FLV_STREAM_TYPE_VIDEO) {
static int s_video_header_count = 0;
++s_video_header_count;
if (s_video_header_count > 1) {
av_log(s, AV_LOG_FATAL, "[xlive]EOF new sps pps\n");
return -1;
}
}

if (st->codecpar->extradata) {
if ((ret = flv_queue_extradata(flv, s->pb, stream_type, size)) < 0)
return ret;
Expand Down
3 changes: 3 additions & 0 deletions xlive/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.flv
*.mp4
*.dat
3 changes: 3 additions & 0 deletions xlive/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnSave": true
}
30 changes: 30 additions & 0 deletions xlive/configure_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

./configure \
--disable-everything \
--disable-autodetect \
--disable-encoders \
--disable-decoders \
--enable-decoder='h264,aac,hevc' \
--enable-encoder='aac' \
--enable-parser='h264,aac,mp3' \
--enable-demuxer='flv,h264,aac,mp3,live_flv' \
--enable-muxer='flv,mp4' \
--enable-protocol='file,pipe,http' \
--enable-bsf='h264_mp4toannexb,aac_adtstoasc' \
--disable-avdevice \
--disable-swscale \
--disable-postproc \
--disable-doc \
--disable-runtime-cpudetect \
--enable-network \
--enable-gpl \
--enable-version3 \
--enable-avcodec \
--enable-avformat \
--enable-swresample \
--enable-avfilter \
--disable-programs \
--enable-ffmpeg \
"$@" \
--pkg-config=pkg-config
25 changes: 25 additions & 0 deletions xlive/dev_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -x
SCRIPT_DIR=$(dirname "$0")
if [ "$1" = "windows" ]; then
if [ ! -f "./ffmpeg.exe" ]; then
$SCRIPT_DIR/configure_script.sh \
--target-os=mingw32 \
--arch=x86_64 \
--cross-prefix=x86_64-w64-mingw32- \
--enable-debug=3 \
--disable-optimizations \
--enable-w32threads \
--disable-stripping
fi
else
if [ ! -f "./ffmpeg" ]; then
$SCRIPT_DIR/configure_script.sh \
--enable-debug=3 \
--disable-optimizations \
--enable-pthreads \
--disable-stripping
fi
fi

make -j$(nproc)