Newest 'ffmpeg' Questions - Stack Overflow

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

Articles published on the website

  • Start Android Java VM from native C code NDK (ffmpeg mediacodec use)

    19 April, by eusoubrasileiro

    I managed to cross-compile ffmpeg using the NDK for armv8a api 27 with MediaCodec hardware acceleration support.

    Using root after setting permissions, folders and setting properly LD_LIBRARY_PATH etc. I can run it without problems on a terminal session (ssh). Only if I don't try to use the -hwaccel option.

    If try to run something using -hwaccel, like:

    ffmpeg -rtsp_transport tcp -an -hwaccel mediacodec -c:v hevc_mediacodec -i rtsp://user:pass@192.168.0.100:554/onvif1 -f null - -benchmark
    

    I get the error bellow about No Java virtual machine.

    ...
    Input #0, rtsp, from 'rtsp://user:pass@192.168.0.100:554/onvif1':
      Metadata:
        title           : H.265 Video, RtspServer_0.0.0.2
      Duration: N/A, start: 0.000000, bitrate: N/A
        Stream #0:0: Video: hevc (Main), yuv420p(tv, bt470bg), 1920x1080 [SAR 1:1 DAR 16:9], 10 fps, 10 tbr, 90k tbn, 10 tbc
        Stream #0:1: Audio: pcm_alaw, 8000 Hz, mono, s16, 64 kb/s
    [amediaformat @ 0x7e2ea27300] No Java virtual machine has been registered
    [hevc_mediacodec @ 0x7e2eb44f00] Failed to create media format
    Stream mapping:
      Stream #0:0 -> #0:0 (hevc (hevc_mediacodec) -> wrapped_avframe (native))
    Error while opening decoder for input stream #0:0 : Generic error in an external library
    

    Would it be possible to start (create or launch?) the Dalvik Java VM directly from the C code? I don't even know if those are correct terms. Make it visible for ffmpeg?

    Any information that will help a Android Newbie get on his feet will be greatly appreciated. If that is possible I would write a little patch on the ffmpeg code.

    I really would not like to package this in an app only to be able to test around with this.

  • Can I pass a list of image into the input method of ffmpeg-python

    18 April, by Horla.li

    My task involves using ffmpeg to create video from image sequence. the code belows solves the problem.

    import ffmpeg
    
    video = ffmpeg.input('/path/to/images/*.jpg', pattern_type='glob',framerate=20).output(video.mp4).run()
    

    However since the image data we are getting follows the pattern

    1.jpg,
    2.jpg,
    3.jpg
    .
    .
    20.jpg
    .
    .
    100.jpg
    

    the video get created with the glob pattern 1.jpg, 100.jpg, 11.jpg, 12.jpg, ... 2.jpg, 20.jpg, 21.jpg ... which is very unpleasant to watch.

    Is there anyway I can pass a list or anything else aside a path/glob pattern where the images are sorted in order. Also as a bonus I will be happy if I can choose which files to add as an the input method input()

  • ffmpeg concat of two files results in malformed video

    18 April, by Stas Ezersky

    I processing two videos as follows:

    ffmpeg -i video-raw/455848793538790988_duration18.051.mp4 -b:v 993k -b:a 128k -vf "scale=720x1280:force_original_aspect_ratio=decrease,pad=720:1280:(ow-iw)/2:(oh-ih)/2,setsar=1:1" video-proc/455848793538790988_duration18.051.mp4
    

    and

    ffmpeg -i video-raw/14425661295137552_duration11.666.mp4  -b:v 993k -b:a 128k -vf "scale=720x1280:force_original_aspect_ratio=decrease,pad=720:1280:(ow-iw)/2:(oh-ih)/2,setsar=1:1" video-proc/14425661295137552_duration11.666.mp4
    

    then running the following command to concat:

    ffmpeg -f concat -safe 0 -i video-concat/dogs-2021-04-17-06-46-id-1.txt -c:v copy -c:a copy ./output.mp4

    the resulting video starts properly but when getting to the second video the image stuck and and sound becomes slow.

    The ffprobe results are as follow:

    Before processing:

    ffprobe video-raw/14425661295137552_duration11.666.mp4 
    
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video-raw/14425661295137552_duration11.666.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf58.45.100
      Duration: 00:00:11.68, start: 0.000000, bitrate: 565 kb/s
        Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 640x800 [SAR 1:1 DAR 4:5], 462 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
        Metadata:
          handler_name    : VideoHandler
        Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 93 kb/s (default)
        Metadata:
          handler_name    : SoundHandler
    

    for the second one:

    ffprobe video-raw/455848793538790988_duration18.051.mp4
    
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video-raw/455848793538790988_duration18.051.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf58.45.100
      Duration: 00:00:18.07, start: 0.000000, bitrate: 655 kb/s
        Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt709/bt709), 576x1024 [SAR 1:1 DAR 9:16], 585 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
        Metadata:
          handler_name    : VideoHandler
        Stream #0:1(und): Audio: aac (HE-AACv2) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 62 kb/s (default)
        Metadata:
          handler_name    : SoundHandler
    

    after processing:

    ffprobe video-proc/14425661295137552_duration11.666.mp4
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video-proc/14425661295137552_duration11.666.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf58.45.100
      Duration: 00:00:11.70, start: 0.000000, bitrate: 1133 kb/s
        Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x1280 [SAR 1:1 DAR 9:16], 993 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
        Metadata:
          handler_name    : VideoHandler
        Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 130 kb/s (default)
        Metadata:
          handler_name    : SoundHandler
    

    and the second one

    ffprobe video-proc/455848793538790988_duration18.051.mp4
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video-proc/455848793538790988_duration18.051.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf58.45.100
      Duration: 00:00:18.19, start: 0.000000, bitrate: 1044 kb/s
        Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x1280 [SAR 1:1 DAR 9:16], 923 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
        Metadata:
          handler_name    : VideoHandler
        Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 112 kb/s (default)
        Metadata:
          handler_name    : SoundHandler
    

    any ideas whats wrong? both videos play perfect separately after processing but not after the concat

  • How to put bat into wmv? [closed]

    18 April, by Dead_TheRay

    Like open some folder after opening it file

    start explorer.exe

    or something, idk.

    Maybe i can do it with ffmpeg? Or something else?

    Don't ask why i want it lol :D

    I don't want change it question,

    I JUST WANT PUT BAT INTO WMV FILE.

    uhm. It question don't need changes cause i write all what i want!

  • OpusError while using ffmpeg library in discord.py

    18 April, by The Assignment Nerd

    While playing a local file or youtube audio, I get OpusError: invalid argument error

    The play command looks like:

    # bot.py
    import os
    import discord
    from discord.ext import commands
    from dotenv import load_dotenv
    from models import *
    from discord.voice_client import VoiceClient
    import logging
    from config import *
    import youtube_dl
    from youtube_dl import YoutubeDL
    
    @bot.command()
    async def play(ctx):
        user=ctx.author
        voice_channel=user.voice.channel
        channel=None
        # only play music if user is in a voice channel
        if voice_channel:
            # grab user's voice channel
            channel=voice_channel.name
            await ctx.send('User is in channel: '+ channel)
            # create StreamPlayer
            vc = await voice_channel.connect()
            url="https://www.youtube.com/watch?v=AOeY-nDp7hI"
            YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist':'True'}
            FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
            voice = discord.utils.get(bot.voice_clients, guild=ctx.guild)
            print(0)
            if not voice.is_playing():
                print("1")
                with YoutubeDL(YDL_OPTIONS) as ydl:
                    info = ydl.extract_info(url, download=False)
                    print(2)
                URL = info['formats'][0]['url']
                print(3)
                voice.play(discord.FFmpegPCMAudio(URL, **FFMPEG_OPTIONS))
                print(4)
                voice.is_playing()
                print("Strated playing")
            else:
                await ctx.send("Already playing song")
                return
        else:
            await ctx.send('User is not in a channel.')
    

    My error:

    0
    1
    [youtube] AOeY-nDp7hI: Downloading webpage
    [youtube] Downloading just video AOeY-nDp7hI because of --no-playlist
    2
    3
    Ignoring exception in command play:
    Traceback (most recent call last):
      File "/opt/homebrew/lib/python3.9/site-packages/discord/ext/commands/core.py", line 85, in wrapped
        ret = await coro(*args, **kwargs)
      File "/Users/mohit/programming/discord/area-51-helper/main.py", line 115, in play
        voice.play(discord.FFmpegPCMAudio(URL, **FFMPEG_OPTIONS))
      File "/opt/homebrew/lib/python3.9/site-packages/discord/voice_client.py", line 564, in play
        self.encoder = opus.Encoder()
      File "/opt/homebrew/lib/python3.9/site-packages/discord/opus.py", line 291, in __init__
        self.set_fec(True)
      File "/opt/homebrew/lib/python3.9/site-packages/discord/opus.py", line 326, in set_fec
        _lib.opus_encoder_ctl(self._state, CTL_SET_FEC, 1 if enabled else 0)
      File "/opt/homebrew/lib/python3.9/site-packages/discord/opus.py", line 92, in _err_lt
        raise OpusError(result)
    discord.opus.OpusError: invalid argument
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "/opt/homebrew/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 939, in invoke
        await ctx.command.invoke(ctx)
      File "/opt/homebrew/lib/python3.9/site-packages/discord/ext/commands/core.py", line 863, in invoke
        await injected(*ctx.args, **ctx.kwargs)
      File "/opt/homebrew/lib/python3.9/site-packages/discord/ext/commands/core.py", line 94, in wrapped
        raise CommandInvokeError(exc) from exc
    discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OpusError: invalid argument
    

    I'm using these version

    discord.py==1.0.1
    ffmpeg==4.3.2
    youtube_dl==2021.4.17