Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
How to correct faulty aspect ratio with FFMPEG when encoded in both stream and container
14 mai, par Kurt FitznerI have a video that I converted from the original in a way that seems to have poisoned the aspect ratio. The intended aspect ratio is 12:5 (2.4.:1) at 1920x800 with square pixels, but the cuda scale seems to have adjusted the storage aspect ratio.
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 SAR 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.
-
Why are rectangular boxes ([]) showing instead of text in burned subtitles when using ffmpeg/MoviePy on Google Colab ?
14 mai, par LavishI'm working on a Python script that adds subtitles to a video using MoviePy and burns/hardcodes them directly onto the video. The subtitles contain Hindi text, and I’ve specified a custom font that supports Devanagari (Hindi) script.
The code works perfectly fine on my local machine, the subtitles appear correctly with Hindi characters. However, when I run the same code on Google Colab, the subtitles display as rectangular boxes (something like this -> [][][]) instead of proper characters.
Things I've tried:
- Ensured the font used supports Hindi (I'm using NotoSansDevanagari-Regular.ttf renamed as font.ttf).
- Uploaded the font to Colab and specified the full path correctly.
- Verified that the text is passed as a proper Unicode string.
Here's the code snippet:
def add_subtitles(video_path, subtitles_path, output_path): """Adds subtitles using FFmpeg with proper path escaping.""" # Convert to absolute paths and normalize video_path = os.path.abspath(video_path) subtitles_path = os.path.abspath(subtitles_path) output_path = os.path.abspath(output_path) # Subtitle path font_path = "input_files/font.ttf" font_path = os.path.abspath(font_path).replace("\\", "\\\\") subtitles_path_escaped = os.path.abspath(subtitles_path).replace("\\", "\\\\") # Escape backslashes in paths subtitles_path = subtitles_path.replace("\\", "\\\\") # Remove all files in final_videos [os.remove(os.path.join(base_dir, "final_videos", f)) for f in os.listdir(os.path.join(base_dir, "final_videos")) if os.path.isfile(os.path.join(base_dir, "final_videos", f))] os.makedirs(os.path.dirname(output_path), exist_ok=True) escaped_path = subtitles_path.replace(':', '\\:').replace('\\', '\\\\') cmd = [ "ffmpeg", "-i", video_path, "-vf", f"subtitles={escaped_path}:force_style='FontFile={font_path}'", "-c:v", "libx264", "-c:a", "copy", "-preset", "fast", "-crf", "22", output_path ] # Debug: Print the exact command being executed print("Executing:", " ".join(cmd)) try: subprocess.run(cmd, check=True, capture_output=True, text=True) print(f"✅ Success! Output saved to: {output_path}") except subprocess.CalledProcessError as e: print(f"❌ FFmpeg failed with error:\n{e.stderr}")
What could be causing this issue on Colab, and how can I get non-English subtitles (like Hindi) to render properly when burning subtitles using MoviePy/ffmpeg in a Colab environment?
-
JavaFX media issue on Ubuntu : Could not create player
14 mai, par parsa2820I am trying to play mp3 file on JavaFX-11.0.2 on Ubuntu-20.04 using JDK-13.0.2 but I keep getting this same error every time. While I was searching for that I found that JavaFX uses older version of some libraries(See this issue on github). So I compiled and installed ffmpeg-3.1.11 from source. But the same exception is thrown. I put my code and error message bellow. I stuck on this for days so I really appreciate any help. Thanks.
note : This is not duplicate qeustion. All other questions regarding to this error happend on different versions and had different causes. I tried most of them but none of them works for me.
/usr/lib/jvm/jdk-13.0.2/bin/java --module-path /opt/javafx-sdk-11.0.2/lib --add-modules=javafx.controls,javafx.fxml,javafx.media -Djava.library.path=/opt/javafx-sdk-11.0.2/lib -javaagent:/opt/idea-IU-201.7846.76/lib/idea_rt.jar=46237:/opt/idea-IU-201.7846.76/bin -Dfile.encoding=UTF-8 -classpath /home/parsa/Documents/welanner/target/classes:/opt/javafx-sdk-11.0.2/lib/src.zip:/opt/javafx-sdk-11.0.2/lib/javafx-swt.jar:/opt/javafx-sdk-11.0.2/lib/javafx.web.jar:/opt/javafx-sdk-11.0.2/lib/javafx.base.jar:/opt/javafx-sdk-11.0.2/lib/javafx.fxml.jar:/opt/javafx-sdk-11.0.2/lib/javafx.media.jar:/opt/javafx-sdk-11.0.2/lib/javafx.swing.jar:/opt/javafx-sdk-11.0.2/lib/javafx.controls.jar:/opt/javafx-sdk-11.0.2/lib/javafx.graphics.jar:/home/parsa/.m2/repository/com/google/code/gson/gson/2.8.6/gson-2.8.6.jar view.GUI Exception in Application start method java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:567) at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464) at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:567) at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051) Caused by: java.lang.RuntimeException: Exception in Application start method at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900) at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195) at java.base/java.lang.Thread.run(Thread.java:830) Caused by: MediaException: UNKNOWN : com.sun.media.jfxmedia.MediaException: Could not create player! : com.sun.media.jfxmedia.MediaException: Could not create player! at javafx.media/javafx.scene.media.MediaException.exceptionToMediaException(MediaException.java:146) at javafx.media/javafx.scene.media.MediaPlayer.init(MediaPlayer.java:518) at javafx.media/javafx.scene.media.MediaPlayer.
(MediaPlayer.java:421) at view.GUI.start(GUI.java:13) at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846) at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455) at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428) at java.base/java.security.AccessController.doPrivileged(AccessController.java:391) at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427) at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96) at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method) at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277) ... 1 more Caused by: com.sun.media.jfxmedia.MediaException: Could not create player! at javafx.media/com.sun.media.jfxmediaimpl.NativeMediaManager.getPlayer(NativeMediaManager.java:295) at javafx.media/com.sun.media.jfxmedia.MediaManager.getPlayer(MediaManager.java:118) at javafx.media/javafx.scene.media.MediaPlayer.init(MediaPlayer.java:474) ... 11 more Exception running application view.GUI Process finished with exit code 1 This is my code. I know path and other things are correct because I can run it on Windows properly.
package view; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; import javafx.stage.Stage; import java.io.File; public class GUI extends javafx.application.Application{ public void start(Stage stage) throws Exception { String path = "/home/parsa/Music/Ninoush.mp3"; Media media = new Media(new File(path).toURI().toString()); MediaPlayer mediaPlayer = new MediaPlayer(media); mediaPlayer.setAutoPlay(true); stage.setTitle("Playing audio"); stage.show(); } public static void main(String[] args) { launch(args); } }
This is my ffmpeg and libraries versions :
ffmpeg version 3.1.11 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 9 (Ubuntu 9.3.0-10ubuntu2) configuration: libavutil 55. 28.100 / 55. 28.100 libavcodec 57. 48.101 / 57. 48.101 libavformat 57. 41.100 / 57. 41.100 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 47.100 / 6. 47.100 libswscale 4. 1.100 / 4. 1.100 libswresample 2. 1.100 / 2. 1.100
Edit 3 : I can play wav file this way but I can't play mp3.
-
FFmpeg drawtext over multiple lines [closed]
13 mai, par JayI have the code:
C:\ffmpeg_10_6_11.exe -i C:\test_in.avi -vf drawtext=fontfile=/Windows/Fonts/arial.ttf:text="onLine1 onLine2 onLine3":fontcolor=white:fontsize=20 -y C:\test_out.avi
to write text to a video file. But I want to write out many lines of text instead of just having it all on the one line.
How can I do that?
-
How can I run FFPROBE in a Python script without triggering the Windows Command window ?
13 mai, par fnord12I am using ffmeg/ffprobe to get video durations (in an addon for Kodi). The code:
result = subprocess.run(["ffprobe", "-hide_banner", "-v", "quiet", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", filename], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
The above code and the file importing that code both have a .pyw extension (after first trying regular .py).
This works fine but in Windows 11 it causes the black Windows Command window to briefly flash for each video, despite the -hide_banner flag and loglevel being set to quiet. In Linux Mint it runs without any such window popping up.
Is there any way to suppress the Windows Command window?