Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Sample Test to convert media file in hls format in different Resolution #294

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
77 changes: 77 additions & 0 deletions src/test/java/net/bramp/ffmpeg/ReadmeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.io.IOException;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

import com.google.common.base.Joiner;
import net.bramp.ffmpeg.builder.FFmpegBuilder;
import net.bramp.ffmpeg.fixtures.Samples;
import net.bramp.ffmpeg.job.FFmpegJob;
Expand Down Expand Up @@ -141,4 +143,79 @@ public void progress(Progress progress) {

assertEquals(FFmpegJob.State.FINISHED, job.getState());
}

@Test
public void testHLSVideoEncoding() throws IOException {
long start = System.currentTimeMillis();
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
FFmpegProbeResult in = ffprobe.probe(Samples.big_buck_bunny_720p_1mb);
FFmpegBuilder builder = new FFmpegBuilder()
.setInput(in)
.overrideOutputFiles(true)
.addOutput("src/test/resources/net/bramp/ffmpeg/samples/%v/index.m3u8")
.setPreset("slow")
.addExtraArgs("-g", "48")
.addExtraArgs("-sc_threshold","0")
.addExtraArgs("-map","0:0")
.addExtraArgs("-map","0:1")
.addExtraArgs("-map","0:0")
.addExtraArgs("-map","0:1")
.addExtraArgs("-map","0:0")
.addExtraArgs("-map","0:1")
.addExtraArgs("-map","0:0")
.addExtraArgs("-map","0:1")
.addExtraArgs("-map","0:0")
.addExtraArgs("-map","0:1")
.addExtraArgs("-map","0:0")
.addExtraArgs("-map","0:1")
.addExtraArgs("-s:v:0","1920*1080")
.addExtraArgs("-b:v:0","1800k")
.addExtraArgs("-s:v:1","1280*720")
.addExtraArgs("-b:v:1","1200k")
.addExtraArgs("-s:v:2","858*480")
.addExtraArgs("-b:v:2","750k")
.addExtraArgs("-s:v:3","630*360")
.addExtraArgs("-b:v:3","550k")
.addExtraArgs("-s:v:4","426*240")
.addExtraArgs("-b:v:4","400k")
.addExtraArgs("-s:v:5","256*144")
.addExtraArgs("-b:v:5","200k")
.addExtraArgs("-c:a","copy")
.addExtraArgs("-var_stream_map","v:0,a:0,name:1080p v:1,a:1,name:720p v:2,a:2,name:480p v:3,a:3,name:360p v:4,a:4,name:240p v:5,a:5,name:144p")
.addExtraArgs("-master_pl_name","master.m3u8")
.addExtraArgs("-f","hls")
.addExtraArgs("-hls_time","10")
.addExtraArgs("-hls_playlist_type","vod")
.addExtraArgs("-hls_list_size","0")
.addExtraArgs("-hls_segment_filename","src/test/resources/net/bramp/ffmpeg/samples/%v/segment%d.ts")
.done();
String actual = Joiner.on(" ").join(ffmpeg.path(builder.build()));
System.out.println("actual "+actual);
FFmpegJob job =
executor.createJob(
builder,
new ProgressListener() {
// Using the FFmpegProbeResult determine the duration of the input
final double duration_ns = in.getFormat().duration * TimeUnit.SECONDS.toNanos(1);
@Override
public void progress(Progress progress) {
double percentage = progress.out_time_ns / duration_ns;
// Print out interesting information about the progress
System.out.println(
String.format(
locale,
"[%.0f%%] status:%s frame:%d time:%s fps:%.0f speed:%.2fx",
percentage * 100,
progress.status,
progress.frame,
FFmpegUtils.toTimecode(progress.out_time_ns, TimeUnit.NANOSECONDS),
progress.fps.doubleValue(),
progress.speed));
}
});
job.run();
long end = System.currentTimeMillis();
long execution = (end - start)/1000;
System.out.println("Execution time: " + execution + " seconds");
}
}