Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Converting a call center recording to something useful

    9 août 2018, par Abhay

    I have a call center recording (when played it sounds gibberish) for which the mediainfo shows info as

    ion@aurora:~/Inbound$ mediainfo 48401-3405-48403--18042018170000.wav 
    General
    Complete name                            : 48401-3405-48403--18042018170000.wav
    Format                                   : Wave
    File size                                : 327 KiB
    Duration                                 : 4mn 11s
    Overall bit rate                         : 10.7 Kbps
    
    Audio
    Format                                   : G.723.1
    Codec ID                                 : A100
    Duration                                 : 4mn 11s
    Bit rate                                 : 10.7 Kbps
    Channel(s)                               : 2 channels
    Sampling rate                            : 8 000 Hz
    Stream size                              : 327 KiB (100%)
    

    The ffmpeg info shows this as

    ion@aurora:~/Inbound$ ffmpeg -i 48401-3405-48403--18042018170000.wav
    ffmpeg version N-91330-ga990184 Copyright (c) 2000-2018 the FFmpeg developers
      built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609
      configuration: --prefix=/home/ion/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/ion/ffmpeg_build/include --extra-ldflags=-L/home/ion/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/ion/bin --enable-gpl --enable-libaom --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
      libavutil      56. 18.102 / 56. 18.102
      libavcodec     58. 20.103 / 58. 20.103
      libavformat    58. 17.100 / 58. 17.100
      libavdevice    58.  4.101 / 58.  4.101
      libavfilter     7. 25.100 /  7. 25.100
      libswscale      5.  2.100 /  5.  2.100
      libswresample   3.  2.100 /  3.  2.100
      libpostproc    55.  2.100 / 55.  2.100
    Input #0, wav, from '48401-3405-48403--18042018170000.wav':
      Duration: 00:04:11.37, bitrate: 10 kb/s
        Stream #0:0: Audio: g723_1 ([0][161][0][0] / 0xA100), 8000 Hz, mono, s16, 10 kb/s
    At least one output file must be specified
    

    So I converted this file to PCM using

    ffmpeg -acodec g723_1 -i 48401-3405-48403--18042018170000.wav -acodec pcm_s16le -f wav outnew1.wav
    

    But the audio still sound gibberish , I tried many variation and only Goldwave worked but that works on windows and with GUI not cli.

    So how can I convert this file to something useful so that atleast I can listen to it , It feels like a challenge now.

    Audio file : https://drive.google.com/open?id=1T54lKaI6IJmOqTPNOA_OkYRz89EQ5F2L

    PS : Use VLC to play audio file

  • Is it possible to stream multi framerate videos using MPEG-DASH ?

    9 août 2018, par Suresh Murali

    I transcoded a mp4 video to several framerates like 5FPS, 10FPS .. 30FPS and used MP4Box to segment them to play in DASH IF player.

    FFMPEG Command to generate multi framerate videos with same resolution:

    ffmpeg -i fball.mp4 -f mp4 -vcodec libx264 -profile:v high -vf scale=1280:-1 -b:v 2000k -minrate 2000k -maxrate 2000k -bufsize 2000k -nal-hrd cbr -g 120 -keyint_min 120 -r 60.0 -flags +cgop -sc_threshold 0 -pix_fmt yuv420p -threads 0 -x264opts keyint=120:min-keyint=120:sps-id=1 -an -y fball_720p_60fps.mp4

    ffmpeg -i fball.mp4 -f mp4 -vcodec libx264 -profile:v high -vf scale=1280:-1 -b:v 1000k -minrate 1000k -maxrate 1000k -bufsize 1000k -nal-hrd cbr -g 60 -keyint_min 60 -r 30.0 -flags +cgop -sc_threshold 0 -pix_fmt yuv420p -threads 0 -x264opts keyint=60:min-keyint=60:sps-id=1 -an -y fball_720p_30fps.mp4

    FFMPEG command to extract audio:

    ffmpeg -i fball.mp4 -acodec aac -b:a 128k -vn -strict -2 -y fball_audio.mp4

    MP4Box command for segmentation:

    MP4Box -frag 2000 -dash 2000 -rap -base-url ./segments/ -profile main -segment-name /segments/%s_ -out dash/fball_dash.mpd fball_720p_24fps.mp4 fball_720p_30fps.mp4 fball_720p_60fps.mp4 fball_audio.mp4

    1. Segment Duration: 2 seconds

    2. GOP length: segment duration x FPS of video

    3. Resolution: 720p for all videos

    Result is VIDEO DECODE error or stalls while switching framerate.

    Am I making any mistake while transcoding? Is it possible to stream Multi frame rate videos using MPEG DASH?

  • ffmpeg : recording audio + video into separate files, pressing 'q' or ctrl-C, audio is truncated

    9 août 2018, par zzzeek

    Trying to record from the camera and sound card at the same time. If I use the "-t" option with a fixed time, both streams come out fine. If I try to break out while it's recording, by pressing either 'q' or ctrl-C, the audio stream is cut typically 5 seconds short.

    I've tried many many options, codecs, -presets, combinations of everything, changing the order of the streams, usually with no luck. the thing that works the "best" is -preset ultrafast -threads 0, however I find when using these options, the program doesn't exit cleanly and I can't find documentation for what "-threads 0" really means (even though its name seems obvious).

    Here's the basic command:

    ffmpeg -y -f alsa -i default -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0 -map 0:a out.wav -map 1:v out.mkv

  • Code runs when in a main method but not when in another method

    8 août 2018, par Zubair Ahmed

    I created the setArtwork method to set the artwork of an aac file in an .m4a container and it does exactly what I want it to when I run the main method

    public static void setArtwork(File art, File m4a) throws Exception{
        Mp4TagReader reader = new Mp4TagReader();
        Mp4TagWriter writer = new Mp4TagWriter();
        RandomAccessFile song = new RandomAccessFile(m4a.toString(),"rw");
        Mp4Tag mp4tag = reader.read(song);
    
        Artwork artwork = ArtworkFactory.createArtworkFromFile(art);
        mp4tag.addField(artwork);
        mp4tag.setField(artwork);
    
        RandomAccessFile temp = new RandomAccessFile(m4a,"rw");
        writer.write(mp4tag,song,temp);
    }
    public static void main(String[] args) throws Exception{
        File art = new File("C:\\Users\\Zubair\\Documents\\music\\coverArt.jpeg");
        File m4a = new File("C:\\Users\\Zubair\\Documents\\music\\song.m4a");
        setArtwork(art,m4a);
    }
    

    BUT, when I try to use the setArtwork method in a different method in a different class it doesn't actually save the mp4 tag to the File. I did some debugging to see if the picture was even being added to the artwork tag and it all looks good, but it seems that the tag doesn't get written to the file.

    public static void mp3Tom4a(File mp3File, File m4aFolder, File coverArt) throws Exception {
        String input = mp3File.toString();
        String name = mp3File.getName();
    
        String output = name.substring(0,name.indexOf(MP3)) + M4A;
        output = m4aFolder.toString() + "\\" + output;
    
        //cd ffmpeg\bin && ffmpeg -y -i input.mp3 -an -vcodec copy cover.jpg && ffmpeg -y -i input.mp3 -c:a aac -b:a 192k -vn output.m4a
        ProcessBuilder builder = new ProcessBuilder(
                "cmd.exe","/c","cd ffmpeg\\bin && ffmpeg -y -i "
                + input +" -an -vcodec copy "+coverArt+
                " && ffmpeg -y -i " + input + " -c:a aac -b:a 128k -vn " + output);
        builder.redirectErrorStream(true);
        builder.start();
        JAudioData.setArtwork(coverArt,new File(output));
    }
    public static void main(String[] args) throws Exception {
        mp3Tom4a(new File("C:\\Users\\Zubair\\Documents\\music\\song.mp3"),
                new File("C:\\Users\\Zubair\\Documents\\music"),
                new File("C:\\Users\\Zubair\\Documents\\music\\coverArt.jpeg"));
    }
    

    it doesn't make sense that setArtwork only works when it's in the main method of its own class, especially because the objects I am using for the parameters are identical to eachother, so there should be no difference in the result. I think it might have something to do with the RandomAccessFile object being updated but the physical storage not getting updated

    Edit- If I comment out builder.start() then it can successfully write the mp4tag to the m4a file. But I don't see why having builder.start() would prevent that from happenning. My best guess is that because builder.start() is what creates song.m4a it is still being "edited" by that and can't be edited by any other processes.

  • how to use ffmpeg with mjpeg_vaapi encoder (with hardware acceleration) ?

    8 août 2018, par Marat

    When I use ffmpeg with mjpeg encoder without hardware acceleration, everything works fine. I use following command:

    ffmpeg -nostdin -rtsp_transport udp_multicast -allowed_media_types 'video' -i 'rtsp://MYIP' -ss 00:00:0.00 -f image2pipe -q:v 24 -vf scale=-2:480,format=yuv420p -c:v mjpeg -vframes 1 pipe:1
    

    But, when I try to use mjpeg with hardware acceleration, I always get error:

    ffmpeg -nostdin -rtsp_transport udp_multicast -allowed_media_types 'video' -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i 'rtsp://MYIP' -ss 00:00:0.00 -f image2pipe -q:v 24 -vf scale=-2:480,format=yuv420p -c:v mjpeg_vaapi -vframes 1 pipe:1
    ffmpeg version N-91514-gc51e0cd Copyright (c) 2000-2018 the FFmpeg developers
      built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609
      configuration: --pkg-config-flags=--static
      libavutil      56. 18.102 / 56. 18.102
      libavcodec     58. 21.106 / 58. 21.106
      libavformat    58. 17.101 / 58. 17.101
      libavdevice    58.  4.101 / 58.  4.101
      libavfilter     7. 26.100 /  7. 26.100
      libswscale      5.  2.100 /  5.  2.100
      libswresample   3.  2.100 /  3.  2.100
    libva info: VA-API version 0.39.0
    libva info: va_getDriverName() returns 0
    libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
    libva info: Found init function __vaDriverInit_0_39
    libva info: va_openDriver() returns 0
    Input #0, rtsp, from 'rtsp://MYIP':
      Metadata:
        title           : Session streamed with GStreamer
        comment         : rtsp-server
      Duration: N/A, start: 0.180600, bitrate: N/A
        Stream #0:0: Video: h264 (Main), yuvj420p(pc, progressive), 800x600, 50 fps, 50 tbr, 90k tbn, 100 tbc
    Stream mapping:
      Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (mjpeg_vaapi))
    Impossible to convert between the formats supported by the filter 'graph 0 input from stream 0:0' and the filter 'auto_scaler_0'
    Error reinitializing filters!
    Failed to inject frame into filter network: Function not implemented
    Error while processing the decoded data for stream #0:0
    Conversion failed!
    

    I tried with some additional options but it still keeps failing:

    ffmpeg -nostdin -rtsp_transport udp_multicast -allowed_media_types 'video' -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i 'rtsp://MYIP' -ss 00:00:0.00 -f image2pipe -q:v 24 -vf "scale_vaapi=w=800:h=600" -b:v 700k -r 25 -vcodec mjpeg_vaapi -vframes 1 pipe:1                
    ffmpeg version N-91514-gc51e0cd Copyright (c) 2000-2018 the FFmpeg developers
      built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609
      configuration: --pkg-config-flags=--static
      libavutil      56. 18.102 / 56. 18.102
      libavcodec     58. 21.106 / 58. 21.106
      libavformat    58. 17.101 / 58. 17.101
      libavdevice    58.  4.101 / 58.  4.101
      libavfilter     7. 26.100 /  7. 26.100
      libswscale      5.  2.100 /  5.  2.100
      libswresample   3.  2.100 /  3.  2.100
    libva info: VA-API version 0.39.0
    libva info: va_getDriverName() returns 0
    libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
    libva info: Found init function __vaDriverInit_0_39
    libva info: va_openDriver() returns 0
    Input #0, rtsp, from 'rtsp://MYIP':
      Metadata:
        title           : Session streamed with GStreamer
        comment         : rtsp-server
      Duration: N/A, start: 0.179933, bitrate: N/A
        Stream #0:0: Video: h264 (Main), yuvj420p(pc, progressive), 800x600, 50 fps, 50 tbr, 90k tbn, 100 tbc
    Stream mapping:
      Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (mjpeg_vaapi))
    [mjpeg_vaapi @ 0x374cd80] Encoding entrypoint not found (12 / 7).
    Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
    Conversion failed!
    

    Can please anyone suggest right options to make it work?