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

Upgrade FFmpeg to 7.1 #6726

Merged
merged 31 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0a0ef32
Fix compiler errors in upgrading the ffmpeg
mekya Sep 4, 2024
e46b2da
Update ffmpeg versions
mekya Sep 8, 2024
c2b07b5
Merge remote-tracking branch 'origin/master' into ffmpeg-upgrade-latest
mekya Sep 23, 2024
6eb09b9
Update fmp4 extension for HLS & Refactor
mekya Sep 27, 2024
1721ebe
Change the location of getting ffmpeg custom build files
mekya Sep 27, 2024
0957a26
Fix syntax issue
mekya Sep 27, 2024
cc420d7
Remove - from multiline command
mekya Sep 27, 2024
5a4ae21
Add missing ffmpeg file
mekya Sep 27, 2024
152b659
Fix test case
mekya Sep 28, 2024
83a877d
Fix test case
mekya Sep 28, 2024
c4bfa95
Remove ffmpeg build replacement because there is a new version
mekya Oct 21, 2024
22b7813
Merge remote-tracking branch 'origin/master' into ffmpeg-upgrade-latest
mekya Oct 21, 2024
e2d673a
Fix test case
mekya Oct 21, 2024
e368087
Fix the test case
mekya Oct 21, 2024
2b8ad66
Fix mp4 rotation issue
mekya Oct 22, 2024
2f023bf
Set coded_side_data if address is null
mekya Oct 22, 2024
18f5c84
Disable testRemux temp
mekya Oct 22, 2024
80cfa40
Fix test case
mekya Oct 22, 2024
53a9d74
Fix test case
mekya Oct 22, 2024
c5f1fb8
Fix test case
mekya Oct 22, 2024
d4848bb
Disable testMp4MuxingWithDirectParams temp
mekya Oct 22, 2024
2bd74e0
Update ffmpeg with new build and enable tests
mekya Oct 22, 2024
0847b43
Fix crash in unit tests
mekya Oct 22, 2024
f647085
Rebuild Ant Media Server after FFmpeg replacement
mekya Oct 22, 2024
573bc1d
Fix RTMP buffering timing
mekya Oct 22, 2024
d678c67
Remove setting verbose log level for ffmpeg
mekya Oct 22, 2024
78fd3f3
Download custom ffmpeg build in packaging phase
mekya Oct 23, 2024
35fe268
Refactor remux method to not have crash
mekya Oct 23, 2024
5e279dc
Fix test crash
mekya Oct 23, 2024
d255c5e
Add comment for hwScaling and build for latest native libs
mekya Oct 24, 2024
19bd3e0
Update test case according to latest ffmpeg build
mekya Oct 24, 2024
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
10 changes: 3 additions & 7 deletions .github/actions/build-projects/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ inputs:
runs:
using: "composite"
steps:

- name: Clone and build Ant Media Server Parent project
shell: bash
run: |
Expand All @@ -19,7 +19,7 @@ runs:
mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dgpg.skip=true --quiet
cd ..

- name: Build Ant Media Server project
- name: Build Ant Media Server project #let the dependencies be resolved
shell: bash
run: mvn clean install -Dmaven.javadoc.skip=true -Dmaven.test.skip=true -Dgpg.skip=true --quiet

Expand Down Expand Up @@ -93,8 +93,4 @@ runs:
cp -a ManagementConsole_AngularApp/node_modules/. ~/ManagementConsole_AngularApp-node_modules-cache/


- name: Replace ffmpeg builds
shell: bash
run: |
wget -O ~/.m2/repository/org/bytedeco/ffmpeg/5.1.2-1.5.8/ffmpeg-5.1.2-1.5.8-linux-x86_64.jar https://storage.sbg.cloud.ovh.net/v1/AUTH_8cb28f9bc6ee43f0a3a1825efbb4311e/test-storage/ffmpeg-5.1.2-1.5.8-linux-x86_64.jar
wget -O ~/.m2/repository/org/bytedeco/ffmpeg/5.1.2-1.5.8/ffmpeg-5.1.2-1.5.8-linux-arm64.jar https://storage.sbg.cloud.ovh.net/v1/AUTH_8cb28f9bc6ee43f0a3a1825efbb4311e/test-storage/ffmpeg-5.1.2-1.5.8-linux-arm64.jar

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ temp/

*.iml
.idea
.fleet
.fleet
/ffmpeg*.jar
12 changes: 12 additions & 0 deletions download_custom_ffmpeg_builds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash


if [ ! -f "ffmpeg-7.1-1.5.11-SNAPSHOT-linux-x86_64.jar" ]; then
wget -O ffmpeg-7.1-1.5.11-SNAPSHOT-linux-x86_64.jar https://storage.sbg.cloud.ovh.net/v1/AUTH_8cb28f9bc6ee43f0a3a1825efbb4311e/test-storage/ffmpeg-7.1-1.5.11-SNAPSHOT-linux-x86_64.jar
fi

if [ ! -f "ffmpeg-7.1-1.5.11-SNAPSHOT-linux-arm64.jar" ]; then
wget -O ffmpeg-7.1-1.5.11-SNAPSHOT-linux-arm64.jar https://storage.sbg.cloud.ovh.net/v1/AUTH_8cb28f9bc6ee43f0a3a1825efbb4311e/test-storage/ffmpeg-7.1-1.5.11-SNAPSHOT-linux-arm64.jar
fi


23 changes: 23 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@
</artifactItems>
</configuration>
</execution>

</executions>
</plugin>
<plugin>
Expand Down Expand Up @@ -754,6 +755,17 @@
</arguments>
</configuration>
</execution>
<execution>
<id>download-custom-ffmpeg-builds</id> <!-- We're downloading custom builds because original files are updated when building and our custom build not works. We overwrite these info in assembely files -->
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>download_custom_ffmpeg_builds.sh</executable>
</configuration>
</execution>

</executions>
</plugin>
<plugin>
Expand Down Expand Up @@ -954,7 +966,18 @@
</arguments>
</configuration>
</execution>
<execution>
<id>download-custom-ffmpeg-builds</id> <!-- We're downloading custom builds because original files are updated when building and our custom build not works. We overwrite these info in assembely files -->
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>download_custom_ffmpeg_builds.sh</executable>
</configuration>
</execution>
</executions>

</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
Expand Down
15 changes: 15 additions & 0 deletions src/main/assembly/server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,23 @@
<exclude>javacpp*windows*.jar</exclude>
<exclude>cuda*.jar</exclude>


<!-- exclude these files becauwe we write below from the custom build -->

<exclude>ffmpeg*linux-x86_64.jar</exclude>
<exclude>ffmpeg*linux-arm64.jar</exclude>


</excludes>
</fileSet>
<fileSet> <!-- Overwrite Custom FFmepg Build Plugins - these files are downloaded autoomatically in pom.xml-->
<directory>${project.basedir}</directory>
<outputDirectory>plugins</outputDirectory>
<includes>
<include>ffmpeg-*.jar</include>
</includes>

</fileSet>
<fileSet>
<directory>${project.basedir}/src/main/server</directory>
<outputDirectory></outputDirectory>
Expand Down
11 changes: 11 additions & 0 deletions src/main/assembly/server_enterprise.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,19 @@
<exclude>cuda*ppc64le.jar</exclude>
<exclude>cuda*macosx*.jar</exclude>
<exclude>cuda*windows*.jar</exclude>

<!-- exclude these files becauwe we write below from the custom build -->
<exclude>ffmpeg*linux-x86_64.jar</exclude>
<exclude>ffmpeg*linux-arm64.jar</exclude>
</excludes>
</fileSet>
<fileSet> <!-- Overwrite Custom FFmepg Build Plugins - these files are downloaded autoomatically in pom.xml -->
<directory>${project.basedir}</directory>
<outputDirectory>plugins</outputDirectory>
<includes>
<include>ffmpeg-*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/main/server</directory>
<outputDirectory></outputDirectory>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/antmedia/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2129,7 +2129,8 @@ public boolean isWriteStatsToDatastore() {
private boolean sendAudioLevelToViewers = false;

/**
* Enable/disable video frame scaling in GPU when there is an adaptive bitrate
* Enable/disable video frame scaling in GPU when there is an adaptive bitrate.
* It's disabled by default. If you want to use this feature, ask from Ant Media Support to have the build that supports this feature - mekya
*/
@Value("${hwScalingEnabled:${"+SETTINGS_HW_SCALING_ENABLED+":false}}")
private boolean hwScalingEnabled = false;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/antmedia/filter/TokenFilterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,27 +242,27 @@ else if(requestURI.contains("chunked")) {
}

//if specific ts file requested
tsRegex = "(.*)_([0-9]+p|[0-9]+kbps|[0-9]+p[0-9]+kbps)+[0-9]{" + Muxer.SEGMENT_INDEX_LENGTH + "}.ts$"; // matches ending with _[_240p300kbps0000].ts or _[_300kbps0000].ts or _[_240p0000].ts default ts file extension _[0000].ts
tsRegex = "(.*)_([0-9]+p|[0-9]+kbps|[0-9]+p[0-9]+kbps)+[0-9]{" + Muxer.SEGMENT_INDEX_LENGTH + "}.(ts|fmp4)$"; // matches ending with _[_240p300kbps0000].ts or _[_300kbps0000].ts or _[_240p0000].ts default ts file extension _[0000].ts
if (requestURI.matches(tsRegex)) {
endIndex = requestURI.lastIndexOf('_'); //because file format is [NAME]_[RESOLUTION]p[0000].ts
return requestURI.substring(requestURI.lastIndexOf("/")+1, endIndex);
}

//for backward compatibility
tsRegex = "(.*)_([0-9]+p|[0-9]+kbps|[0-9]+p[0-9]+kbps)+[0-9]{4}.ts$"; // matches ending with _[_240p300kbps0000].ts or _[_300kbps0000].ts or _[_240p0000].ts default ts file extension _[0000].ts
tsRegex = "(.*)_([0-9]+p|[0-9]+kbps|[0-9]+p[0-9]+kbps)+[0-9]{4}.(ts|fmp4)$"; // matches ending with _[_240p300kbps0000].ts or _[_300kbps0000].ts or _[_240p0000].ts default ts file extension _[0000].ts
if (requestURI.matches(tsRegex)) {
endIndex = requestURI.lastIndexOf('_'); //because file format is [NAME]_[RESOLUTION]p[0000].ts
return requestURI.substring(requestURI.lastIndexOf("/")+1, endIndex);
}

tsRegex = "(.*)[0-9]{"+ Muxer.SEGMENT_INDEX_LENGTH +"}.ts$"; // matches default ts file extension [0000].ts
tsRegex = "(.*)[0-9]{"+ Muxer.SEGMENT_INDEX_LENGTH +"}.(ts|fmp4)$"; // matches default ts file extension [0000].ts
if (requestURI.matches(tsRegex)) {
endIndex = requestURI.lastIndexOf('.'); //because file format is [NAME][0000].ts
return requestURI.substring(requestURI.lastIndexOf("/")+1, endIndex-Muxer.SEGMENT_INDEX_LENGTH);
}

//for backward compatibility
tsRegex = "(.*)[0-9]{4}.ts$"; // matches default ts file extension [0000].ts
tsRegex = "(.*)[0-9]{4}.(ts|fmp4)$"; // matches default ts file extension [0000].ts
if (requestURI.matches(tsRegex)) {
endIndex = requestURI.lastIndexOf('.'); //because file format is [NAME][0000].ts
return requestURI.substring(requestURI.lastIndexOf("/")+1, endIndex-4);
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/io/antmedia/muxer/HLSMuxer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ public class HLSMuxer extends Muxer {


public static final String SEI_USER_DATA = "sei_user_data";

private static final String TS_EXTENSION = "ts";
private static final String FMP4_EXTENSION = "fmp4";

private static final String SEGMENT_SUFFIX_TS = "%0"+SEGMENT_INDEX_LENGTH+"d.ts";
private static final String SEGMENT_SUFFIX_FMP4 = "%0"+SEGMENT_INDEX_LENGTH+"d.m4s";
private static final String SEGMENT_SUFFIX_TS = "%0"+SEGMENT_INDEX_LENGTH+"d." + TS_EXTENSION;
//DASH also has m4s and ChunkTransferServlet is responsbile for streaming m4s files, so it's better to use fmp4 here
private static final String SEGMENT_SUFFIX_FMP4 = "%0"+SEGMENT_INDEX_LENGTH+"d."+ FMP4_EXTENSION;

private static final String HLS_SEGMENT_TYPE_MPEGTS = "mpegts";
private static final String HLS_SEGMENT_TYPE_FMP4 = "fmp4";
Expand Down Expand Up @@ -149,19 +153,17 @@ public void init(IScope scope, String name, int resolutionHeight, String subFold

if (StringUtils.isNotBlank(httpEndpoint))
{

segmentFilename = httpEndpoint;
segmentFilename += !segmentFilename.endsWith(File.separator) ? File.separator : "";
segmentFilename += (this.subFolder != null ? subFolder : "");
segmentFilename += !segmentFilename.endsWith(File.separator) ? File.separator : "";
segmentFilename += initialResourceNameWithoutExtension;

segmentFilename += initialResourceNameWithoutExtension;
}
else {
else
{
segmentFilename = file.getParentFile().toString();
segmentFilename += !segmentFilename.endsWith(File.separator) ? File.separator : "";
segmentFilename += initialResourceNameWithoutExtension;

}

//remove double slashes with single slash because it may cause problems
Expand Down Expand Up @@ -294,12 +296,13 @@ public synchronized void addID3Data(String data) {

ByteBuffer byteBuffer = ByteBuffer.allocate(id3ContentSize);

logger.info("Adding ID3 data: {} lenght:{} byte length:{} buffer capacacity:{}", data, data.length(), data.getBytes().length, byteBuffer.capacity());
logger.debug("Adding ID3 data: {} lenght:{} to streamId:{} endpoint:{}", data, data.length(), byteBuffer.capacity(), streamId, getOutputURL());

// ID3 header (https://id3.org/id3v2.3.0#ID3v2_header)
byteBuffer.put("ID3".getBytes());
byteBuffer.put(new byte[]{0x03, 0x00}); // version
byteBuffer.put((byte) 0x00); // flags

byteBuffer.put(convertIntToID3v2TagSize(tagSize)); // size

// TXXX frame header (https://id3.org/id3v2.3.0#ID3v2_frame_overview)
Expand Down Expand Up @@ -367,7 +370,7 @@ public synchronized void writeTrailer() {

vertx.setTimer(Integer.parseInt(hlsTime) * Integer.parseInt(hlsListSize) * 1000l, l ->
{
final String filenameWithoutExtension = file.getName().substring(0, file.getName().lastIndexOf(extension));
//final String filenameWithoutExtension = file.getName().substring(0, file.getName().lastIndexOf(extension));

//SEGMENT_SUFFIX_TS is %09d.ts
//convert segmentFileName to regular expression
Expand All @@ -381,7 +384,7 @@ public synchronized void writeTrailer() {
}

String segmentFileWithoutSuffix = segmentFilename.substring(segmentFilename.lastIndexOf("/")+1, indexOfSuffix);
String regularExpression = segmentFileWithoutSuffix + "[0-9]*\\.(?:ts|m4s)$";
String regularExpression = segmentFileWithoutSuffix + "[0-9]*\\.(?:" + TS_EXTENSION +"|" + FMP4_EXTENSION +")$";
File[] files = getHLSFilesInDirectory(regularExpression);

if (files != null)
Expand Down
32 changes: 24 additions & 8 deletions src/main/java/io/antmedia/muxer/Mp4Muxer.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.bytedeco.ffmpeg.avcodec.AVBitStreamFilter;
import org.bytedeco.ffmpeg.avcodec.AVCodecParameters;
import org.bytedeco.ffmpeg.avcodec.AVPacket;
import org.bytedeco.ffmpeg.avcodec.AVPacketSideData;
import org.bytedeco.ffmpeg.avformat.AVFormatContext;
import org.bytedeco.ffmpeg.avformat.AVIOContext;
import org.bytedeco.ffmpeg.avformat.AVStream;
Expand Down Expand Up @@ -229,17 +230,32 @@ public static void remux(String srcFile, String dstFile, int rotation) {
//On the other hand, if av_stream_add_side_data below would copy the side data, there would be no problem.
//av_stream_add_side_data just sets the pointer
//mekya Jan 29, 22
IntPointer rotationMatrixPointer = new IntPointer(avutil.av_malloc(size)).capacity(size);

avutil.av_display_rotation_set(rotationMatrixPointer, rotation);

BytePointer bytePointer = new BytePointer(rotationMatrixPointer);
bytePointer.limit(rotationMatrixPointer.sizeof() * rotationMatrixPointer.limit());
int[] entryNb = new int[1];
entryNb[0] = stream.codecpar().nb_coded_side_data();

ret = avformat.av_stream_add_side_data(stream, avcodec.AV_PKT_DATA_DISPLAYMATRIX , bytePointer, bytePointer.limit());
if (ret < 0) {
AVPacketSideData sideData = new AVPacketSideData(stream.codecpar().coded_side_data());
AVPacketSideData av_packet_side_data_add = avcodec.av_packet_side_data_new(sideData,
entryNb,
avcodec.AV_PKT_DATA_DISPLAYMATRIX,
size,
0
);
//ret = avformat.av_stream_add_side_data(stream, avcodec.AV_PKT_DATA_DISPLAYMATRIX , bytePointer, bytePointer.limit());
if (av_packet_side_data_add == null) {
loggerStatic.error("Cannot add rotation matrix side data to file:{}", dstFile);
}
return;
}

IntPointer intPointer = new IntPointer(av_packet_side_data_add.data());
avutil.av_display_rotation_set(intPointer, rotation);

stream.codecpar().coded_side_data(sideData);
//entryNb increases in av_packet_side_data_new so just update it
stream.codecpar().nb_coded_side_data(entryNb[0]);

loggerStatic.info("Added rotation matrix side data to file:{}", dstFile);

}
}

Expand Down
Loading
Loading