Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

Commit 21e8381

Browse files
committed
improvements to mp4stream rendering
1 parent dfe7215 commit 21e8381

File tree

1 file changed

+56
-24
lines changed

1 file changed

+56
-24
lines changed

src/org/ffmpeg/android/FfmpegController.java

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,6 @@ public MediaDesc combineAudioAndVideo (MediaDesc videoIn, MediaDesc audioIn, Med
398398
cmd.add(ffmpegBin);
399399
cmd.add("-y");
400400

401-
cmd.add("-shortest");
402-
403401
cmd.add("-i");
404402
cmd.add(audioIn.path);
405403

@@ -519,26 +517,17 @@ public MediaDesc convertToMP4Stream (MediaDesc mediaIn, String outPath, ShellCal
519517
cmd.add("-i");
520518
cmd.add(mediaPath);
521519

522-
if (mediaIn.startTime != null)
523-
{
524-
cmd.add(FFMPEGArg.ARG_STARTTIME);
525-
cmd.add(mediaIn.startTime);
526-
}
520+
cmd.add("-f");
521+
cmd.add("mpegts");
527522

528-
if (mediaIn.duration != null)
529-
{
530-
cmd.add(FFMPEGArg.ARG_DURATION);
531-
cmd.add(mediaIn.duration);
532-
}
533-
534523
cmd.add("-c");
535524
cmd.add("copy");
536-
537-
cmd.add(FFMPEGArg.ARG_VIDEOBITSTREAMFILTER);
538-
cmd.add("h264_mp4toannexb");
539525

540-
cmd.add("-f");
541-
cmd.add("mpegts");
526+
cmd.add("-an");
527+
528+
//cmd.add(FFMPEGArg.ARG_VIDEOBITSTREAMFILTER);
529+
cmd.add("-bsf:v");
530+
cmd.add("h264_mp4toannexb");
542531

543532
mediaOut.path = outPath;
544533

@@ -903,20 +892,62 @@ public void processComplete(int exitValue) {
903892
}
904893

905894

895+
public MediaDesc trim (MediaDesc mediaIn, String outPath, ShellCallback sc) throws Exception
896+
{
897+
ArrayList<String> cmd = new ArrayList<String>();
898+
899+
MediaDesc mediaOut = mediaIn.clone();
900+
901+
String mediaPath = mediaIn.path;
902+
903+
cmd = new ArrayList<String>();
904+
905+
cmd.add(ffmpegBin);
906+
cmd.add("-y");
907+
cmd.add("-i");
908+
cmd.add(mediaPath);
909+
910+
cmd.add("-c");
911+
cmd.add("copy");
912+
913+
if (mediaIn.startTime != null)
914+
{
915+
cmd.add(FFMPEGArg.ARG_STARTTIME);
916+
cmd.add(mediaIn.startTime);
917+
}
918+
919+
if (mediaIn.duration != null)
920+
{
921+
cmd.add(FFMPEGArg.ARG_DURATION);
922+
cmd.add(mediaIn.duration);
923+
}
924+
925+
mediaOut.path = outPath;
926+
927+
cmd.add(mediaOut.path);
928+
929+
execFFMPEG(cmd, sc);
930+
931+
return mediaOut;
932+
}
933+
906934
public void concatAndTrimFilesMP4Stream (ArrayList<MediaDesc> videos,MediaDesc out, boolean mediaNeedsConversion, ShellCallback sc) throws Exception
907935
{
908936

909937
StringBuffer sbCat = new StringBuffer();
910938

911-
912939
ArrayList<String> alCleanupPaths = new ArrayList<String>();
913940

914941
int tmpIdx = 0;
915942

916943
for (MediaDesc vdesc : videos)
917944
{
918-
File fileOut = new File(mFileTemp,tmpIdx + ".ts");
919-
MediaDesc mdOut = convertToMP4Stream(vdesc,fileOut.getAbsolutePath(), sc);
945+
MediaDesc mdOut = new MediaDesc();
946+
File fileOut = new File(mFileTemp,tmpIdx + "-trim.mp4");
947+
mdOut = trim(vdesc,fileOut.getAbsolutePath(), sc);
948+
949+
fileOut = new File(mFileTemp,tmpIdx + ".ts");
950+
mdOut = convertToMP4Stream(mdOut,fileOut.getAbsolutePath(), sc);
920951
alCleanupPaths.add(mdOut.path);
921952

922953
if (sbCat.length()>0)
@@ -936,9 +967,10 @@ public void concatAndTrimFilesMP4Stream (ArrayList<MediaDesc> videos,MediaDesc o
936967

937968
cmd.add("-c");
938969
cmd.add("copy");
939-
940-
cmd.add("-bsf:a");
941-
cmd.add("aac_adtstoasc");
970+
971+
cmd.add("-an");
972+
//cmd.add("-bsf:a");
973+
//cmd.add("aac_adtstoasc");
942974

943975
cmd.add(out.path);
944976

0 commit comments

Comments
 (0)