Skip to content

Commit

Permalink
Merge pull request #6726 from ant-media/ffmpeg-upgrade-latest
Browse files Browse the repository at this point in the history
Upgrade FFmpeg to 7.1
  • Loading branch information
mekya authored Oct 25, 2024
2 parents a6b905d + 19bd3e0 commit e5412c1
Show file tree
Hide file tree
Showing 23 changed files with 397 additions and 237 deletions.
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

0 comments on commit e5412c1

Please sign in to comment.