Newest 'ffmpeg' Questions - Stack Overflow

http://stackoverflow.com/questions/tagged/ffmpeg

Les articles publiés sur le site

  • ffmpeg command running stand alone but not from a linux script

    31 mai 2016, par user1490563

    i made a simple script that breaks a flv file into multiple parts, convert them all to .mp4 individually and then merge all of them to form a final mp4 file. i did this to save time and convert large files in parallel.

    however, i am stuck because the command that normally run on command line for ffmpeg, dont run via script.

    I am kind of stuck here and will like to have some assistance.

    #!/bin/bash
    
    
    #sleep 5
    
    
    filenametmp=$1;
    
    filename=`echo "$filenametmp" | awk '{split($0,a,"."); print a[1]}'`
    
    
    echo $filename
    
    output="$filename-output"
    
    filenamewithoutpath=`echo "$output" | awk '{split($0,a,"/"); print a[4]}'`
    
    echo $output $filenamewithoutpath
    
    /usr/bin/ffmpeg -i $filenametmp -c copy -map 0 -segment_time $2 -f segment $output%01d.flv
    
    #sleep 10
    
    
    #echo "/bin/ls -lrt /root/storage/ | /bin/grep $filenamewithoutpath | /usr/bin/wc -l"
    filecounttmp=`/bin/ls -lrt /opt/storage/ | /bin/grep $filenamewithoutpath | /usr/bin/wc -l`
    
    filecount=`expr $filecounttmp - 1`
    
    echo $filecount
    
    for i in `seq 0 $filecount`
    do
    
    
    suffix=`expr 0000 + $i`
    
    filenametoconvert="$output$suffix.flv"
    convertedfilename="$output$suffix.mp4"
    echo $filenametoconvert
    
    /usr/bin/ffmpeg -i $filenametoconvert -c:v libx264 -crf 23 -preset medium -vsync 1 -r 25 -c:a aac -strict -2 -b:a 64k -ar 44100 -ac 1 $convertedfilename > /dev/null 2>&1 &
    
    
    done
    
    
    
    
    
    sleep 5
    
    concatstring=""
    
    for j in `seq 0 $filecount`
    do
    
    
    suffix=`expr 0000 + $j`
    
    convertedfilenamemp4="$output$suffix.mp4"
    
    #concatstring=`concat:$concatstring|$convertedfilenamemp4`
    
    echo "file" $convertedfilenamemp4 >> $filename.txt
    
    #ffmpeg -i concat:"$concatstring" -codec copy $filename.mp4
    
    #ffmpeg -f concat -i $filename.txt -c copy $filename.mp4
    
    
    done
    
    echo $concatstring
    
    ffmpeg -f concat -i $filename.txt -c copy $filename.mp4
    
    
    rm $output*
    rm $filename.txt
    

    following is how to run this on any flv file

    ./ff.sh /opt/storage/tttttssssssssss_573f5b1cd473202daf2bf694.flv 20

    Any help will be appreciated and any input required will be given.

    I am on Ubuntu 14.04 LTS version. Standard installation of ffmpeg.

  • How to add creation complete event after converting wav format to mp3 format using ffmpeg in Actionscript 3 ?

    31 mai 2016, par Ashish

    I am using the following codes to convert wav file format to mp3 file format using ffmpeg :

    private var info:NativeProcessStartupInfo = new NativeProcessStartupInfo();
    private var originalAudio:String = "C:\Users\User_Name\Desktop\test.wav";
    info.executable = File.applicationDirectory.resolvePath("assets\\nativefiles\\ffmpeg.exe");
    private var args: Vector. = new Vector.();
    args.push("-i", originalAudio, "-vn", "-ar", "44100", "-ac", "2", "-ab", "192", "-acodec", "libmp3lame", "-f", "mp3", (tempDir.nativePath + '\\' + audioId + '.mp3'));
    info.arguments = args;
    private var nativeProcess:NativeProcess = new NativeProcess();
    nativeProcess.start(info);
    nativeProcess.addEventListener(Event.COMPLETE , onComplete);
    
    protected function onComplete(event:Event):void
    {
        trace("Conversion Completed");
    }
    

    But problem is that I am unable to trace the complete event control after file conversion. I have already added a complete event on nativeprocess (i.e nativeProcess.addEventListener(Event.COMPLETE , onComplete); but the control not coming in to the function onComplete after conversion.

    So any body have an idea why the control not coming into the function or how to add event listener to trace complete event function.

  • How to compile FFmpeg-3.0.2+ Library for Android ?

    30 mai 2016, par Timo Schuck

    Struggling with many errors and deprecated folder and file architectures with the new Android NDK 11+ and FFmpeg-3.0.2+ on how to compile that Library for all Android Architecutres on Ubuntu (or Windows).

    There seems to be no up-to-date docu or tutorial without outdated links or build-scripts to bring that to work.

  • Slow Video rotation in FFMPEG

    30 mai 2016, par lalitsharma1607

    I am using Ffmpeg4Android library to encode videos. I want to merge videos by selecting them. The problem I faced is if a select portrait videos, the produced video has the rotated videos. To resolve this issue I am rotating the video based on its rotation metadata then I am executing merge command. It is taking too long approx 3-5 minutes for 10 sec HD video. Please suggest me the faster way..

    Rotation command:

    String[] cmd= new String[]{"ffmpeg", "-y", "-i", orginalFilePath, "-strict", "experimental", "-vf", "transpose=" + transposeby, newFilePath}; 
    

    //transposeby=1 for 90degree cw

    Merge Command:

    String[] command = new String[]{"ffmpeg", "-y", "-i", files[0], "-i", files[1], "-strict", "experimental",
                        "-filter_complex", "[0:v]scale=640x480,setsar=1:1[v0];[1:v]scale=640x480,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1",
                        "-ab", "48000", "-ac", "2", "-ar", "22050", "-s", "640x480", "-r", "30", "-vcodec", "mpeg4", "-b", "2097k", newFilePath};
    
  • Decompressing time-To-Sample table (STTS) in an MP4 file

    30 mai 2016, par man-r

    i have an mp4 video byte array and i need to generate a thumbnail for it using its middle frame (e.g. if the video length is 10 seconds then i need to get the picture from 5th second).

    i managed to parse through the file and extract its boxes (atom). i have also managed to get the video length from the mvhd box. also i managed to extract 1. the time-To-Sample table from stts box, 2. the sample-To-Chunk table from stcs box, 3. the chunk-Offset table from stco box, 4. the sample Size table from stsz box, 5. the Sync Sample table from stss box

    i know that all the actual media are available in the mdat box and that i need to correlate the above table to find the exact frame offset in the file but my question is how? the tables data seems to be compressed (specially the time-To-Sample table) but i don't know how decompress them.

    any help is appreciated.

    below are code samples

    code to convert byte to hex

    public static char[] bytesToHex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];
        for ( int j = 0; j < bytes.length; j++ ) {
            int v = bytes[j] & 0xFF;
    
            hexChars[j * 2] = hexArray[v >>> 4];
            hexChars[j * 2 + 1] = hexArray[v & 0x0F];            
        }
        return hexChars;
    }
    

    code for getting the box offset

    final static String MOOV                          = "6D6F6F76";
    final static String MOOV_MVHD                     = "6D766864";
    final static String MOOV_TRAK                     = "7472616B";
    final static String MOOV_TRAK_MDIA                = "6D646961";
    final static String MOOV_TRAK_MDIA_MINF           = "6D696E66";
    final static String MOOV_TRAK_MDIA_MINF_STBL      = "7374626C";
    final static String MOOV_TRAK_MDIA_MINF_STBL_STSD = "73747364";
    final static String MOOV_TRAK_MDIA_MINF_STBL_STTS = "73747473";
    final static String MOOV_TRAK_MDIA_MINF_STBL_STSS = "73747373";
    final static String MOOV_TRAK_MDIA_MINF_STBL_STSC = "73747363";
    final static String MOOV_TRAK_MDIA_MINF_STBL_STCO = "7374636F";
    final static String MOOV_TRAK_MDIA_MINF_STBL_STSZ = "7374737A";
    
    static int getBox(char[] s, int offset, String type) {
        int typeOffset = -1;
        for (int i = offset*2; i-1) {
                    break;
                } 
            }
            i+=(size*2);
        }
    
        return typeOffset;
    }
    

    code for getting the duration and timescale

    static int[] getDuration(char[] s) {
        int mvhdOffset = getBox(s, 0, MOOV_MVHD);
        int timeScaleStart = (mvhdOffset*2) + (4 + 4 + 1 + 3 + 4 + 4)*2;
        int timeScaleEnd   = (mvhdOffset*2) + (4 + 4 + 1 + 3 + 4 + 4 + 4)*2;
    
        int durationStart  = (mvhdOffset*2) + (4 + 4 + 1 + 3 + 4 + 4 + 4)*2;
        int durationEnd    = (mvhdOffset*2) + (4 + 4 + 1 + 3 + 4 + 4 + 4 + 4)*2;
    
        String timeScaleHex = new String(Arrays.copyOfRange(s, timeScaleStart, timeScaleEnd));
        String durationHex = new String(Arrays.copyOfRange(s, durationStart, durationEnd));
    
        int timeScale = Integer.parseInt(timeScaleHex, 16);
        int duration = Integer.parseInt(durationHex, 16);
    
        int[] result = {duration, timeScale};
        return result;
    }
    

    code to get the time-To-Sample table

    static int[][] getTimeToSampleTable(char[] s, int trakOffset) {
        int offset = getBox(s, trakOffset, MOOV_TRAK_MDIA_MINF_STBL_STTS);
        int sizeStart = offset*2;
        int sizeEnd   = offset*2 + (4)*2;
    
        int typeStart = offset*2 + (4)*2;
        int typeEnd   = offset*2 + (4 + 4)*2;
    
        int noOfEntriesStart = offset*2 + (4 + 4 + 1 + 3)*2;
        int noOfEntriesEnd   = offset*2 + (4 + 4 + 1 + 3 + 4)*2;
    
        String sizeHex = new String(Arrays.copyOfRange(s, sizeStart, sizeEnd));
        String typeHex = new String(Arrays.copyOfRange(s, typeStart, typeEnd));
        String noOfEntriesHex = new String(Arrays.copyOfRange(s, noOfEntriesStart, noOfEntriesEnd));
    
        int size = Integer.parseInt(sizeHex, 16);
        int noOfEntries = Integer.parseInt(noOfEntriesHex, 16);
    
        int[][] timeToSampleTable = new int[noOfEntries][2];
    
        for (int i = 0; icode>