Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Set matplotlib video animation size (1920x1080)

    23 août, par David Ferris

    I'm trying to create a matplotlib animation that is 1920x1080. The following animation generated is (1152x648), which is the right ratio but too small. I know that I can do this after the fact with ffmpeg, but I'd like to avoid re-encoding if possible.

    y = my_data
    fig = plt.figure(figsize=(16,9))
    
    def ani(i):
        # Animation Code
    
    animator = FuncAnimation(fig, ani, frames=y.shape[0])
    
    # Can't figure out what extra_args to set here
    ffmpeg_writer = FFMpegWriter(fps=y.shape[0]/sound.duration_seconds, extra_args=['-scale', '1920x1080'])
    animator.save('mymovie.mp4', writer=ffmpeg_writer)
    
    print(ffmpeg_writer.frame_size) # prints (1152, 648)
    
    ipd.Video('mymovie.mp4')
    

    As you can see above, I have tried a few extra_args, however I can't get anything to work.

  • Converting mkv files to mp4 with ffmpeg-python [closed]

    22 août, par myth0s

    I have a lot of .mkv files that I'm trying to convert to .mp4, so I decided to try and program a solution in python. After a few hours, trying to figure out how to copy the subfolders too, I gave up on it and decided to stick with converting individual subfolders, and then copying them over to another directory.

    I've made a simple script, that should convert .mkv files that are in the same folder as the script. However, I keep getting this error:

    FileNotFoundError: [WinError 2] The system cannot find the file specified

    Here's my code:

    import os
    import ffmpeg
    
    start_dir = os.getcwd()
    
    def convert_to_mp4(mkv_file):
        no_extension = str(os.path.splitext(mkv_file))
        with_mp4 = no_extension + ".mp4"
        ffmpeg.input(mkv_file).output(with_mp4).run()
        print("Finished converting {}".format(no_extension))
    
    for path, folder, files in os.walk(start_dir):
        for file in files:
            if file.endswith('.mkv'):
                print("Found file: %s" % file)
                convert_to_mp4(file)
            else:
                pass
    
    
  • how to upscale video max dimensions which fit within target size using ffmpeg ? [closed]

    22 août, par bguiz

    I'm using the following ffmpeg command to crop off the top N pixels from the input video, and replace it with a black padding:

    INVID=""
    OUTVID=""
    
    ffmpeg \
      -y \
      -i "${INVID}" \
      -vf "crop=iw:ih-30:0:30,pad=iw:ih:0:0:black" \
      "${OUTVID}"
    
    ffprobe  "${OUTVID}"
    
    

    In the ffprobe output, I can see the dimensions of the output video.

    However, the dimensions of the output video is entirely dependent on the dimensions of input video. In some cases, my input video are in odd sizes, and I wish to scale them up to a particular set of "standard" dimensions, e.g. 1280x720.

    How can I do so?

  • How to Terminate a Process Normally Created using ProcessBuilder

    21 août, par Bilal Ahmed Yaseen

    I am creating Processes using ProcessBuilder in my Java Application. The created process executes some FFMPEG commands which actually copy the RTSP streams in specified destination media file.

    ProcessBuilder builder = new ProcessBuilder("ffmpeg", "-i", RTSP_URL, "-f", fileFormat, destFilePath);
    Process processToExecute = builder.start();
    

    I want to close the process before it completes its execution. So, If I run this FFMPEG command directly in windows CMD and then press 'CTRL+C' after 5 seconds then process get terminates with status '2'. And I can play the media file created so far.

    So, If I do the same operation in my Java Application using:

     process.destroy(); //I call this method after 5 sec
    

    I get the status code '1' which means abnormal termination. I get the status by the following way:

     processToExecute.destroy();
     processToExecute.exitValue(); //This return me status '1'
    

    And I can't play the media file and I think this is due to the abnormal termination of the process.

    So how I can terminate the process created using ProcessBuilder in the same way we do in CMD with (CTRL+C) so that I may play the created media file ?

    I want to terminate process (created using ProcessBuilder) in Java Application with status code of '2' that I get when I terminate process using CMD.

    EDIT#01: --- Sharing Findings

    So, when I try to delete that file once app terminates, I get the following error:

    The Action Can't be Performed Because File is Opened in FFMPEG.exe
    

    Which means that process is not terminating the command it is executing. That command still has occupied this file that's why I am not getting able to play it. Process gets terminate when I call:

     processToExecute.destroy();
    

    But, the task it is performing (that is execution of a command) is still active. Strange!!!!

    EDIT#02: Sharing Ultimate Reason

    Actually If I directly press 'CTRL+C' or 'q' in cmd when process is running then it terminates the process successfully and this process is no more visible in the currently executing processes lists.

    And Programatically when I call method:

    cmd> processToExecute.destroy();
    

    It terminates the process but when I see the list of currently executing processes I can still see them over there.

    And same scenario exists If I try to terminate this process using 'taskkill' or 'kill' command in another CMD by specifying their's name or pid that still process terminates abnormally.

    P.S. I use the following command to see the running processes:

    tasklist
    

    So from this it proves that destroy() method from Application and 'taskkill or kill' command from another CMD is not terminating the process normally that pressing 'CTRL+C' and 'q' does.

  • Can moviepy render via GPU, using something like FFMPEG ?

    21 août, par Shenhav Mor

    I'm working on something that concatenate videos and adds some titles on through moviepy.

    As I saw on the web and on my on pc moviepy works on the CPU and takes a lot of time to save(render) a movie. Is there a way to improve the speed by running the writing of moviepy on GPU? Like using FFmpeg or something like this?

    I didn't find an answer to that on the web, so I hope that some of you can help me. I tried using thread=4 and thread=16 but they are still very very slow and didn't change much.

    My CPU is very strong (i7 10700k), but still, rendering on moviepy takes me for a compilation with a total of 8 minutes 40 seconds, which is a lot.

    Any ideas?Thanks! the code doesnt realy matter but :

    def Edit_Clips(self):
    
        clips = []
    
        time=0.0
        for i,filename in enumerate(os.listdir(self.path)):
            if filename.endswith(".mp4"):
                tempVideo=VideoFileClip(self.path + "\\" + filename)
    
                txt = TextClip(txt=self.arrNames[i], font='Amiri-regular',
                               color='white', fontsize=70)
                txt_col = txt.on_color(size=(tempVideo.w + txt.w, txt.h - 10),
                                       color=(0, 0, 0), pos=(6, 'center'), col_opacity=0.6)
    
                w, h = moviesize = tempVideo.size
                txt_mov = txt_col.set_pos(lambda t: (max(w / 30, int(w - 0.5 * w * t)),
                                                     max(5 * h / 6, int(100 * t))))
    
                sub=txt_mov.subclip(time,time+4)
                time = time + tempVideo.duration
    
                final=CompositeVideoClip([tempVideo,sub])
    
                clips.append(final)
    
        video = concatenate_videoclips(clips, method='compose')
        print("after")
        video.write_videofile(self.targetPath+"\\"+'test.mp4',threads=16,audio_fps=44100,codec = 'libx264')