Newest 'ffmpeg' Questions - Stack Overflow

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

Articles published on the website

  • How do I make Ffmpeg work for subtitles in flutter?

    19 July, by Mohammed Bekele

    I'm trying to burn subtitles in a video. I'm going to show you the manual command I used:

    String newCmd =
              '-i /storage/emulated/0/ffmpeg/video.avi -vf subtitles=\'/storage/emulated/0/ffmpeg/caption.srt\':force_style=\'Fontsize=24\' /storage/emulated/0/ffmpeg/apt.mp4';
          
    

    When I use the above command it just fail, but the following code works.

     String newCmd =
              '-i /storage/emulated/0/ffmpeg/video.avi /storage/emulated/0/ffmpeg/apt.mp4';
    

    When I run ffmpeg on my pc this is the command

    ffmpeg -i F:\ffmpeg\video.avi -vf subtitles='F\:\\ffmpeg\\caption.srt':force_style='Fontsize=24' F:\ffmpeg\new.mp4
    

    So when using in subtitles we need to provide extra backslashes to the paths. So does this mean Flutter expects the same? Or should I have to include a font file to it?

    I'm using ffmpeg_kit_flutter package.

  • Piping yt_dlp to FFMPEG using python: ffmpeg failing to recognize video data from pipe

    19 July, by ThePrince

    I am trying to pipe the output of yt_dlp into a pipe used by ffmpeg which then outputs.:

    def pipe_function(url):
    
    ydl_command = [
        'yt-dlp', '-f', 'bestvideo+bestaudio', '--quiet', '--no-warnings', '-o', '-', url
    ]
    
    
    ffmpeg_command = [
        'ffmpeg', '-v', 'debug', '-i', '-', '-c', 'copy', 'output.mp4'
    ]
    
    
    # Start yt-dlp process
    ydl_process = subprocess.Popen(
        ydl_command,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE
    )
    
    
    # Start ffmpeg process and pipe output from yt-dlp to ffmpeg
    ffmpeg_process = subprocess.Popen(
        ffmpeg_command,
        stdin=ydl_process.stdout,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE
    )
    
    
    
    ydl_stdout, ydl_stderr = ydl_process.communicate()
    
    
    try:
        print(ydl_stdout[:100].decode('utf-8'))
    except UnicodeDecodeError:
        print(ydl_stdout[:100].decode('latin-1', errors='ignore'))
    
    ffmpeg_stdout, ffmpeg_stderr = ffmpeg_process.communicate()
    
    
    if ydl_stderr:
        try:
            print("error in yt-dlp: ", ydl_stderr.decode('utf-8'))
        except UnicodeDecodeError:
            print("decode error in yt-dlp: ", ydl_stderr)
    
    if ffmpeg_stderr:
        try:
            print("error in ffmpeg: ", ffmpeg_stderr.decode('utf-8'))
        except UnicodeDecodeError:
            print("decode error in ffmpeg: ", ffmpeg_stderr)
    
    
    try:
        print(ffmpeg_stdout[:100].decode('utf-8'))
    except UnicodeDecodeError:
        print(ffmpeg_stdout[:100].decode('latin-1', errors='ignore'))
    
    return ffmpeg_stdout
    

    This outputs an audio file. If I look at the console I see some messages. I have removed the lengthier stuff and shown only what I find the most interesting:

    [mpegts @ 0000021b8576a380] probing stream 0 pp:1457
    [mpegts @ 0000021b8576a380] probed stream 0
    [mpegts @ 0000021b8576a380] parser not found for codec bin_data, packets or times may be invalid.
    For transform of length 120, inverse, mdct_float, flags: [aligned, out_of_place], found 6 matches:
        1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
        2: mdct_pfa_15xM_inv_float_c - type: mdct_float, len: [30, ∞], factors[2]: [15, any], flags: [unaligned, out_of_place, inv_only], prio: 304
        3: mdct_pfa_5xM_inv_float_c - type: mdct_float, len: [10, ∞], factors[2]: [5, any], flags: [unaligned, out_of_place, inv_only], prio: 144
        4: mdct_pfa_3xM_inv_float_c - type: mdct_float, len: [6, ∞], factors[2]: [3, any], flags: [unaligned, out_of_place, inv_only], prio: 112
        5: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
        6: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
    For transform of length 60, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 1 matches:
        1: fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: [60, ∞], factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 688
    For transform of length 4, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 1 matches:
        1: fft4_fwd_asm_float_sse2 - type: fft_float, len: 4, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 352
    Transform tree:
        mdct_inv_float_avx2 - type: mdct_float, len: 120, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
            fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: 60, factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call]
                fft4_fwd_asm_float_sse2 - type: fft_float, len: 4, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
    For transform of length 128, inverse, mdct_float, flags: [aligned, out_of_place], found 3 matches:
        1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
        2: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
        3: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
    For transform of length 64, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 3 matches:
        1: fft_sr_asm_float_avx2 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 480
        2: fft_sr_asm_float_fma3 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 448
        3: fft_sr_asm_float_avx - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 416
    Transform tree:
        mdct_inv_float_avx2 - type: mdct_float, len: 128, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
            fft_sr_asm_float_avx2 - type: fft_float, len: 64, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
    For transform of length 480, inverse, mdct_float, flags: [aligned, out_of_place], found 6 matches:
        1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
        2: mdct_pfa_15xM_inv_float_c - type: mdct_float, len: [30, ∞], factors[2]: [15, any], flags: [unaligned, out_of_place, inv_only], prio: 304
        3: mdct_pfa_5xM_inv_float_c - type: mdct_float, len: [10, ∞], factors[2]: [5, any], flags: [unaligned, out_of_place, inv_only], prio: 144
        4: mdct_pfa_3xM_inv_float_c - type: mdct_float, len: [6, ∞], factors[2]: [3, any], flags: [unaligned, out_of_place, inv_only], prio: 112
        5: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
        6: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
    For transform of length 240, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 1 matches:
        1: fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: [60, ∞], factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 688
    For transform of length 16, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 2 matches:
        1: fft16_asm_float_fma3 - type: fft_float, len: 16, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 512
        2: fft16_asm_float_avx - type: fft_float, len: 16, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 480
    Transform tree:
        mdct_inv_float_avx2 - type: mdct_float, len: 480, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
            fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: 240, factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call]
                fft16_asm_float_fma3 - type: fft_float, len: 16, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
    For transform of length 512, inverse, mdct_float, flags: [aligned, out_of_place], found 3 matches:
        1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
        2: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
        3: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
    For transform of length 256, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 3 matches:
        1: fft_sr_asm_float_avx2 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 480
        2: fft_sr_asm_float_fma3 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 448
        3: fft_sr_asm_float_avx - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 416
    Transform tree:
        mdct_inv_float_avx2 - type: mdct_float, len: 512, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
            fft_sr_asm_float_avx2 - type: fft_float, len: 256, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
    For transform of length 960, inverse, mdct_float, flags: [aligned, out_of_place], found 6 matches:
        1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
        2: mdct_pfa_15xM_inv_float_c - type: mdct_float, len: [30, ∞], factors[2]: [15, any], flags: [unaligned, out_of_place, inv_only], prio: 304
        3: mdct_pfa_5xM_inv_float_c - type: mdct_float, len: [10, ∞], factors[2]: [5, any], flags: [unaligned, out_of_place, inv_only], prio: 144
        4: mdct_pfa_3xM_inv_float_c - type: mdct_float, len: [6, ∞], factors[2]: [3, any], flags: [unaligned, out_of_place, inv_only], prio: 112
        5: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
        6: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
    For transform of length 480, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 1 matches:
        1: fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: [60, ∞], factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 688
    For transform of length 32, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 2 matches:
        1: fft32_asm_float_fma3 - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 512
        2: fft32_asm_float_avx - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 480
    Transform tree:
        mdct_inv_float_avx2 - type: mdct_float, len: 960, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
            fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: 480, factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call]
                fft32_asm_float_fma3 - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
    For transform of length 1024, inverse, mdct_float, flags: [aligned, out_of_place], found 3 matches:
        1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
        2: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
        3: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
    For transform of length 512, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 3 matches:
        1: fft_sr_asm_float_avx2 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 480
        2: fft_sr_asm_float_fma3 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 448
        3: fft_sr_asm_float_avx - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 416
    Transform tree:
        mdct_inv_float_avx2 - type: mdct_float, len: 1024, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
            fft_sr_asm_float_avx2 - type: fft_float, len: 512, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
    For transform of length 1024, forward, mdct_float, flags: [aligned, out_of_place], found 2 matches:
        1: mdct_fwd_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, fwd_only], prio: 96
        2: mdct_naive_fwd_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, fwd_only], prio: -130976
    For transform of length 512, forward, fft_float, flags: [aligned, inplace, preshuf], found 5 matches:
        1: fft_sr_ns_float_avx2 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf], prio: 480
        2: fft_sr_ns_float_fma3 - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf], prio: 448
        3: fft_sr_ns_float_avx - type: fft_float, len: [64, 131072], factor: 2, flags: [aligned, inplace, out_of_place, preshuf], prio: 416
        4: fft_pfa_ns_float_c - type: fft_float, len: [6, ∞], factors[2]: [7, 5, 3, 2, any], flags: [unaligned, inplace, out_of_place, preshuf], prio: 112
        5: fft512_ns_float_c - type: fft_float, len: 512, factor: 2, flags: [unaligned, inplace, out_of_place, preshuf], prio: 96
    Transform tree:
        mdct_fwd_float_c - type: mdct_float, len: 1024, factors[2]: [2, any], flags: [unaligned, out_of_place, fwd_only]
            fft_sr_ns_float_avx2 - type: fft_float, len: 512, factor: 2, flags: [aligned, inplace, out_of_place, preshuf]
    For transform of length 64, inverse, mdct_float, flags: [aligned, out_of_place], found 3 matches:
        1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
        2: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
        3: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
    For transform of length 32, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 2 matches:
        1: fft32_asm_float_fma3 - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 512
        2: fft32_asm_float_avx - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 480
    Transform tree:
        mdct_inv_float_avx2 - type: mdct_float, len: 64, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
            fft32_asm_float_fma3 - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
    For transform of length 64, inverse, mdct_float, flags: [aligned, out_of_place], found 3 matches:
        1: mdct_inv_float_avx2 - type: mdct_float, len: [16, ∞], factors[2]: [2, any], flags: [aligned, out_of_place, inv_only], prio: 544
        2: mdct_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: 96
        3: mdct_naive_inv_float_c - type: mdct_float, len: [2, ∞], factors[2]: [2, any], flags: [unaligned, out_of_place, inv_only], prio: -130976
    For transform of length 32, inverse, fft_float, flags: [aligned, inplace, preshuf, asm_call], found 2 matches:
        1: fft32_asm_float_fma3 - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 512
        2: fft32_asm_float_avx - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call], prio: 480
    Transform tree:
        mdct_inv_float_avx2 - type: mdct_float, len: 64, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
            fft32_asm_float_fma3 - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
    [mpegts @ 0000021b8576a380] max_analyze_duration 5000000 reached at 5005000 microseconds st:0
    [mpegts @ 0000021b8576a380] After avformat_find_stream_info() pos: 5403308 bytes read:5404624 seeks:0 frames:365
    Input #0, mpegts, from 'fd:':
      Duration: N/A, start: 1.400000, bitrate: 130 kb/s
      Program 1
        Metadata:
          service_name    : Service01
          service_provider: FFmpeg
      Stream #0:0[0x100], 152, 1/90000: Data: bin_data ([6][0][0][0] / 0x0006), 0/1
      Stream #0:1[0x101](und), 213, 1/90000: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 130 kb/s
    Successfully opened the file.
    Parsing a group of options: output url output.mp4.
    Applying option c (codec name) with argument copy.
    Successfully parsed a group of options.
    Opening an output file: output.mp4.
    [out#0/mp4 @ 0000021b89b251c0] No explicit maps, mapping streams automatically...
    [aost#0:0/copy @ 0000021b89b8d800] Created audio stream from input stream 0:1
    [file @ 0000021b89586680] Setting default whitelist 'file,crypto,data'
    Successfully opened the file.
    Stream mapping:
      Stream #0:1 -> #0:0 (copy)
    Output #0, mp4, to 'output.mp4':
      Metadata:
        encoder         : Lavf60.20.100
      Stream #0:0(und), 0, 1/44100: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 130 kb/s
    [out#0/mp4 @ 0000021b89b251c0] Starting thread...
    [in#0/mpegts @ 0000021b85724080] Starting thread...
    Automatically inserted bitstream filter 'aac_adtstoasc'; args=''
    [in#0/mpegts @ 0000021b85724080] EOF while reading inputpeed=  40x
    [in#0/mpegts @ 0000021b85724080] Terminating thread with return code 0 (success)
    [out#0/mp4 @ 0000021b89b251c0] All streams finished
    [out#0/mp4 @ 0000021b89b251c0] Terminating thread with return code 0 (success)
    [AVIOContext @ 0000021b87146340] Statistics: 2723207 bytes written, 2 seeks, 14 writeouts
    [out#0/mp4 @ 0000021b89b251c0] Output file #0 (output.mp4):
    [out#0/mp4 @ 0000021b89b251c0]   Output stream #0:0 (audio): 7232 packets muxed (2737451 bytes);
    [out#0/mp4 @ 0000021b89b251c0]   Total: 7232 packets (2737451 bytes) muxed
    [out#0/mp4 @ 0000021b89b251c0] video:0kB audio:2673kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
    size=    2659kB time=00:02:47.92 bitrate= 129.7kbits/s speed=41.3x
      Metadata:
        encoder         : Lavf60.20.100
      Stream #0:0(und), 0, 1/44100: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 130 kb/s
    [out#0/mp4 @ 0000021b89b251c0] Starting thread...
    [in#0/mpegts @ 0000021b85724080] Starting thread...
    Automatically inserted bitstream filter 'aac_adtstoasc'; args=''
    [in#0/mpegts @ 0000021b85724080] EOF while reading inputpeed=  40x
    [in#0/mpegts @ 0000021b85724080] Terminating thread with return code 0 (success)
    [out#0/mp4 @ 0000021b89b251c0] All streams finished
    [out#0/mp4 @ 0000021b89b251c0] Terminating thread with return code 0 (success)
    [AVIOContext @ 0000021b87146340] Statistics: 2723207 bytes written, 2 seeks, 14 writeouts
    [out#0/mp4 @ 0000021b89b251c0] Output file #0 (output.mp4):
    [out#0/mp4 @ 0000021b89b251c0]   Output stream #0:0 (audio): 7232 packets muxed (2737451 bytes);
    [out#0/mp4 @ 0000021b89b251c0]   Total: 7232 packets (2737451 bytes) muxed
    [out#0/mp4 @ 0000021b89b251c0] video:0kB audio:2673kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
    size=    2659kB time=00:02:47.92 bitrate= 129.7kbits/s speed=41.3x
    [in#0/mpegts @ 0000021b85724080] Starting thread...
    Automatically inserted bitstream filter 'aac_adtstoasc'; args=''
    [in#0/mpegts @ 0000021b85724080] EOF while reading inputpeed=  40x
    [in#0/mpegts @ 0000021b85724080] Terminating thread with return code 0 (success)
    [out#0/mp4 @ 0000021b89b251c0] All streams finished
    [out#0/mp4 @ 0000021b89b251c0] Terminating thread with return code 0 (success)
    [AVIOContext @ 0000021b87146340] Statistics: 2723207 bytes written, 2 seeks, 14 writeouts
    [out#0/mp4 @ 0000021b89b251c0] Output file #0 (output.mp4):
    [out#0/mp4 @ 0000021b89b251c0]   Output stream #0:0 (audio): 7232 packets muxed (2737451 bytes);
    [out#0/mp4 @ 0000021b89b251c0]   Total: 7232 packets (2737451 bytes) muxed
    [out#0/mp4 @ 0000021b89b251c0] video:0kB audio:2673kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
    size=    2659kB time=00:02:47.92 bitrate= 129.7kbits/s speed=41.3x
    [out#0/mp4 @ 0000021b89b251c0] All streams finished
    [out#0/mp4 @ 0000021b89b251c0] Terminating thread with return code 0 (success)
    [AVIOContext @ 0000021b87146340] Statistics: 2723207 bytes written, 2 seeks, 14 writeouts
    [out#0/mp4 @ 0000021b89b251c0] Output file #0 (output.mp4):
    [out#0/mp4 @ 0000021b89b251c0]   Output stream #0:0 (audio): 7232 packets muxed (2737451 bytes);
    [out#0/mp4 @ 0000021b89b251c0]   Total: 7232 packets (2737451 bytes) muxed
    [out#0/mp4 @ 0000021b89b251c0] video:0kB audio:2673kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
    size=    2659kB time=00:02:47.92 bitrate= 129.7kbits/s speed=41.3x
    [out#0/mp4 @ 0000021b89b251c0] Output file #0 (output.mp4):
    [out#0/mp4 @ 0000021b89b251c0]   Output stream #0:0 (audio): 7232 packets muxed (2737451 bytes);
    [out#0/mp4 @ 0000021b89b251c0]   Total: 7232 packets (2737451 bytes) muxed
    [out#0/mp4 @ 0000021b89b251c0] video:0kB audio:2673kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
    size=    2659kB time=00:02:47.92 bitrate= 129.7kbits/s speed=41.3x
    [out#0/mp4 @ 0000021b89b251c0]   Total: 7232 packets (2737451 bytes) muxed
    [out#0/mp4 @ 0000021b89b251c0] video:0kB audio:2673kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
    size=    2659kB time=00:02:47.92 bitrate= 129.7kbits/s speed=41.3x
    [out#0/mp4 @ 0000021b89b251c0] video:0kB audio:2673kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
    size=    2659kB time=00:02:47.92 bitrate= 129.7kbits/s speed=41.3x
    [in#0/mpegts @ 0000021b85724080] Input file #0 (fd:):
    size=    2659kB time=00:02:47.92 bitrate= 129.7kbits/s speed=41.3x
    [in#0/mpegts @ 0000021b85724080] Input file #0 (fd:):
    [in#0/mpegts @ 0000021b85724080] Input file #0 (fd:):
    [in#0/mpegts @ 0000021b85724080]   Input stream #0:1 (audio): 7232 packets read (2737451 bytes);
    [in#0/mpegts @ 0000021b85724080]   Total: 7232 packets (2737451 bytes) demuxed
    [AVIOContext @ 0000021b85744880] Statistics: 27226912 bytes read, 0 seeks
    

    It seems to me that the video data is being interpreted as bin_data and no codec is found for it. What is going on here?

    Must YT_DLP data be converted to some other format before being read by FFMPEG?

    Thank you.

  • FFmpeg: Issues for Transparent Background in WebM Video

    19 July, by BlueSky

    I've encountered an issue while processing videos with FFmpeg. I want to convert a MOV video with an alpha channel to WebM format and overlay it onto a main video. Below are the steps I took and the problem I encountered.

    I used Adobe After Effects (AE) to remove the green screen background from a video and exported the MOV file with RGB+Alpha channels using the Animation codec. Additionally, I tried exporting in QuickTime format, both ensuring the alpha channel was included.

    When converting the MOV video to WebM format, I executed the following command:

    ffmpeg -i input.mov -c:v libvpx-vp9 overlay.webm
    

    Then, I attempted to overlay the converted WebM video onto the main video main.mp4 using the following command:

    ffmpeg -i main.mp4 -vf "movie=overlay.webm,scale=200x200[video_inner];[in][video_inner]overlay=x=10:y=10[out]" output.mp4
    

    However, in the final output.mp4 video, the background of the WebM video was not transparent as expected, but instead showed a black background after removing the green screen.

    Could there be an error in one of my steps?

    I have tried different command parameters and options but have not been able to resolve this issue.

    I expected the WebM video to retain its transparent background when overlaid onto the main video. However, the resulting output.mp4 video showed the background of the WebM portion as black instead of transparent.

  • Python extract wav from video file

    19 July, by xolodec

    Related:

    How to extract audio from a video file using python?

    Extract audio from video as wav

    How to rip the audio from a video?

    My question is how could I extract wav audio track from video file, say video.avi? I read many articles and everywhere people suggest to use (from Python) ffmpeg as a subprocess (because there are no reliable python bindings to ffmpeg - the only hope was PyFFmpeg but i found it is unmaintaned now). I don't know if it is right solution and i am looking for good one.
    I looked to gstreamer and found it nice but unable to satisfy my needs -- the only way I found to accomplish this from command line looks like

     gst-launch-0.10 playbin2 uri=file://`pwd`/ex.mp4  audio-sink='identity single-segment=true ! audioconvert ! audio/x-raw-int, endianness=(int)1234, signed=(boolean)true, width=(int)16, depth=(int)16, rate=(int)16000, channels=(int)1 ! wavenc !  filesink location=foo.wav’ 
    

    But it is not efficient because i need to wait ages while playing video and simultaneously writing to wav file.

    ffmpeg is much better:

    avconv  -i foo.mp4  -ab 160k -ac 1 -ar 16000 -vn ffaudio.wav
    

    But i am unable to launch it from python (not as a command line subprocess). Could you please point me out pros and cons of launching ffmpeg from python as a command line utility ? (I mean using python multiprocessing module or something similar).

    And second question.

    What is simple way to cut long wav file into pieces so that i don't break any words ? i mean pieces of 10-20 sec length with start and end during the pause in sentences/words ?

    i know how to break them on arbitrary pieces:

    import wave
    
    
    win= wave.open('ffaudio.wav', 'rb')
    wout= wave.open('ffsegment.wav', 'wb')
    
    t0, t1= 2418, 2421 # cut audio between 2413, 2422 seconds
    s0, s1= int(t0*win.getframerate()), int(t1*win.getframerate())
    win.readframes(s0) # discard
    frames= win.readframes(s1-s0)
    
    wout.setparams(win.getparams())
    wout.writeframes(frames)
    
    win.close()
    wout.close()
    
  • why am i getting this error when using FFmpeg in a spring boot app on a mac intel device: SIGSEGV (0xb) at pc=0x000000013d71b0e0, pid=49777, tid=42755

    19 July, by Godwill Christopher

    I am working with FFmpeg library in spring boot app to stream live recording from an ip camera via RSTP and save to S3 bucket but i am running into the error below.

    A fatal error has been detected by the Java Runtime Environment:

    SIGSEGV (0xb) at pc=0x000000013d71b0e0, pid=49777, tid=42755

    JRE version: OpenJDK Runtime Environment Corretto-19.0.2.7.1 (19.0.2+7) (build 19.0.2+7-FR) Java VM: OpenJDK 64-Bit Server VM Corretto-19.0.2.7.1 (19.0.2+7-FR, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, bsd-amd64) Problematic frame: C [libavutil.56.dylib+0xa0e0] av_strstart+0x10

    No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again An error report file with more information is saved as: /Users/CODA/Desktop/videoSaleService/hs_err_pid49777.log

    If you would like to submit a bug report, please visit: https://github.com/corretto/corretto-19/issues/ The crash happened outside the Java Virtual Machine in native code. See problematic frame for where to report the bug.

    Process finished with exit code 134 (interrupted by signal 6:SIGABRT)

    public static void main(String[] args) {
        OkHttpClient client = new OkHttpClient();
        try (S3Client s3Client = S3Client.create()) {
            VideoService videoService = new VideoService(new VideoRepositoryImpl(),
                    new S3Service(s3Client), new VideoExtractor(client), new ISApiClient());
            videoService.streamLiveVideoRSTP(System.out);
        } catch (IOException e) {
            log.error("Error occurred while streaming live video: {}", e.getMessage(), e);
        } catch (Exception e) {
            log.error("Unexpected error occurred: {}", e.getMessage(), e);
        }
    }
    
    public void streamLiveVideoRSTP(OutputStream outputStream) throws IOException {
        File tempFile = File.createTempFile("live_stream", ".mp4");
    
        try (InputStream inputStream = client.getLiveStreamingVideoRSTP();
             OutputStream fileOutputStream = new FileOutputStream(tempFile)) {
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
                fileOutputStream.write(buffer, 0, bytesRead);
            }
        } catch (Exception e) {
            log.error("Error occurred while streaming live video: {}", e.getMessage(), e);
            throw new IOException("Error occurred while streaming live video", e);
        }
    
        // Upload the captured video file to S3
        try {
            uploadStreamedVideoToS3(tempFile);
        } finally {
            if (tempFile.exists()) {
                if (!tempFile.delete()) {
                    log.warn("Failed to delete temporary file: {}", tempFile.getAbsolutePath());
                }
            }
        }
    }
    
    private final BlockingQueue frameQueue = new ArrayBlockingQueue<>(10);
    
    public ISApiClient() {
        new Thread(this::startGrabbingFrames).start();
    }
    
    public InputStream getLiveStreamingVideoRSTP() {
        return new InputStream() {
            private ByteArrayInputStream currentStream;
    
            @Override
            public int read() {
                if (currentStream == null || currentStream.available() == 0) {
                    byte[] frame = frameQueue.poll();
                    if (frame != null) {
                        currentStream = new ByteArrayInputStream(frame);
                    } else {
                        return -1;
                    }
                }
                return currentStream.read();
            }
        };
    }
    
    private void startGrabbingFrames() {
        try (FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(rtspUrl)) {
            frameGrabber.setOption("rtsp_transport", "tcp");
            frameGrabber.start();
    
            FFmpegFrameFilter frameFilter = new FFmpegFrameFilter("format=yuv420p",
                    frameGrabber.getImageWidth(), frameGrabber.getImageHeight());
            frameFilter.setPixelFormat(frameGrabber.getPixelFormat());
            frameFilter.start();
    
            log.info("Started grabbing frames from RTSP stream.");
    
            while (true) {
                Frame frame = frameGrabber.grab();
                if (frame != null && frame.image != null) {
                    log.info("Frame grabbed: width={} height={} timestamp={}",
                            frame.imageWidth, frame.imageHeight, frame.timestamp);
                    frameFilter.push(frame);
                    Frame filteredFrame = frameFilter.pull();
    
                    if (filteredFrame != null && filteredFrame.image != null) {
                        log.info("Frame filtered: width={} height={} timestamp={}",
                                filteredFrame.imageWidth, filteredFrame.imageHeight, filteredFrame.timestamp);
                        byte[] imageBytes = convertFrameToBytes(filteredFrame);
                        if (imageBytes.length > 0) {
                            frameQueue.offer(imageBytes);
                            log.info("Frame added to queue, queue size={}", frameQueue.size());
                        }
                    }
                }
            }
        } catch (IOException e) {
            log.error("Error grabbing frames: {}", e.getMessage(), e);
        }
    }
    
    private byte[] convertFrameToBytes(Frame frame) {
        if (frame == null || frame.image == null) {
            return new byte[0];
        }
    
        ByteBuffer byteBuffer = null;
        for (Object img : frame.image) {
            if (img instanceof ByteBuffer) {
                byteBuffer = (ByteBuffer) img;
                break;
            }
        }
    
        if (byteBuffer == null) {
            return new byte[0];
        }
    
        byte[] bytes = new byte[byteBuffer.remaining()];
        byteBuffer.get(bytes);
        return bytes;
    }