Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
Converting mkv files to mp4 with ffmpeg-python
16 mai, par myth0sI 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 interact with process output ?
14 mai, par 1ben99Ok so at the moment I have a program which runs FFmpeg using a process in VB.net. I send the process arguments in the startinfo as well as other things like the file location. When I run the code it sends the console output to the debug console; this is probably because I have the .UseShellExecute = False and processInfo.RedirectStandardOutput = True
My question is: How do I make something which can interpret the output? Also with FFmpeg, the process is continuous so the process is always running for the most part and constantly adding more output lines in the debug console.
The code I am using:
Dim process As New Process Dim processInfo As New ProcessStartInfo processInfo.FileName = tempPath processInfo.Arguments = ("-r 1/.1 -i " + link + " -c copy " + saveLocation + "\" + streamerName + ".ts") processInfo.UseShellExecute = False processInfo.WindowStyle = ProcessWindowStyle.Hidden processInfo.CreateNoWindow = True processInfo.RedirectStandardOutput = True process.StartInfo = processInfo process.Start()
I tried this with no luck.
Dim output As String Using StreamReader As System.IO.StreamReader = process.StandardOutput output = StreamReader.ReadToEnd().ToString End Using
Edit: I now have this code:
Dim process As New Process AddHandler process.OutputDataReceived, AddressOf CallbackProcesoAsync AddHandler process.ErrorDataReceived, AddressOf ErrorDataReceivedAsync Dim processInfo As New ProcessStartInfo processInfo.FileName = tempPath processInfo.Arguments = ("-r 1/.1 -i " + link + " -c copy " + saveLocation + "\" + streamerName + ".ts") processInfo.UseShellExecute = False processInfo.WindowStyle = ProcessWindowStyle.Hidden processInfo.CreateNoWindow = False processInfo.RedirectStandardOutput = True processInfo.RedirectStandardError = True process.StartInfo = processInfo process.Start() processes.Add(Tuple.Create(tempPath, streamerName)) Debug.WriteLine("Attempting to record " + streamerName) Dim output As String Using StreamReader As System.IO.StreamReader = process.StandardOutput output = StreamReader.ReadToEnd().ToString End Using End If End Sub Private Sub CallbackProcesoAsync(sender As Object, args As System.Diagnostics.DataReceivedEventArgs) If Not args.Data Is Nothing AndAlso Not String.IsNullOrEmpty(args.Data) Then RichTextBox1.Text = args.Data End If End Sub Private Sub ErrorDataReceivedAsync(sender As Object, args As System.Diagnostics.DataReceivedEventArgs) If Not args.Data Is Nothing AndAlso Not String.IsNullOrEmpty(args.Data) Then RichTextBox2.Text = args.Data End If End Sub
But I have not recieved any outputs to the richtextboxes?
I feel like it has something to do with the streamReader so I removed it and it still didn't work? I don't have any more ideas what it could be.
-
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.