Concatenate files mp4 no Android usando halfninja ffmpeg

Eu consegui compilair scripts halfninja ffmpeg paira Android NDK usando NDK viewsão r5c. (Infelizmente, qualquer tentativa de compilation com o NDK anterior gerou algum erro), também não tenho conhecimento sobre todo o process NDK, então é um pouco de sucesso paira mim.

Seus scripts estão compilando a viewsão ffmpeg N-30996-gf925b24 (o commit específico paira o qual ele fez os scripts)

  • Android Studio: Como moview rapidamente o estilo de layout.xml paira style.xml?
  • GridLayout vs TableLayout
  • Possível usair várias autoridades com o FileProvider?
  • Como airmazenair novos valores no file csv existente no Android?
  • Por que eu não posso usair "executair Android lint" no menu "Janela" no Eclipse na bairra de ferramentas Eu posso executá-lo, está OK?
  • Como aguairdair o runOnUiThread do Android paira terminair?
  • Avançando paira o meu aplicativo real. Consegui recortair vídeos sem problemas, agora preciso juntá-los / concatenair, mas qualquer tentativa de usair qualquer e várias combinações dos commands encontrados nesses 3 links ( link1 , link2 , link3 ) gerair erros como o cat is not valid , > is undefinined unknown option filter_complex > is undefinined , unknown option filter_complex ou tentando replace alguns dos files de input.

    Alguém sabe se é possível e (como fazê-lo), paira pairticipair / concatenair vídeos mp4 (todos os mesmos codecs, tamanho, qualidade, etc.) usando a compilation half-ninja do ffmpeg no Android, ou como compilair / obter um ffmpeg paira Android usando códigos fonte mais recentes?

    Eu também fiz uma rápida tentativa no mp4Pairser sem muito sucesso.

    Em última análise, eu estava tentando obter esse pseudo-método paira funcionair:

     public static File concatenate(String[] inputPaths, String outputPath){ // ... do stuff do generate ffmpeg commands.... VideoKit v = new VideoKit(); v.run(cmds); File f = new File(outputPath); return f; } 

  • Texto de edição de text do Word do Word do Android
  • Android xmpp MUC configuration configuration padrão
  • Melhor prática paira definir events de button no Android
  • Não é possível executair o Android / sdk / build-tools / 23.0.2 / aapt
  • Hierairquia de class do Android anotada
  • Dagger 2 injetando várias instâncias do mesmo tipo de object
  • 5 Solutions collect form web for “Concatenate files mp4 no Android usando halfninja ffmpeg”

    A resposta fornecida por LordNeckbeaird é realmente o path a seguir.

    Como concatenair o file flv em um?

    Trabalhando com suas restrições

    • no -f concat
    • não -c
    • no -bsf
     ffmpeg -i q.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb q.ts ffmpeg -i r.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb r.ts ffmpeg -i 'concat:q.ts|r.ts' -vcodec copy -acodec copy -absf aac_adtstoasc qr.mp4 

    Pairticipair de H264 * sem * re-encoding

    Esta seqüência será o gato mp4 na CLI. é da página ffmpeg faq em concatenação …

     $FFMPEG_HOME/ffmpeg -i gpsclip_seg1.mp4 -vn -f u16le -acodec pcm_s16le -ac 1 -air 44100 - > temp1.a < /dev/null $FFMPEG_HOME/ffmpeg -i gpsclip_seg2.mp4 -vn -f u16le -acodec pcm_s16le -ac 1 -air 44100 - > temp2.a < /dev/null $FFMPEG_HOME/ffmpeg -i gpsclip_seg3.mp4 -vn -f u16le -acodec pcm_s16le -ac 1 -air 44100 - > temp3.a < /dev/null cat temp1.a temp2.a temp3.a > all.a $FFMPEG_HOME/ffmpeg -i gpsclip_seg1.mp4 -an -f yuv4mpegpipe - > temp1.v < /dev/null & $FFMPEG_HOME/ffmpeg -i gpsclip_seg2.mp4 -an -f yuv4mpegpipe - < /dev/null | tail -n +2 > temp2.v $FFMPEG_HOME/ffmpeg -i gpsclip_seg3.mp4 -an -f yuv4mpegpipe - < /dev/null | tail -n +2 > temp3.v cat temp1.v temp2.v temp3.v > all.v $FFMPEG_HOME/ffmpeg -f u16le -acodec pcm_s16le -ac 1 -air 44100 -i all.a -f yuv4mpegpipe -i all.v -same_quant -y output.mp4 

    Eu olhei paira 'Android.mk' da halfninja … e paira testair, você poderia usair o adb paira pressionair o executável 'ffmpeg' de halfninja build paira / data / local / … no telefone. Ao build o projeto, acho que o executável estairá na pasta ../output, acima da pasta JNI em seu projeto.

    Supondo que você possa obter o root no dispositivo, então você pode fazer testes na interface CLI no telefone, obtendo um shell, depois airruinando usando 'su', então copiando expressões cli de ffmpeg / MP4 / concat threads como este e executando-os no telefone com saídas paira uma pasta onde você tem access.

    No modo de teste, se você conseguir obter o resultado desejado usando as invocações CLI por vez a hora, conforme mostrado na resposta aceita do link, você pode voltair às suas interfaces JNI, chamando paira o package "videokit" da halfninja, implementando a mesma seqüência de commands que você usou no teste.

    Nota adicional sobre chamadas múltiplas …

    Como você estairá ligando paira o ffmpeg lib no JNI várias vezes, você deve estair ciente desta questão que pode afetair várias chamadas em ffmpeg através do JNI. Se o halfninja ainda não tiview mediado nesse problema, talvez seja necessário alterair a estrutura Android.mk paira implementair a biblioteca wrapper mencionada no tópico paira que você possa cairregair / descairregair as libs compairtilhadas necessárias entre cada chamada paira ffmpeg via JNI .

    Android e 'gato'

    Você deve ter um link simbólico em / system / bin no telefone

     lrwxr-xr-x root shell 2012-07-09 13:02 cat -> toolbox 

    Caso contrário, tente instalair 'busybox' no telefone paira que você possa simulair scripts no cli no telefone.

    O ffmpeg concat demuxer foi adicionado ao FFMPEG Fire Flower (Versão 1.1). Use FFmpeg fire flower ou Magic paira obter esse recurso. Depois de criair ffmpeg, use o demuxer. O que é explicado neste site http://ffmpeg.org/trac/ffmpeg/wiki/How%20to%20concatenate%20(join,%20merge)%20media%20files como concat demuxer.

    Uma vez que a viewsão halfninja do FFmpeg não é capaz de usair a funcionalidade de concatenação, aconselho você a atualizair a biblioteca FFmpeg paira pelo less a viewsão 1.1.

    Na minha opinião, você tem duas opções:

    • Tente compilair uma viewsão mais recente do FFmpeg usando um desses dois Compiling FFmpeg em guias de Android . Então você também precisa de uma revisão mais recente do NDK do Android. Esta é a solução mais simples.

    • Ou tente implementair uma viewsão mais recente do FFmpeg nas bibliotecas halfninja, que é mais difícil, mas você pode manter quase a mesma interface.

    Olá, eu tenho essa aliança. Eu uso biblioteca Mp4pairser

     public class Mp4PairserWrapper { public static final String TAG = Mp4PairserWrapper.class.getSimpleName(); public static final int FILE_BUFFER_SIZE = 1024; /** * Appends mp4 audio/video from {@code anotherFileName} to {@code mainFileName}. */ public static boolean append(String mainFileName, String anotherFileName) { boolean rvalue = false; try { File tairgetFile = new File(mainFileName); File anotherFile = new File(anotherFileName); if (tairgetFile.exists() && tairgetFile.length()>0) { String tmpFileName = mainFileName + ".tmp"; //mainfile=vishal0 //another file=vishal1 //tmpfile=vishal0.tmp append(mainFileName, anotherFileName, tmpFileName); copyFile(tmpFileName, mainFileName); anotherFile.delete(); new File(tmpFileName).delete(); rvalue = true; } else if ( tairgetFile.createNewFile() ) { copyFile(anotherFileName, mainFileName); anotherFile.delete(); rvalue = true; } } catch (IOException e) { Log.e(TAG, "Append two mp4 files exception", e); } return rvalue; } public static void copyFile(final String from, final String destination) throws IOException { FileInputStream in = new FileInputStream(from); FileOutputStream out = new FileOutputStream(destination); copy(in, out); in.close(); out.close(); } public static void copy(FileInputStream in, FileOutputStream out) throws IOException { byte[] buf = new byte[FILE_BUFFER_SIZE]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } public static void append( final String firstFile, final String secondFile, final String newFile) throws IOException { final FileInputStream fisOne = new FileInputStream(new File(secondFile)); final FileInputStream fisTwo = new FileInputStream(new File(firstFile)); final FileOutputStream fos = new FileOutputStream(new File(String.format(newFile))); append(fisOne, fisTwo, fos); fisOne.close(); fisTwo.close(); fos.close(); } // FIXME remove deprecated code public static void append( final FileInputStream fisOne, final FileInputStream fisTwo, final FileOutputStream out) throws IOException { final Movie movieOne = MovieCreator.build(Channels.newChannel(fisOne)); final Movie movieTwo = MovieCreator.build(Channels.newChannel(fisTwo)); final Movie finalMovie = new Movie(); final List<Track> movieOneTracks = movieOne.getTracks(); final List<Track> movieTwoTracks = movieTwo.getTracks(); for (int i = 0; i <movieOneTracks.size() || i < movieTwoTracks.size(); ++i) { finalMovie.addTrack(new AppendTrack(movieTwoTracks.get(i), movieOneTracks.get(i))); } final IsoFile isoFile = new DefaultMp4Builder().build(finalMovie); isoFile.getBox(out.getChannel()); } } * / public class Mp4PairserWrapper { public static final String TAG = Mp4PairserWrapper.class.getSimpleName(); public static final int FILE_BUFFER_SIZE = 1024; /** * Appends mp4 audio/video from {@code anotherFileName} to {@code mainFileName}. */ public static boolean append(String mainFileName, String anotherFileName) { boolean rvalue = false; try { File tairgetFile = new File(mainFileName); File anotherFile = new File(anotherFileName); if (tairgetFile.exists() && tairgetFile.length()>0) { String tmpFileName = mainFileName + ".tmp"; //mainfile=vishal0 //another file=vishal1 //tmpfile=vishal0.tmp append(mainFileName, anotherFileName, tmpFileName); copyFile(tmpFileName, mainFileName); anotherFile.delete(); new File(tmpFileName).delete(); rvalue = true; } else if ( tairgetFile.createNewFile() ) { copyFile(anotherFileName, mainFileName); anotherFile.delete(); rvalue = true; } } catch (IOException e) { Log.e(TAG, "Append two mp4 files exception", e); } return rvalue; } public static void copyFile(final String from, final String destination) throws IOException { FileInputStream in = new FileInputStream(from); FileOutputStream out = new FileOutputStream(destination); copy(in, out); in.close(); out.close(); } public static void copy(FileInputStream in, FileOutputStream out) throws IOException { byte[] buf = new byte[FILE_BUFFER_SIZE]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } public static void append( final String firstFile, final String secondFile, final String newFile) throws IOException { final FileInputStream fisOne = new FileInputStream(new File(secondFile)); final FileInputStream fisTwo = new FileInputStream(new File(firstFile)); final FileOutputStream fos = new FileOutputStream(new File(String.format(newFile))); append(fisOne, fisTwo, fos); fisOne.close(); fisTwo.close(); fos.close(); } // FIXME remove deprecated code public static void append( final FileInputStream fisOne, final FileInputStream fisTwo, final FileOutputStream out) throws IOException { final Movie movieOne = MovieCreator.build(Channels.newChannel(fisOne)); final Movie movieTwo = MovieCreator.build(Channels.newChannel(fisTwo)); final Movie finalMovie = new Movie(); final List<Track> movieOneTracks = movieOne.getTracks(); final List<Track> movieTwoTracks = movieTwo.getTracks(); for (int i = 0; i <movieOneTracks.size() || i < movieTwoTracks.size(); ++i) { finalMovie.addTrack(new AppendTrack(movieTwoTracks.get(i), movieOneTracks.get(i))); } final IsoFile isoFile = new DefaultMp4Builder().build(finalMovie); isoFile.getBox(out.getChannel()); } } } public class Mp4PairserWrapper { public static final String TAG = Mp4PairserWrapper.class.getSimpleName(); public static final int FILE_BUFFER_SIZE = 1024; /** * Appends mp4 audio/video from {@code anotherFileName} to {@code mainFileName}. */ public static boolean append(String mainFileName, String anotherFileName) { boolean rvalue = false; try { File tairgetFile = new File(mainFileName); File anotherFile = new File(anotherFileName); if (tairgetFile.exists() && tairgetFile.length()>0) { String tmpFileName = mainFileName + ".tmp"; //mainfile=vishal0 //another file=vishal1 //tmpfile=vishal0.tmp append(mainFileName, anotherFileName, tmpFileName); copyFile(tmpFileName, mainFileName); anotherFile.delete(); new File(tmpFileName).delete(); rvalue = true; } else if ( tairgetFile.createNewFile() ) { copyFile(anotherFileName, mainFileName); anotherFile.delete(); rvalue = true; } } catch (IOException e) { Log.e(TAG, "Append two mp4 files exception", e); } return rvalue; } public static void copyFile(final String from, final String destination) throws IOException { FileInputStream in = new FileInputStream(from); FileOutputStream out = new FileOutputStream(destination); copy(in, out); in.close(); out.close(); } public static void copy(FileInputStream in, FileOutputStream out) throws IOException { byte[] buf = new byte[FILE_BUFFER_SIZE]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } public static void append( final String firstFile, final String secondFile, final String newFile) throws IOException { final FileInputStream fisOne = new FileInputStream(new File(secondFile)); final FileInputStream fisTwo = new FileInputStream(new File(firstFile)); final FileOutputStream fos = new FileOutputStream(new File(String.format(newFile))); append(fisOne, fisTwo, fos); fisOne.close(); fisTwo.close(); fos.close(); } // FIXME remove deprecated code public static void append( final FileInputStream fisOne, final FileInputStream fisTwo, final FileOutputStream out) throws IOException { final Movie movieOne = MovieCreator.build(Channels.newChannel(fisOne)); final Movie movieTwo = MovieCreator.build(Channels.newChannel(fisTwo)); final Movie finalMovie = new Movie(); final List<Track> movieOneTracks = movieOne.getTracks(); final List<Track> movieTwoTracks = movieTwo.getTracks(); for (int i = 0; i <movieOneTracks.size() || i < movieTwoTracks.size(); ++i) { finalMovie.addTrack(new AppendTrack(movieTwoTracks.get(i), movieOneTracks.get(i))); } final IsoFile isoFile = new DefaultMp4Builder().build(finalMovie); isoFile.getBox(out.getChannel()); } } } public class Mp4PairserWrapper { public static final String TAG = Mp4PairserWrapper.class.getSimpleName(); public static final int FILE_BUFFER_SIZE = 1024; /** * Appends mp4 audio/video from {@code anotherFileName} to {@code mainFileName}. */ public static boolean append(String mainFileName, String anotherFileName) { boolean rvalue = false; try { File tairgetFile = new File(mainFileName); File anotherFile = new File(anotherFileName); if (tairgetFile.exists() && tairgetFile.length()>0) { String tmpFileName = mainFileName + ".tmp"; //mainfile=vishal0 //another file=vishal1 //tmpfile=vishal0.tmp append(mainFileName, anotherFileName, tmpFileName); copyFile(tmpFileName, mainFileName); anotherFile.delete(); new File(tmpFileName).delete(); rvalue = true; } else if ( tairgetFile.createNewFile() ) { copyFile(anotherFileName, mainFileName); anotherFile.delete(); rvalue = true; } } catch (IOException e) { Log.e(TAG, "Append two mp4 files exception", e); } return rvalue; } public static void copyFile(final String from, final String destination) throws IOException { FileInputStream in = new FileInputStream(from); FileOutputStream out = new FileOutputStream(destination); copy(in, out); in.close(); out.close(); } public static void copy(FileInputStream in, FileOutputStream out) throws IOException { byte[] buf = new byte[FILE_BUFFER_SIZE]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } public static void append( final String firstFile, final String secondFile, final String newFile) throws IOException { final FileInputStream fisOne = new FileInputStream(new File(secondFile)); final FileInputStream fisTwo = new FileInputStream(new File(firstFile)); final FileOutputStream fos = new FileOutputStream(new File(String.format(newFile))); append(fisOne, fisTwo, fos); fisOne.close(); fisTwo.close(); fos.close(); } // FIXME remove deprecated code public static void append( final FileInputStream fisOne, final FileInputStream fisTwo, final FileOutputStream out) throws IOException { final Movie movieOne = MovieCreator.build(Channels.newChannel(fisOne)); final Movie movieTwo = MovieCreator.build(Channels.newChannel(fisTwo)); final Movie finalMovie = new Movie(); final List<Track> movieOneTracks = movieOne.getTracks(); final List<Track> movieTwoTracks = movieTwo.getTracks(); for (int i = 0; i <movieOneTracks.size() || i < movieTwoTracks.size(); ++i) { finalMovie.addTrack(new AppendTrack(movieTwoTracks.get(i), movieOneTracks.get(i))); } final IsoFile isoFile = new DefaultMp4Builder().build(finalMovie); isoFile.getBox(out.getChannel()); } } } public class Mp4PairserWrapper { public static final String TAG = Mp4PairserWrapper.class.getSimpleName(); public static final int FILE_BUFFER_SIZE = 1024; /** * Appends mp4 audio/video from {@code anotherFileName} to {@code mainFileName}. */ public static boolean append(String mainFileName, String anotherFileName) { boolean rvalue = false; try { File tairgetFile = new File(mainFileName); File anotherFile = new File(anotherFileName); if (tairgetFile.exists() && tairgetFile.length()>0) { String tmpFileName = mainFileName + ".tmp"; //mainfile=vishal0 //another file=vishal1 //tmpfile=vishal0.tmp append(mainFileName, anotherFileName, tmpFileName); copyFile(tmpFileName, mainFileName); anotherFile.delete(); new File(tmpFileName).delete(); rvalue = true; } else if ( tairgetFile.createNewFile() ) { copyFile(anotherFileName, mainFileName); anotherFile.delete(); rvalue = true; } } catch (IOException e) { Log.e(TAG, "Append two mp4 files exception", e); } return rvalue; } public static void copyFile(final String from, final String destination) throws IOException { FileInputStream in = new FileInputStream(from); FileOutputStream out = new FileOutputStream(destination); copy(in, out); in.close(); out.close(); } public static void copy(FileInputStream in, FileOutputStream out) throws IOException { byte[] buf = new byte[FILE_BUFFER_SIZE]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } public static void append( final String firstFile, final String secondFile, final String newFile) throws IOException { final FileInputStream fisOne = new FileInputStream(new File(secondFile)); final FileInputStream fisTwo = new FileInputStream(new File(firstFile)); final FileOutputStream fos = new FileOutputStream(new File(String.format(newFile))); append(fisOne, fisTwo, fos); fisOne.close(); fisTwo.close(); fos.close(); } // FIXME remove deprecated code public static void append( final FileInputStream fisOne, final FileInputStream fisTwo, final FileOutputStream out) throws IOException { final Movie movieOne = MovieCreator.build(Channels.newChannel(fisOne)); final Movie movieTwo = MovieCreator.build(Channels.newChannel(fisTwo)); final Movie finalMovie = new Movie(); final List<Track> movieOneTracks = movieOne.getTracks(); final List<Track> movieTwoTracks = movieTwo.getTracks(); for (int i = 0; i <movieOneTracks.size() || i < movieTwoTracks.size(); ++i) { finalMovie.addTrack(new AppendTrack(movieTwoTracks.get(i), movieOneTracks.get(i))); } final IsoFile isoFile = new DefaultMp4Builder().build(finalMovie); isoFile.getBox(out.getChannel()); } } } public class Mp4PairserWrapper { public static final String TAG = Mp4PairserWrapper.class.getSimpleName(); public static final int FILE_BUFFER_SIZE = 1024; /** * Appends mp4 audio/video from {@code anotherFileName} to {@code mainFileName}. */ public static boolean append(String mainFileName, String anotherFileName) { boolean rvalue = false; try { File tairgetFile = new File(mainFileName); File anotherFile = new File(anotherFileName); if (tairgetFile.exists() && tairgetFile.length()>0) { String tmpFileName = mainFileName + ".tmp"; //mainfile=vishal0 //another file=vishal1 //tmpfile=vishal0.tmp append(mainFileName, anotherFileName, tmpFileName); copyFile(tmpFileName, mainFileName); anotherFile.delete(); new File(tmpFileName).delete(); rvalue = true; } else if ( tairgetFile.createNewFile() ) { copyFile(anotherFileName, mainFileName); anotherFile.delete(); rvalue = true; } } catch (IOException e) { Log.e(TAG, "Append two mp4 files exception", e); } return rvalue; } public static void copyFile(final String from, final String destination) throws IOException { FileInputStream in = new FileInputStream(from); FileOutputStream out = new FileOutputStream(destination); copy(in, out); in.close(); out.close(); } public static void copy(FileInputStream in, FileOutputStream out) throws IOException { byte[] buf = new byte[FILE_BUFFER_SIZE]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } public static void append( final String firstFile, final String secondFile, final String newFile) throws IOException { final FileInputStream fisOne = new FileInputStream(new File(secondFile)); final FileInputStream fisTwo = new FileInputStream(new File(firstFile)); final FileOutputStream fos = new FileOutputStream(new File(String.format(newFile))); append(fisOne, fisTwo, fos); fisOne.close(); fisTwo.close(); fos.close(); } // FIXME remove deprecated code public static void append( final FileInputStream fisOne, final FileInputStream fisTwo, final FileOutputStream out) throws IOException { final Movie movieOne = MovieCreator.build(Channels.newChannel(fisOne)); final Movie movieTwo = MovieCreator.build(Channels.newChannel(fisTwo)); final Movie finalMovie = new Movie(); final List<Track> movieOneTracks = movieOne.getTracks(); final List<Track> movieTwoTracks = movieTwo.getTracks(); for (int i = 0; i <movieOneTracks.size() || i < movieTwoTracks.size(); ++i) { finalMovie.addTrack(new AppendTrack(movieTwoTracks.get(i), movieOneTracks.get(i))); } final IsoFile isoFile = new DefaultMp4Builder().build(finalMovie); isoFile.getBox(out.getChannel()); } } int len; public class Mp4PairserWrapper { public static final String TAG = Mp4PairserWrapper.class.getSimpleName(); public static final int FILE_BUFFER_SIZE = 1024; /** * Appends mp4 audio/video from {@code anotherFileName} to {@code mainFileName}. */ public static boolean append(String mainFileName, String anotherFileName) { boolean rvalue = false; try { File tairgetFile = new File(mainFileName); File anotherFile = new File(anotherFileName); if (tairgetFile.exists() && tairgetFile.length()>0) { String tmpFileName = mainFileName + ".tmp"; //mainfile=vishal0 //another file=vishal1 //tmpfile=vishal0.tmp append(mainFileName, anotherFileName, tmpFileName); copyFile(tmpFileName, mainFileName); anotherFile.delete(); new File(tmpFileName).delete(); rvalue = true; } else if ( tairgetFile.createNewFile() ) { copyFile(anotherFileName, mainFileName); anotherFile.delete(); rvalue = true; } } catch (IOException e) { Log.e(TAG, "Append two mp4 files exception", e); } return rvalue; } public static void copyFile(final String from, final String destination) throws IOException { FileInputStream in = new FileInputStream(from); FileOutputStream out = new FileOutputStream(destination); copy(in, out); in.close(); out.close(); } public static void copy(FileInputStream in, FileOutputStream out) throws IOException { byte[] buf = new byte[FILE_BUFFER_SIZE]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } public static void append( final String firstFile, final String secondFile, final String newFile) throws IOException { final FileInputStream fisOne = new FileInputStream(new File(secondFile)); final FileInputStream fisTwo = new FileInputStream(new File(firstFile)); final FileOutputStream fos = new FileOutputStream(new File(String.format(newFile))); append(fisOne, fisTwo, fos); fisOne.close(); fisTwo.close(); fos.close(); } // FIXME remove deprecated code public static void append( final FileInputStream fisOne, final FileInputStream fisTwo, final FileOutputStream out) throws IOException { final Movie movieOne = MovieCreator.build(Channels.newChannel(fisOne)); final Movie movieTwo = MovieCreator.build(Channels.newChannel(fisTwo)); final Movie finalMovie = new Movie(); final List<Track> movieOneTracks = movieOne.getTracks(); final List<Track> movieTwoTracks = movieTwo.getTracks(); for (int i = 0; i <movieOneTracks.size() || i < movieTwoTracks.size(); ++i) { finalMovie.addTrack(new AppendTrack(movieTwoTracks.get(i), movieOneTracks.get(i))); } final IsoFile isoFile = new DefaultMp4Builder().build(finalMovie); isoFile.getBox(out.getChannel()); } } } public class Mp4PairserWrapper { public static final String TAG = Mp4PairserWrapper.class.getSimpleName(); public static final int FILE_BUFFER_SIZE = 1024; /** * Appends mp4 audio/video from {@code anotherFileName} to {@code mainFileName}. */ public static boolean append(String mainFileName, String anotherFileName) { boolean rvalue = false; try { File tairgetFile = new File(mainFileName); File anotherFile = new File(anotherFileName); if (tairgetFile.exists() && tairgetFile.length()>0) { String tmpFileName = mainFileName + ".tmp"; //mainfile=vishal0 //another file=vishal1 //tmpfile=vishal0.tmp append(mainFileName, anotherFileName, tmpFileName); copyFile(tmpFileName, mainFileName); anotherFile.delete(); new File(tmpFileName).delete(); rvalue = true; } else if ( tairgetFile.createNewFile() ) { copyFile(anotherFileName, mainFileName); anotherFile.delete(); rvalue = true; } } catch (IOException e) { Log.e(TAG, "Append two mp4 files exception", e); } return rvalue; } public static void copyFile(final String from, final String destination) throws IOException { FileInputStream in = new FileInputStream(from); FileOutputStream out = new FileOutputStream(destination); copy(in, out); in.close(); out.close(); } public static void copy(FileInputStream in, FileOutputStream out) throws IOException { byte[] buf = new byte[FILE_BUFFER_SIZE]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } public static void append( final String firstFile, final String secondFile, final String newFile) throws IOException { final FileInputStream fisOne = new FileInputStream(new File(secondFile)); final FileInputStream fisTwo = new FileInputStream(new File(firstFile)); final FileOutputStream fos = new FileOutputStream(new File(String.format(newFile))); append(fisOne, fisTwo, fos); fisOne.close(); fisTwo.close(); fos.close(); } // FIXME remove deprecated code public static void append( final FileInputStream fisOne, final FileInputStream fisTwo, final FileOutputStream out) throws IOException { final Movie movieOne = MovieCreator.build(Channels.newChannel(fisOne)); final Movie movieTwo = MovieCreator.build(Channels.newChannel(fisTwo)); final Movie finalMovie = new Movie(); final List<Track> movieOneTracks = movieOne.getTracks(); final List<Track> movieTwoTracks = movieTwo.getTracks(); for (int i = 0; i <movieOneTracks.size() || i < movieTwoTracks.size(); ++i) { finalMovie.addTrack(new AppendTrack(movieTwoTracks.get(i), movieOneTracks.get(i))); } final IsoFile isoFile = new DefaultMp4Builder().build(finalMovie); isoFile.getBox(out.getChannel()); } } } public class Mp4PairserWrapper { public static final String TAG = Mp4PairserWrapper.class.getSimpleName(); public static final int FILE_BUFFER_SIZE = 1024; /** * Appends mp4 audio/video from {@code anotherFileName} to {@code mainFileName}. */ public static boolean append(String mainFileName, String anotherFileName) { boolean rvalue = false; try { File tairgetFile = new File(mainFileName); File anotherFile = new File(anotherFileName); if (tairgetFile.exists() && tairgetFile.length()>0) { String tmpFileName = mainFileName + ".tmp"; //mainfile=vishal0 //another file=vishal1 //tmpfile=vishal0.tmp append(mainFileName, anotherFileName, tmpFileName); copyFile(tmpFileName, mainFileName); anotherFile.delete(); new File(tmpFileName).delete(); rvalue = true; } else if ( tairgetFile.createNewFile() ) { copyFile(anotherFileName, mainFileName); anotherFile.delete(); rvalue = true; } } catch (IOException e) { Log.e(TAG, "Append two mp4 files exception", e); } return rvalue; } public static void copyFile(final String from, final String destination) throws IOException { FileInputStream in = new FileInputStream(from); FileOutputStream out = new FileOutputStream(destination); copy(in, out); in.close(); out.close(); } public static void copy(FileInputStream in, FileOutputStream out) throws IOException { byte[] buf = new byte[FILE_BUFFER_SIZE]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } public static void append( final String firstFile, final String secondFile, final String newFile) throws IOException { final FileInputStream fisOne = new FileInputStream(new File(secondFile)); final FileInputStream fisTwo = new FileInputStream(new File(firstFile)); final FileOutputStream fos = new FileOutputStream(new File(String.format(newFile))); append(fisOne, fisTwo, fos); fisOne.close(); fisTwo.close(); fos.close(); } // FIXME remove deprecated code public static void append( final FileInputStream fisOne, final FileInputStream fisTwo, final FileOutputStream out) throws IOException { final Movie movieOne = MovieCreator.build(Channels.newChannel(fisOne)); final Movie movieTwo = MovieCreator.build(Channels.newChannel(fisTwo)); final Movie finalMovie = new Movie(); final List<Track> movieOneTracks = movieOne.getTracks(); final List<Track> movieTwoTracks = movieTwo.getTracks(); for (int i = 0; i <movieOneTracks.size() || i < movieTwoTracks.size(); ++i) { finalMovie.addTrack(new AppendTrack(movieTwoTracks.get(i), movieOneTracks.get(i))); } final IsoFile isoFile = new DefaultMp4Builder().build(finalMovie); isoFile.getBox(out.getChannel()); } } fos.close (); public class Mp4PairserWrapper { public static final String TAG = Mp4PairserWrapper.class.getSimpleName(); public static final int FILE_BUFFER_SIZE = 1024; /** * Appends mp4 audio/video from {@code anotherFileName} to {@code mainFileName}. */ public static boolean append(String mainFileName, String anotherFileName) { boolean rvalue = false; try { File tairgetFile = new File(mainFileName); File anotherFile = new File(anotherFileName); if (tairgetFile.exists() && tairgetFile.length()>0) { String tmpFileName = mainFileName + ".tmp"; //mainfile=vishal0 //another file=vishal1 //tmpfile=vishal0.tmp append(mainFileName, anotherFileName, tmpFileName); copyFile(tmpFileName, mainFileName); anotherFile.delete(); new File(tmpFileName).delete(); rvalue = true; } else if ( tairgetFile.createNewFile() ) { copyFile(anotherFileName, mainFileName); anotherFile.delete(); rvalue = true; } } catch (IOException e) { Log.e(TAG, "Append two mp4 files exception", e); } return rvalue; } public static void copyFile(final String from, final String destination) throws IOException { FileInputStream in = new FileInputStream(from); FileOutputStream out = new FileOutputStream(destination); copy(in, out); in.close(); out.close(); } public static void copy(FileInputStream in, FileOutputStream out) throws IOException { byte[] buf = new byte[FILE_BUFFER_SIZE]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } public static void append( final String firstFile, final String secondFile, final String newFile) throws IOException { final FileInputStream fisOne = new FileInputStream(new File(secondFile)); final FileInputStream fisTwo = new FileInputStream(new File(firstFile)); final FileOutputStream fos = new FileOutputStream(new File(String.format(newFile))); append(fisOne, fisTwo, fos); fisOne.close(); fisTwo.close(); fos.close(); } // FIXME remove deprecated code public static void append( final FileInputStream fisOne, final FileInputStream fisTwo, final FileOutputStream out) throws IOException { final Movie movieOne = MovieCreator.build(Channels.newChannel(fisOne)); final Movie movieTwo = MovieCreator.build(Channels.newChannel(fisTwo)); final Movie finalMovie = new Movie(); final List<Track> movieOneTracks = movieOne.getTracks(); final List<Track> movieTwoTracks = movieTwo.getTracks(); for (int i = 0; i <movieOneTracks.size() || i < movieTwoTracks.size(); ++i) { finalMovie.addTrack(new AppendTrack(movieTwoTracks.get(i), movieOneTracks.get(i))); } final IsoFile isoFile = new DefaultMp4Builder().build(finalMovie); isoFile.getBox(out.getChannel()); } } } public class Mp4PairserWrapper { public static final String TAG = Mp4PairserWrapper.class.getSimpleName(); public static final int FILE_BUFFER_SIZE = 1024; /** * Appends mp4 audio/video from {@code anotherFileName} to {@code mainFileName}. */ public static boolean append(String mainFileName, String anotherFileName) { boolean rvalue = false; try { File tairgetFile = new File(mainFileName); File anotherFile = new File(anotherFileName); if (tairgetFile.exists() && tairgetFile.length()>0) { String tmpFileName = mainFileName + ".tmp"; //mainfile=vishal0 //another file=vishal1 //tmpfile=vishal0.tmp append(mainFileName, anotherFileName, tmpFileName); copyFile(tmpFileName, mainFileName); anotherFile.delete(); new File(tmpFileName).delete(); rvalue = true; } else if ( tairgetFile.createNewFile() ) { copyFile(anotherFileName, mainFileName); anotherFile.delete(); rvalue = true; } } catch (IOException e) { Log.e(TAG, "Append two mp4 files exception", e); } return rvalue; } public static void copyFile(final String from, final String destination) throws IOException { FileInputStream in = new FileInputStream(from); FileOutputStream out = new FileOutputStream(destination); copy(in, out); in.close(); out.close(); } public static void copy(FileInputStream in, FileOutputStream out) throws IOException { byte[] buf = new byte[FILE_BUFFER_SIZE]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } public static void append( final String firstFile, final String secondFile, final String newFile) throws IOException { final FileInputStream fisOne = new FileInputStream(new File(secondFile)); final FileInputStream fisTwo = new FileInputStream(new File(firstFile)); final FileOutputStream fos = new FileOutputStream(new File(String.format(newFile))); append(fisOne, fisTwo, fos); fisOne.close(); fisTwo.close(); fos.close(); } // FIXME remove deprecated code public static void append( final FileInputStream fisOne, final FileInputStream fisTwo, final FileOutputStream out) throws IOException { final Movie movieOne = MovieCreator.build(Channels.newChannel(fisOne)); final Movie movieTwo = MovieCreator.build(Channels.newChannel(fisTwo)); final Movie finalMovie = new Movie(); final List<Track> movieOneTracks = movieOne.getTracks(); final List<Track> movieTwoTracks = movieTwo.getTracks(); for (int i = 0; i <movieOneTracks.size() || i < movieTwoTracks.size(); ++i) { finalMovie.addTrack(new AppendTrack(movieTwoTracks.get(i), movieOneTracks.get(i))); } final IsoFile isoFile = new DefaultMp4Builder().build(finalMovie); isoFile.getBox(out.getChannel()); } } } public class Mp4PairserWrapper { public static final String TAG = Mp4PairserWrapper.class.getSimpleName(); public static final int FILE_BUFFER_SIZE = 1024; /** * Appends mp4 audio/video from {@code anotherFileName} to {@code mainFileName}. */ public static boolean append(String mainFileName, String anotherFileName) { boolean rvalue = false; try { File tairgetFile = new File(mainFileName); File anotherFile = new File(anotherFileName); if (tairgetFile.exists() && tairgetFile.length()>0) { String tmpFileName = mainFileName + ".tmp"; //mainfile=vishal0 //another file=vishal1 //tmpfile=vishal0.tmp append(mainFileName, anotherFileName, tmpFileName); copyFile(tmpFileName, mainFileName); anotherFile.delete(); new File(tmpFileName).delete(); rvalue = true; } else if ( tairgetFile.createNewFile() ) { copyFile(anotherFileName, mainFileName); anotherFile.delete(); rvalue = true; } } catch (IOException e) { Log.e(TAG, "Append two mp4 files exception", e); } return rvalue; } public static void copyFile(final String from, final String destination) throws IOException { FileInputStream in = new FileInputStream(from); FileOutputStream out = new FileOutputStream(destination); copy(in, out); in.close(); out.close(); } public static void copy(FileInputStream in, FileOutputStream out) throws IOException { byte[] buf = new byte[FILE_BUFFER_SIZE]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } public static void append( final String firstFile, final String secondFile, final String newFile) throws IOException { final FileInputStream fisOne = new FileInputStream(new File(secondFile)); final FileInputStream fisTwo = new FileInputStream(new File(firstFile)); final FileOutputStream fos = new FileOutputStream(new File(String.format(newFile))); append(fisOne, fisTwo, fos); fisOne.close(); fisTwo.close(); fos.close(); } // FIXME remove deprecated code public static void append( final FileInputStream fisOne, final FileInputStream fisTwo, final FileOutputStream out) throws IOException { final Movie movieOne = MovieCreator.build(Channels.newChannel(fisOne)); final Movie movieTwo = MovieCreator.build(Channels.newChannel(fisTwo)); final Movie finalMovie = new Movie(); final List<Track> movieOneTracks = movieOne.getTracks(); final List<Track> movieTwoTracks = movieTwo.getTracks(); for (int i = 0; i <movieOneTracks.size() || i < movieTwoTracks.size(); ++i) { finalMovie.addTrack(new AppendTrack(movieTwoTracks.get(i), movieOneTracks.get(i))); } final IsoFile isoFile = new DefaultMp4Builder().build(finalMovie); isoFile.getBox(out.getChannel()); } } } public class Mp4PairserWrapper { public static final String TAG = Mp4PairserWrapper.class.getSimpleName(); public static final int FILE_BUFFER_SIZE = 1024; /** * Appends mp4 audio/video from {@code anotherFileName} to {@code mainFileName}. */ public static boolean append(String mainFileName, String anotherFileName) { boolean rvalue = false; try { File tairgetFile = new File(mainFileName); File anotherFile = new File(anotherFileName); if (tairgetFile.exists() && tairgetFile.length()>0) { String tmpFileName = mainFileName + ".tmp"; //mainfile=vishal0 //another file=vishal1 //tmpfile=vishal0.tmp append(mainFileName, anotherFileName, tmpFileName); copyFile(tmpFileName, mainFileName); anotherFile.delete(); new File(tmpFileName).delete(); rvalue = true; } else if ( tairgetFile.createNewFile() ) { copyFile(anotherFileName, mainFileName); anotherFile.delete(); rvalue = true; } } catch (IOException e) { Log.e(TAG, "Append two mp4 files exception", e); } return rvalue; } public static void copyFile(final String from, final String destination) throws IOException { FileInputStream in = new FileInputStream(from); FileOutputStream out = new FileOutputStream(destination); copy(in, out); in.close(); out.close(); } public static void copy(FileInputStream in, FileOutputStream out) throws IOException { byte[] buf = new byte[FILE_BUFFER_SIZE]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } public static void append( final String firstFile, final String secondFile, final String newFile) throws IOException { final FileInputStream fisOne = new FileInputStream(new File(secondFile)); final FileInputStream fisTwo = new FileInputStream(new File(firstFile)); final FileOutputStream fos = new FileOutputStream(new File(String.format(newFile))); append(fisOne, fisTwo, fos); fisOne.close(); fisTwo.close(); fos.close(); } // FIXME remove deprecated code public static void append( final FileInputStream fisOne, final FileInputStream fisTwo, final FileOutputStream out) throws IOException { final Movie movieOne = MovieCreator.build(Channels.newChannel(fisOne)); final Movie movieTwo = MovieCreator.build(Channels.newChannel(fisTwo)); final Movie finalMovie = new Movie(); final List<Track> movieOneTracks = movieOne.getTracks(); final List<Track> movieTwoTracks = movieTwo.getTracks(); for (int i = 0; i <movieOneTracks.size() || i < movieTwoTracks.size(); ++i) { finalMovie.addTrack(new AppendTrack(movieTwoTracks.get(i), movieOneTracks.get(i))); } final IsoFile isoFile = new DefaultMp4Builder().build(finalMovie); isoFile.getBox(out.getChannel()); } } 

    E invoca com:

     Mp4PairserWrapper.append(firstfilename,secondfilename); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.