Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Using ffmpeg in a script to detect and fix mp3 with sample rate != 44.1k

    22 juin 2017, par Mike123456

    I only want to touch files that aren't 44.1 (as mp3 is lossy, so re-encoding/resampling files that dont needed to be touched is t good)

    I have started playing with ffprobe (assuming this is the best way?), but got stuck with the syntax. Using:

     ffprobe -show_streams -select_streams a format=sample_rate -of default=noprint_wrappers=1:nokey=1 myfile.mp3
    

    Its not happy with this syntax, saying "myfile.mp3 provided as input filename, but 'format=sample_rate' was already specified."

    Is there a better way to achieve this? If not, can someone help me with my ffmpeg probe syntax?

  • Add image to video using ffmpeg , the output file can't be played

    22 juin 2017, par StevenChen

    I need to watermark a mp4 video , but it is not working , It has bothered me for a week,please help me here is my code:

    ffmpeg -i sss01.mp4 -i watermark.png -filter_complex "[0:v][1:v] overlay=10:10" -pix_fmt yuv420p -c:a copy output.mp4
    

    ****This command was executed successfully ,but The size of output.mp4 only is 50kb and it cann't play. the command detail:****

    >  ffmpeg -i sss01.mp4 -i watermark.png -filter_complex "[0:v][1:v] overlay=10:10" -pix_fmt yuv420p -c:a copy output.mp4  
     ffmpeg version git-2017-06-08-a3b5b60 Copyright (c) 2000-2017 the FFmpeg developers  
      built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-18)  
      configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --extra-libs=-ldl --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-openssl  
      libavutil      55. 63.100 / 55. 63.100  
      libavcodec     57. 96.101 / 57. 96.101  
      libavformat    57. 72.101 / 57. 72.101  
      libavdevice    57.  7.100 / 57.  7.100  
      libavfilter     6. 91.100 /  6. 91.100  
      libswscale      4.  7.101 /  4.  7.101  
      libswresample   2.  8.100 /  2.  8.100  
      libpostproc    54.  6.100 / 54.  6.100  
    Input #0, png_pipe, from 'watermark.png':  
      Duration: N/A, bitrate: N/A  
        Stream #0:0: Video: png, rgba(pc), 215x115 [SAR 2835:2835 DAR 43:23], 25 tbr, 25 tbn, 25 tbc  
    Invalid file index 1 in filtergraph description [0:v][1:v] overlay=10:10.  
    [root@localhost wwwroot]# ffmpeg -i sss01.mp4 -i watermark.png -filter_complex "[0:v][1:v] overlay=10:10" -pix_fmt yuv420p -c:a copy output.mp4  
    ffmpeg version git-2017-06-08-a3b5b60 Copyright (c) 2000-2017 the FFmpeg developers  
      built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-18)  
      configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --extra-libs=-ldl --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-openssl  
      libavutil      55. 63.100 / 55. 63.100  
      libavcodec     57. 96.101 / 57. 96.101  
      libavformat    57. 72.101 / 57. 72.101  
      libavdevice    57.  7.100 / 57.  7.100  
      libavfilter     6. 91.100 /  6. 91.100  
      libswscale      4.  7.101 /  4.  7.101  
      libswresample   2.  8.100 /  2.  8.100  
      libpostproc    54.  6.100 / 54.  6.100  
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'sss01.mp4':  
      Metadata:  
        major_brand     : isom  
        minor_version   : 512  
        compatible_brands: isomiso2avc1mp41  
        encoder         : Lavf57.72.101  
      Duration: 00:03:09.80, start: 0.000000, bitrate: 1547 kb/s  
        Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 1416 kb/s, 24 fps, 24 tbr, 90k tbn, 48 tbc (default)  
        Metadata:  
          handler_name    : VideoHandler  
        Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)  
        Metadata:  
          handler_name    : SoundHandler  
        Stream #0:2(eng): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)  
        Metadata:  
          handler_name    : SubtitleHandler  
    Input #1, png_pipe, from 'watermark.png':  
      Duration: N/A, bitrate: N/A  
        Stream #1:0: Video: png, rgba(pc), 215x115 [SAR 2835:2835 DAR 43:23], 25 tbr, 25 tbn, 25 tbc  
    File 'output.mp4' already exists. Overwrite ? [y/N] y  
    Stream mapping:  
      Stream #0:0 (h264) -> overlay:main  
      Stream #1:0 (png) -> overlay:overlay  
      overlay -> Stream #0:0 (libx264)  
      Stream #0:1 -> #0:1 (copy)  
    Press [q] to stop, [?] for help  
    [libx264 @ 0xb4ee7e0] using SAR=1/1  
    [libx264 @ 0xb4ee7e0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2  
    [libx264 @ 0xb4ee7e0] profile High, level 4.0  
    [libx264 @ 0xb4ee7e0] 264 - core 150 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00  
    Output #0, mp4, to 'output.mp4':  
      Metadata:  
        major_brand     : isom  
        minor_version   : 512  
        compatible_brands: isomiso2avc1mp41  
        encoder         : Lavf57.72.101  
        Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 24 fps, 12288 tbn, 24 tbc (default)  
        Metadata:  
          encoder         : Lavc57.96.101 libx264  
        Side data:  
          cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1  
        Stream #0:1(und): Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 125 kb/s (default)  
        Metadata:  
          handler_name    : SoundHandler  
    frame=   20 fps=0.0 q=0.0 size=       0kB time=00:00:00.81 bitrate=   0.0kbits/sframe=   30 fps= 29 q=0.0 size=       0kB time=00:00:01.23 bitrate=   0.0kbits/sframe=   37 fps= 23 q=0.0 size=       0kB time=00:00:01.50 bitrate=   0.0kbits/sframe=   42 fps= 11 q=28.0 size=      40kB time=00:00:01.71 bitrate= 190.6kbits/frame=   44 fps= 10 q=28.0 size=      46kB time=00:00:01.81 bitrate= 210.2kbits/Killedd=0.41x  
    
  • Random error "Failed to update header with correct duration."

    22 juin 2017, par RMS

    I have a bash script that triggers a ffmpeg command, the loop strangely doesn't start again after the error below randomly occurs :

    Failed to update header with correct duration.
    Failed to update header with correct filesize.
    

    I looked up everywhere, no luck. I dont mind the error, just why won't the bash loop work correctly and relaunch the command ?

    I am running a nginx server where I push the stream to, here is the script:

    #!/bin/bash
    
    until ffmpeg -thread_queue_size 512 -re -I "external URL" -vcodec copy -vprofile baseline -acodec aac -strict -2 -f flv "nginx URL"; do
        echo "restarting ffmpeg command"
        sleep 1
    done 
    

    Thank you !

  • ffmpeg rtmp publish error Broken pipe

    22 juin 2017, par Forrest Yu

    I use ffmpeg push RTMP stream. it was successful that the server is locally,
    but when the server is not locally ,it is wrong. The mistake is Broken pipe.
    av_interleaved_write_frame() --> ffmpeg error : Broken pipe.
    Could anyone tell me why? tks.

  • batch store %%f as variable

    22 juin 2017, par RyanMe321

    I've been trying to use %%f to operate a script on each file in a directory however however when referencing it through the script the %%f and %%~nf don't seem to be working. I've limited programming experience I'm trying to make a more useful version of this video formatting tutorial.

    So I'd like to store %%f and %%~nf as variables to reference for the rest of the script though I can't work out how.

    @echo off
    set /p FORMAT="Enter File Format: "
    FOR %%f IN (*.%FORMAT%) DO  echo %%f
    set TEST=%%f
    echo %TEST%
    cmd/k
    

    If I could store these it would resolve my issue, however this is the longer form of what I'm trying to do, this script works if I have the user enter the file manually into a variable (%VIDEO%=%%f and %~nf). Though this is far from ideal.

    @echo off
    set /p FORMAT="Enter File Format: "
    
    FOR %%f IN (*.%FORMAT%) DO (
    ::IDFILE
    for /F "delims=" %%I in ('C:\ffmpeg\bin\ffprobe.exe -v error -show_entries format^=filename -of default^=noprint_wrappers^=1:nokey^=1 "%%f"') do set "FILENAME=%%I"
    
    for /F "delims=" %%I in ('C:\ffmpeg\bin\ffprobe.exe -v error -select_streams v:0 -show_entries stream^=codec_name -of default^=noprint_wrappers^=1:nokey^=1 "%%f"') do set "Vcodec=%%I"
    
    for /F "delims=" %%I in ('C:\ffmpeg\bin\ffprobe.exe -v error -select_streams a:0 -show_entries stream^=codec_name -of default^=noprint_wrappers^=1:nokey^=1 "%%f"') do set "Acodec=%%I"
    
    echo %FILENAME% is using %Vcodec% and %Acodec% codecs
    
    if %Vcodec% == h264 (echo DO NOT CONVERT VIDEO) else (echo CONVERT VIDEO) 
    if %Acodec% == ac3 (echo DO NOT CONVERT AUDIO) else (echo CONVERT AUDIO)
    timeout /t 5
    
    :: COPY V FIX A
    if %Vcodec% == h264 if not %Acodec% == ac3 (echo Copying Video, Converting Audio
    timeout /t 5
    C:\ffmpeg\bin\ffmpeg.exe -i "%%f" -map 0 -vcodec copy -scodec copy -acodec ac3 -b:a 640K "%%~nf"-AC3.mkv)
    
    :: FIX V COPY A
    if not %Vcodec% == h264 if  %Acodec% == ac3 (echo Converting Video, Copying Audio
    timeout /t 5
    C:\ffmpeg\bin\ffmpeg.exe -i "%%f" -map 0 -vcodec libx264 -scodec copy -acodec copy "%%~nf-"h264.mkv)
    
    :: FIX V FIX A
    if not %Vcodec% == h264 if not %Acodec% == ac3 (echo Converting Video, Converting Audio
    timeout /t 5
    C:\ffmpeg\bin\ffmpeg.exe -i "%%f" -map 0 -vcodec libx264 -scodec copy -acodec ac3 -b:a 640K "%%~nf"-h264-AC3.mkv)
    
    :: COPY V COPY A
    if %Vcodec% == h264 if %Acodec% == ac3 (echo "Doesn't require any Conversion")
    )
    pause
    cmd/k