Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
How to split an audio / video file based upon multiple timestamps by using FFMPEG (preferably)
19 février, par badr2001I would like to be able to split my audio (mp3 or equiv.) or video file based upon multiple timestamps. The same way, for those who have used any editing software, you can crop the file based upon selecting a start time and end time.
What I have done so far:
[HttpPost] public async Task
ProcessFullAudio([FromBody] ProcessFullAudioRequest processFullAudioRequest) { if (processFullAudioRequest == null || processFullAudioRequest.StartEndTimes == null || processFullAudioRequest.StartEndTimes.Length == 0) { throw new ArgumentException("Invalid request: StartEndTimes cannot be null or empty."); } var timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss"); var fileName = $"{Guid.NewGuid()}_{timestamp}.mp3"; var outputFilePath = Path.Combine(customFolder, fileName); int amntOfTimeStamps = processFullAudioRequest.StartEndTimes.Length; int step = 0; string lineOfCodeForFirstTime = " \"aselect='not(between(t, , )"; string lineOfCodeForRestOfTimes = "+between(t, , )"; string argument = ""; string result = null; string filterComplex = GenerateAtrims(processFullAudioRequest.StartEndTimes); while (step != amntOfTimeStamps) { step++; if (step == 1) { result = ReplacePlaceholders(lineOfCodeForFirstTime, HhMmSsToSeconds(processFullAudioRequest.StartEndTimes[step - 1].Start).ToString() , HhMmSsToSeconds(processFullAudioRequest.StartEndTimes[step - 1].End).ToString()); argument += result; } else { result = ReplacePlaceholders(lineOfCodeForRestOfTimes, HhMmSsToSeconds(processFullAudioRequest.StartEndTimes[step - 1].Start).ToString() , HhMmSsToSeconds(processFullAudioRequest.StartEndTimes[step - 1].End).ToString()); argument += result; } } var FFMPEG_PATH = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "ffmpeg.exe"); if (!System.IO.File.Exists(FFMPEG_PATH)) { return "ffmpeg.exe IS NULL"; } var arguments = $"-i {processFullAudioRequest.InputFilePath} -af {argument})' ,asetpts=N/SR/TB\" -acodec libmp3lame {outputFilePath}"; await ProcessAsyncHelper.ExecuteShellCommand(FFMPEG_PATH, arguments, Timeout.Infinite); return outputFilePath; } The code, I hope, is self explanatory. The argument variable should like something like this:
-i C:\Users\User\Desktop\AudioEditorBackEnmd\AudioEditorAPI\wwwroot\mp3\TestAudio_123.mp3 -af "aselect='not(between(t,120,240))' ,asetpts=N/SR/TB" -acodec libmp3lame C:\Users\User\Desktop\AudioEditorBackEnmd\AudioEditorAPI\wwwroot\mp3\aa887f21-0a90-4ec5-80ba-2b265cb445b4_20250219_123804.mp3
After returning the output path for the newly processed edited audio, I pass it to my DownloadFile function:
[HttpGet] public async Task
DownloadProcessedFile([FromQuery] string fileName) { if (string.IsNullOrWhiteSpace(fileName)) { return BadRequest("File name is required."); } var filePath = Path.Combine(customFolder, fileName); if (!System.IO.File.Exists(filePath)) { return NotFound(new { fileName }); } try { var fileBytes = await System.IO.File.ReadAllBytesAsync(filePath); return File(fileBytes, "audio/mpeg", fileName); } catch (Exception ex) { throw; } } Everything works, in the sense off, I am able to get an processed file which is shorter than the original audio. However the issue is that the timestamps are off. For example, in the argument that I provided above, I am cropping the audio from 120 to 240, which is from the 2 min mark till the 4 min mark. The audio which I am passing is 01:06:53 however the processed audio gives me back 1:05:22 which is not excepted as I should be getting 01:04:53.
The annoying thing is that I was getting the desired output at one point. Im not sure what changes caused the timestamps to become off. The only changes which I did was changing the file locations to my wwwroot folder.
I have tried many different variations of commands to get a desired output but can't seem to get anything close - I always get 1:05:22 back. From the commands that I tired was:
var arguments = $"-i {processFullAudioRequest.InputFilePath} -af {argument})' , asetpts=N/SR/TB\" -c:a libmp3lame -q:a 2 {outputFilePath}";
I tried so many more but I simply can't remember. And now I feel like I have reached a hard wall in coming up with a solution for this.
Any help I would much appreciate. I have tried to give as much detail as I can but if anything remains please let me know.
-
Extract undecoded audio payload from song file ?
19 février, par GabrielWhat tools are available to extract the raw undecoded audio payload from a song file?
I am looking for a solution that will work on wma, m4a, mp3, and ogg files.
One of the purposes is to be able to calculate the md5sum of the audio payload.
I tried
ffmpeg -i
but this actually does a decoding pass which is not desired. Also this seems to produce different results depending on the versions of the decoders in use.-f md5 - I tried
ffmpeg -i
but ffmpeg complains that it does not know the desired output format even though-acodec copy - > copy
is explicitly specified.I've tried various incarnations of
-map_metadata -1
but the documentation is obtuse at best.In the end the ideal is to have an stdout of the raw UNdecoded audio portion of a song file.
Any ideas?
-
How can i create a stable checksum of a media file ?
19 février, par yawniekhow can i create a checksum of only the media data without the metadata to get a stable identification for a media file. preferably an cross platform approach with a library that has support for many formats. e.g. vlc, ffmpeg or mplayer.
(media files should be audio and video in common formats, images would be nice to have too)
-
How can a desktop node.js app play audio that may be controlled by the user like a media player ? [closed]
19 février, par eedefeedI'm building a playlist manager that plays music. How can Node.JS play audio files quickly, reliably and with all the basic level features you would expect from a media player, namely:
- play
- pause
- seek
- stop
- adjust volume
I'm targetting windows/linux, but a Windows-only solution but be okay (for now.)
I have tried a number of libraries and methods to play audio but it seems none of them are good enough:
- Audic: it's reasonably good, but buggy. The play and pause functions sometimes get switched around. I also recall that there are some issues with uncaught exceptions somewhere in the dependencies that crash the entire app.
- OBS: since the app is designed with broadcasting in mind, I've tried to use OBS's API to get it to play media. Unfortunately, it sometimes stops playback during some tracks, which is surprising since its underlying library, FFmpeg, plays them without issue.
- node-groove: seems like its underlying library, libgroove, only supports linux. I can't find any builds to download, regardless.
Attempts to use Speaker (which seems pretty good) have also failed because all the decoders have big issues:
- Anything using lame - I want support for all audio, not specific formats.
- fluent-FFmpeg - this is a wrapper around FFmpeg's CLI interface. It has no play/pause function, but bonus library fluent-FFmpeg-util adds this feature. Unfortunately, its pause takes about 4 seconds to work, which I'm guessing is to do with a buffer being exhausted. This is just too latent. Seek would also work by stopping the CLI process and reloading the file, which seems massively inefficient.
- Node Vlc - promising but ancient library that gives me reams of node-gyp errors on install. Poorly documented and no explanation of what the library to do
- VLC Client - this library has uncaught exceptions that crash the app. Wrapping in try/catch doesn't help.
- sound play - doesn't support play/pause
NPM's search function is filled with audio players designed to work in browsers, but I'm not building a web app. I guess it's an option but it seems inelegant to the point of rediculous.
So it seems the best option centres around FFmpeg. FFmpeg has libraries, and I'm aware that node has ways to hook into those libraries via some sort of C or C++ compatibility layer. Unfortunately, official documentation is rather dense. Different unofficial guides seem to be recommending conflicting approaches (and might be dated), and it's difficult to work out whether myriad technologies are working in tandem or are alternatives, renames or replacements: node-gyp, node-api, addons, windows-build-tools, nan, C vs C++, Visual Studio. It's difficult to make any decisions or know where to start.
Perhaps, also, another option is to use a Python library to interact with FFmpeg, since initial searches have indicated this might be possible. I wouldn't know whether this is a good option.
So my question is: what's my best option to play audio? Is it another NPM module that I'm not aware of? Is it a compatibility layer with FFmpeg libraries?
-
How to Identify the Version of ffmpeg.dll in WebView2 Runtime Fixed Version
19 février, par Po-SenI am currently using the WebView2 runtime fixed version. After expanding the package, I found multiple DLL files, including
ffmpeg.dll
.In the file properties, the
file version
is displayed as0.0.0.0
, and the only version-related information I can see is theproduct version
:git-2024-04-25-e3581fa2dd
.This format is different from the numeric versioning scheme I see on the official FFmpeg website: https://ffmpeg.org/download.html#releases.
I want to trace the exact FFmpeg version used in this WebView2 distribution. Initially, I assumed
e3581fa2dd
was a Git commit SHA. However, after cloning the FFmpeg repository from https://git.ffmpeg.org/ffmpeg.git, I could not find this commit.Our product was recently scanned and found to contain FFmpeg version
3.4.2
, which has knownCVE
security vulnerabilities. Therefore, we want to clarify the actual version of FFmpeg included in the WebView2 runtime.How can I determine the version of
ffmpeg.dll
included in WebView2 runtime fixed version?