Code:

for (File f : files) { FrameGrabber grabber = new FFmpegFrameGrabber(f.getPath()); grabber.start(); while ((frame = grabber.grab()) != null) { recorder.record(frame); } grabber.stop(); } 

And it seems to be working fine, but if there are a lot of files, it is very long. Is there any method for this library to simply glue the files together and not to “rob” each?

  • I am not ready to give a full answer, but look at this: I don’t know what kind of container you have, but, in general, you need at least to adjust the PTS./DTS for each frame, starting with the second file. Those. it is necessary to process POFREYMOVO, from it you will not leave anywhere. BUT: if only gluing and video are made in the same format (codec, encoding parameters, resolution, frame rate, etc.), then DECODING and ENCODING can be excluded. Those. You will transmuxing. Purely using FFmpeg (libavformat) this is done quite simply. In a JavaCV wrapper, you need to look at the documentation. - Monah Tuk

2 answers 2

Look towards FfmpegController.concatAndTrimFilesMP4Stream ():

 package org.ffmpeg.android.test; import java.io.File; import java.util.ArrayList; import java.util.Locale; import net.sourceforge.sox.SoxController; import org.ffmpeg.android.Clip; import org.ffmpeg.android.FfmpegController; import org.ffmpeg.android.ShellUtils; public class ConcatTest { public static void test (String videoRoot, String fileTmpPath, String fileOut, double fadeLen) throws Exception { File fileTmp = new File(fileTmpPath); File fileAppRoot = new File(""); File fileVideoRoot = new File(videoRoot); FfmpegController fc = new FfmpegController(null, fileTmp); SoxController sxCon = new SoxController(null, fileAppRoot, null); ArrayList<Clip> listVideos = new ArrayList<Clip>(); String[] fileList = fileVideoRoot.list(); for (String fileVideo : fileList) { if (fileVideo.endsWith("mp4")) { Clip clip = new Clip(); clip.path = new File(fileVideoRoot,fileVideo).getCanonicalPath(); fc.getInfo(clip); clip.duration = clip.duration-fadeLen; listVideos.add(clip); } } Clip clipOut = new Clip (); clipOut.path = new File(fileOut).getCanonicalPath(); fc.concatAndTrimFilesMP4Stream(listVideos, clipOut, false, false, new ShellUtils.ShellCallback() { @Override public void shellOut(String shellLine) { System.out.println("fc>" + shellLine); } @Override public void processComplete(int exitValue) { if (exitValue < 0) System.err.println("concat non-zero exit: " + exitValue); } }); } } 

Taken from here

    Perhaps this will help you:

     cmd="( " h264options="-vcodec libx264 -b 512k -flags +loop+mv4 -cmp 256 \ -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 \ -me_method hex -subq 7 -trellis 1 -refs 5 -bf 3 \ -flags2 +bpyramid+wpred+mixed_refs+dct8x8 -coder 1 -me_range 16 \ -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10\ -qmax 51 -qdiff 4" outfile="out-`date +%F-%H%M.%S`.mp4" for i; do cmd="${cmd}ffmpeg -i $i -ab 256000 -vb 10000000 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -g 100 -f mpeg -; " done cmd="${cmd} ) | ffmpeg -y -i - -threads 8 ${h264options} -vb 10000000 -acodec libfaac -ar 44100 -ab 128k -s 1280x720 ${outfile}" echo "${cmd}" eval ${cmd}