Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • How can I get my saved mp4 to exactly match the output of plot.show() ?

    10 mai 2019, par Jimmy

    When I try to save the results of an animation to mp4 using ffmpeg, I am getting a jumbled mess.

    plt.show() shows exactly what I want it to show in the animation. However, when I save it using ffmpeg, the result is very different from what plt.show() returns. I have tried various arguments for fps etc. but nothing has helped.

    %matplotlib
    import pandas as pd
    import matplotlib as mpl ## uncomment this if you are running this on a Mac
    #mpl.use('TkAgg')         ## and want to use blit=True
    import matplotlib.pyplot as plt 
    import matplotlib.animation as animation 
    import numpy as np 
    import csv
    
    people = ('','Jim', 'Dan')
    plt.rcdefaults()
    fig, ax = plt.subplots()
    y_pos = np.arange(len(people))
    
    ax.set_xlim(0,10)
    ax.set_yticks(y_pos)
    ax.set_yticklabels(people)
    ax.invert_yaxis() 
    ax.set_xlabel('Skill')
    titleList=['Basketball','Hockey','Baseball']
    df=[[0,5,7],[0,4,9],[0,2,6]]
    def animate(i):
       # Example data
        while i<3:
            ax.set_yticks(y_pos)
            ax.set_yticklabels(people)
            ax.set_xlabel(titleList[i])
            performance=df[i]
    
            title = ax.text(0.5,0.95,str(titleList[i]), bbox={'facecolor':'w', 'alpha':0.5, 'pad':5},transform=ax.transAxes, ha="center")
    
            rects = ax.barh(y_pos, performance, align='center',
                    color='blue', ecolor='None')
            return [rect for rect in rects] + [title]
    
    
    ani = animation.FuncAnimation(fig,animate, frames=3, blit=True
                                ,interval=2000,repeat=False)
    
    plt.rcParams['animation.ffmpeg_path'] = 'C:\\ffmpeg\\bin\\ffmpeg.exe'
    Writer = animation.writers['ffmpeg']
    ani.save('test.mp4')
    plt.show() 
    

    The result is a very fast video where all the data gets written over (similar to the plt.show() results when blit=False).

  • Discord.py music bot doesn't play next song in queue

    10 mai 2019, par Lewis H

    This is my code for the bot I'm trying to create, it plays the music fine.

    ytdl_options = {
        'format': 'bestaudio/best',
        'restrictfilenames': True,
        'noplaylist': True,
        'nocheckcertificate': True,
        'quiet':True,
        'ignoreerrors': False,
        'logtostderr': False,
        'no_warnings': True,
        'default_search': 'auto',
        'source_address': '0.0.0.0' # using ipv4 since ipv6 addresses causes issues sometimes
        }
    
    
            # ffmpeg options
    ffmpeg_options= {
        'options': '-vn'
        }
    
    
    
    @bot.command()
    async def play(ctx, url:str = None): 
        queue = {} 
    
        channel = ctx.author.voice.channel    
        if ctx.voice_client is not None:  
            await ctx.voice_client.move_to(channel)
        elif ctx.author.voice and ctx.author.voice.channel:       
            await channel.connect()
    
        if not url:
            await ctx.send("Try adding a URL. e.g. !play https://youtube.com/watch?v=XXXXXXXXX")
    
        if ctx.voice_client is not None:
            vc = ctx.voice_client #vc = voice client, retrieving it
            ytdl = youtube_dl.YoutubeDL(ytdl_options)
    
    
            loop = asyncio.get_event_loop()
            data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url))
    
            if 'entries' in data:
                data = data['entries'][0] 
            svr_id = ctx.guild.id
            if svr_id in queue:
                queue[svr_id].append(data)
    
            else:
                queue[svr_id] = [data]
            await ctx.send(data.get('title') + " added to queue")
    
            source = ytdl.prepare_filename(queue[svr_id][0])
            def pop_queue():
                if queue[svr_id] != []:
                    queue[svr_id].pop(0)
                    data = queue[svr_id][0]
                else:
                    vc.stop()
    
            if not vc.is_playing():
                vc.play(discord.FFmpegPCMAudio(source, **ffmpeg_options), after=lambda: pop_queue())
    

    The next song downloads and queues it fine, but once the first song finishes, it doesn't play the next one. I can't figure out how to make it play after the first song has commenced. I have the after= set to remove the top item of the queue, but how do I get it to play again? Thanks

  • Muxing AVPackets into mp4 file - revisited

    10 mai 2019, par Kiamur

    I'm refering to this thread here: Muxing AVPackets into mp4 file

    The question over there is mainly the same that I have and the first answer looks very promising. The source (somkind of pseudo) code that the user pogorskiy provides seems to do exactly what I need:

    AVOutputFormat * outFmt = av_guess_format("mp4", NULL, NULL);
    AVFormatContext *outFmtCtx = NULL;
    avformat_alloc_output_context2(&outFmtCtx, outFmt, NULL, NULL);
    AVStream * outStrm = av_new_stream(outFmtCtx, 0);
    
    AVCodec * codec = NULL;
    avcodec_get_context_defaults3(outStrm->codec, codec);
    outStrm->codec->coder_type = AVMEDIA_TYPE_VIDEO;
    
    ///....
    /// set some required value, such as
    /// outStrm->codec->flags
    /// outStrm->codec->sample_aspect_ratio
    /// outStrm->disposition
    /// outStrm->codec->codec_tag
    /// outStrm->codec->bits_per_raw_sample
    /// outStrm->codec->chroma_sample_location
    /// outStrm->codec->codec_id
    /// outStrm->codec->codec_tag
    /// outStrm->codec->time_base
    /// outStrm->codec->extradata 
    /// outStrm->codec->extradata_size
    /// outStrm->codec->pix_fmt
    /// outStrm->codec->width
    /// outStrm->codec->height
    /// outStrm->codec->sample_aspect_ratio
    /// see ffmpeg.c for details  
    
    avio_open(&outFmtCtx->pb, outputFileName, AVIO_FLAG_WRITE);
    
    avformat_write_header(outFmtCtx, NULL);
    
    for (...)
    {
    av_write_frame(outFmtCtx, &pkt);
    }
    
    av_write_trailer(outFmtCtx);
    avio_close(outFmtCtx->pb);
    avformat_free_context(outFmtCtx);
    

    The pkt data, I receive from a third party API from my connectec camera. There is no file to open, to read the input data from and there is no RTSP stream to be received from the camera. It is just an API call, that gives me the pointer to a H264 encoded frame which is exactly the raw data for an AVPacket.

    Anyway, I try to use this code as base for my applicatio, but the first problem that occurs is, that I get a runtime error:

    Could not find tag for codec none in stream #0, codec not currently supported in container
    

    So I started adding some more information to the codec, as pogorskiy suggested:

    outStrm->codec->codec_id = AV_CODEC_ID_H264;
    outStrm->codec->width = 1920;
    outStrm->codec->height = 1080;
    

    Now that I provided a codec_id, I was hoping, that the runtime message changes to at least something different, but it still ist the same:

    Could not find tag for codec none in stream #0, codec not currently supported in container
    

    Any idea on how I can set up the structures, so that I can open an mp4 file for writing my packets to?

  • Is there an way to capture audio and video of a window ? [on hold]

    10 mai 2019, par Supertiger

    So, I'm trying to capture audio and video of a single window and not the whole desktop? For instance, I want to capture a game and the sounds that are coming out from it and not from any other program running (Just like discords screen share)

    I have already tried this code but it only captures the video and not the audio of the window.

    ./ffmpeg.exe -f gdigrab -framerate 30 -i title="Minecraft" output.mkv
    
  • How to gain volumes of specific bands of audio files using ffmpeg ?

    10 mai 2019, par Ko Ohhashi

    I want increase or decrease volume of specific frequency bands with ffmpeg.

    I think bandreject and bandpass filter can do similar thing. But is there any way to reject 80% of energy of specific bands?

    Thanks in advance?