Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • How to correct aspect ratio - ffmpeg poisoned video

    13 mai, par Kurt Fitzner

    I have a video that I converted from the original in a way that seems to have poisoned my aspect ratio. The intended aspect ratio is 12:5 (2.4.:1) at 1920x800.

    The video was created with:

    ffmpeg -analyzeduration 1000000000 -probesize 100G -loglevel warning -stats -hwaccel cuda \
      -hwaccel_output_format cuda -y -i "UHDSOURCE.mkv" -map 0:v? -c:v hevc_nvenc \
      -preset p7 -2pass true -multipass fullres -rc vbr -rc-lookahead 55 -b:v 1000k -minrate 0 -maxrate 3000k \
      -bufsize 120000k -vf crop=3840:1600:0:280,scale_cuda=1920:800 -metadata title="HDDEST" \
      -map 0:a:2 -c:a:0 aac -b:a:0 160k -map 0:a:4 -c:a:1 aac -b:a:1 96k \
      -map 0:s? -c:s copy -map_metadata 0 "HDDEST.mkv"
    

    The original was 16:9 letterboxed, and the above command seems to have decided the PAR should reflect that. The result is a video with:

    Stream #0:0(eng): Video: hevc (Main 10), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 1920x800 [SAR 20:27 DAR 16:9], SAR 27:20 DAR 81:25, 23.98 fps, 23.98 tbr, 1k tbn (default)
    

    I can get halfway to fixing this with:

    ffmpeg -i HDDEST.mkv -aspect 12:5 -c copy HDDEST_ASPECT.mkv
    

    But the resultant video still shows two different SAR and DARs. Some players use one, some players insist on the 16:9, though:

    Stream #0:0[0x1](eng): Video: hevc (Main 10) (hev1 / 0x31766568), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 1920x800 [SAR 20:27 DAR 16:9], 1072 kb/s, SAR 1:1 DAR 12:5, 23.98 fps, 23.98 tbr, 16k tbn, Start 0.021000 (default)
    

    Q1: What are the two aspect ratio displays? I think one of them is the file globally and one of them is the stream, but can get no clear answer

    Q2: How to correct this without re-encoding? The disc this came from was damaged when my burner was knocked off the table.

  • Apply multiple text filters at once and burn into video for captioning without re-encoding, and fix error [ffmpeg-python wrapper]

    13 mai, par Baldi

    Is there any way to burn text into a video without re-encoding? I ask this because the re-encoding process goes at around 0.1x speed on my device when writing to WEBM. Alternatively, if there is a faster way to render high quality video quickly while still re-encoding that would be great. I vaguely remember someone writing to a temporary file to solve this problem.

    Also small error in program, code attatched

    def processVideo(self):
        print("creating video")
    
        # File location management
        font_path = self.input_path / "CalSans-Regular.ttf"
        background_path = self.input_path / "new_video_background.webm"
        audio_path = self.sound_output_path
        video_ouput_path = self.parent_path / "new_result.webm"
        sound_input = ffmpeg.input(str(audio_path))
        video_input = ffmpeg.input(str(background_path))
    
        # Adding captions
        print(self.text_caption)
        previous_timepoint = 0
        for caption, timepoint in zip(self.text_caption, self.timepoints, strict=False): 
            # Text caption and timepooints are lists where the end of the words in text_caption correspond
            # to the timepoint with the same index in timepoint
            video_input = video_input.drawtext(
                                                text=caption, 
                                                fontfile = font_path, 
                                                x='w-text_w/2', 
                                                y='h-text_h/2', 
                                                escape_text=True, 
                                                fontsize= 32,
                                                bordercolor = "black",
                                                borderw = 4,
                                                enable=f'between(t,{previous_timepoint},{timepoint["timeSeconds"]})'
                                                )
            previous_timepoint = timepoint["timeSeconds"]
            
        # Combining sound and video and writing output
        command = ffmpeg.output(sound_input, video_input, str(video_ouput_path), codec='copy').overwrite_output().global_args('-shortest')
        print("args =", command)
        print(command.get_args())
        command.run()
        print("done!")
    
      File "c:\Desktop\Projects\video_project\main.py", line 239, in 
        post_list[0].processVideo()
        ~~~~~~~~~~~~~~~~~~~~~~~~~^^
      File "c:\Desktop\Projects\video_project\main.py", line 223, in processVideo
        command.run()
        ~~~~~~~~~~~^^
      File "C:\Desktop\Projects\video_project\.venv\Lib\site-packages\ffmpeg\_run.py", line 313, in run
        process = run_async(
            stream_spec,
        ...<5 lines>...
            overwrite_output=overwrite_output,
        )
      File "C:\Desktop\Projects\video_project\.venv\Lib\site-packages\ffmpeg\_run.py", line 284, in run_async
        return subprocess.Popen(
               ~~~~~~~~~~~~~~~~^
            args, stdin=stdin_stream, stdout=stdout_stream, stderr=stderr_stream
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        )
        ^
      File "C:\AppData\Local\Programs\Python\Python313\Lib\subprocess.py", line 1038, in __init__
        self._execute_child(args, executable, preexec_fn, close_fds,
        ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                            pass_fds, cwd, env,
                            ^^^^^^^^^^^^^^^^^^^
        ...<5 lines>...
                            gid, gids, uid, umask,
                            ^^^^^^^^^^^^^^^^^^^^^^
                            start_new_session, process_group)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\AppData\Local\Programs\Python\Python313\Lib\subprocess.py", line 1550, in _execute_child
        hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
                                 # no special security
                                 ^^^^^^^^^^^^^^^^^^^^^
        ...<4 lines>...
                                 cwd,
                                 ^^^^
                                 startupinfo)
                                 ^^^^^^^^^^^^
    FileNotFoundError: [WinError 206] The filename or extension is too long
    
  • How can I generate a video file directly from an FFmpeg filter with no actual input file ?

    12 mai, par blahdiblah

    FFmpeg has a number of video generating filters, listed in the documentation as "video sources":

    • cellauto
    • color
    • mptestsrc
    • fei0r_src
    • life
    • nullsrc, rgbtestsrc, testsrc

    Those are great for using with other filters like overlay, but is there any way that I can generate a movie consisting of just one of those video sources without any input video?

    Something like:

    ffmpeg -vf color=red" red_movie.mp4
    

    Except that that errors out with At least one input file must be specified.

  • Ffmpeg rtmp to hls conversion but how to solve network issue ?

    11 mai, par Baka-Maru Lama

    I'm trying to convert hls stream from rtmp source and its' working fine but the problem is when rtmp server is down or network issue the ffmpeg hls conversion process gets stuck and never comes to work again even if rtmp server is back online.

    I've tried

    -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 5 
    

    command - it says option is not recognized options by the way I'm using ffmpeg [v4.2.1].

    I'm using following ffmpeg commands

    ffmpeg -i rtmp://localhost/living/test  ^
    -max_muxing_queue_size 9999  ^
    -async 1 -vf yadif -g 29.97 -r 23 ^
    -b:v:0 3150k  -c:v libx264  -filter:v:0 "scale=426:-1" -rc:v vbr_hq -pix_fmt yuv420p -profile:v main -level 4.1 -strict_gop 1 -rc-lookahead 32 -no-scenecut 1 -forced-idr 1  -b:a:0 128k -map 0:v -map 0:a:0 ^
    -b:v:1 4200k  -c:v libx264 -filter:v:1 "scale=640:-1" -rc:v vbr_hq -pix_fmt yuv420p -profile:v main -level 4.1 -strict_gop 1 -rc-lookahead 32 -no-scenecut 1 -forced-idr 1   -b:a:1 192k  -map 0:v -map 0:a:0 ^
    -b:v:2 5250k  -c:v libx264 -filter:v:2 "scale=1280:-1" -rc:v vbr_hq -pix_fmt yuv420p -profile:v main -level 4.1 -strict_gop 1 -rc-lookahead 32 -no-scenecut 1 -forced-idr 1  -b:a:2 256k -map 0:v -map 0:a:0 ^
     -c:a aac -ar 48000    ^
    -f hls ^
    -var_stream_map "v:0,a:0  v:1,a:1 v:2,a:2" ^
    -master_pl_name  index.m3u8 ^
    -t 30000 -hls_time 10 ^
     -hls_init_time 4 -hls_list_size 0 ^
    -master_pl_publish_rate 10 ^
    -hls_flags delete_segments+discont_start+split_by_time "../live/test/vs%%v/manifest.m3u8" 
    pause
    
  • Stream Recorder Using FFmpeg Fails on AWS Lambda

    10 mai, par user30495567

    I am trying to stream audio from URLs and save them to a file in S3 using AWS Lambda with FFmpeg. Here is an example FFmpeg command I'm using:

    ffmpeg -hide_banner -loglevel error -t 10 -i http://playerservices.streamtheworld.com/api/livestream-redirect/KTOOFMAAC_SC -ar 16000 -b:a 64k -ac 2 output.mp3
    
    • The FFmpeg command is getting called in a python script using subprocess.Popen()
    • The command works as expected on local, but does not work in an AWS Lambda python environment using a custom FFMPEG layer configured with these instructions.
    • When run on Lambda, I get the following error: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/output.mp3'

    Note: I've also tried a version where I use python requests to stream chunks and pipe them into ffmpeg. This works for some stream URLs, but for others, such as the streamtheworld URL above, it only saves ~5 seconds of audio from the stream or results in a Broken Pipe error.