Comments (10)
The weird thing is, the code works with this line and no changes var processor = arguments.OutputToFile(@"output_test.mp4");
but var processor = arguments.OutputToPipe(new StreamPipeSink(output));
does not work.
from ffmpegcore.
Also, when I run FFMpeg using the command line I can convert my files without issue.
Command: ffmpeg -i "input.avi" "output.mp4"
from ffmpegcore.
Is there a reason for not using .FromInputFiles(..).ToOutputFile(..)
?
from ffmpegcore.
@rosenbjerg I was trying to do everything in memory, reading from a file stream and writing to a memory stream. I do not want to save the output file, I want to send the output stream to another destination, that's why I am opting for a memory stream.
from ffmpegcore.
Okay. What sort of stream are you outputting to?
Have you tried from file to pipe? It seems you are using an input file, from your example
from ffmpegcore.
@Agrejus Hi, this might be an issue with mp4
container cause it requires seeking when encoding. Try different container, for example mov
or webm
, as i remember it works with them
from ffmpegcore.
@rosenbjerg I am trying to output to a MemoryStream. I tried from file to pipe and I get a different error, this time with FFMpeg. I suspect that would work if I could get my parameters correct. Error is:
[mp4 @ 00000234cf5120c0] muxer does not support non seekable output
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 --
[aac @ 00000234cefa7980] Qavg: 10458.081
[aac @ 00000234cefa7980] 2 frames left in the queue on closing
@max619 webm
does work! Thank you
from ffmpegcore.
@rosenbjerg It does work in memory if I output to a webm
instead of mp4
. I believe we can consider this resolved. Not sure why it says pipe broken
for an mp4
, but webm
works.
from ffmpegcore.
That might be because FFMpeg tries to seek in the stream when using mp4, as Max explains.
From the FFMpeg output you posted, it seems Max was spot on :)
Max is the expert on the piping support in this library. He implemented it
I'll close this issue now that your problem is solved :)
from ffmpegcore.
Sorry for raising the issue.
My research took a lot of time. I hope it helps someone.
var source = await _fileService.UploadAsync("videos", request.Video);
var startTime = TimeSpan.FromSeconds(20);
var duration = TimeSpan.FromSeconds(10);
using var outputStream = new MemoryStream();
await FFMpegArguments.FromUrlInput(new Uri(source), options => options
.WithCustomArgument("-ss " + startTime.ToString(@"hh\:mm\:ss"))
.WithDuration(duration))
.OutputToPipe(new StreamPipeSink(outputStream), options => options
.ForceFormat(VideoType.Mp4)
.WithCustomArgument("-movflags frag_keyframe+empty_moov"))
.ProcessAsynchronously();
var outputData = outputStream.ToArray();
In detail, the code consists of the following steps:
-
The first line calls the "_fileService.UploadAsync" method to upload the video file and assigns the result to the "source" variable.
-
The second line assigns the starting time of the segment to the "startTime" variable and the duration of the cut to the "duration" variable.
-
The third line creates a "MemoryStream" object which will be used as a memory stream to write the cut video data to.
-
On the fourth line, an argument is created using the FFMpegArguments library to mark the video to be cut during the specified start time and duration.
-
On the fifth line, the cut video with the specified settings is written to the memory stream using the "OutputToPipe" method.
-
On the sixth line, the "ForceFormat" method is called to save the video in the MP4 format, with the "frag_keyframe+empty_moov" properties.
-
Finally, the "ProcessAsynchronously" method is used to start the process asynchronously, and the cut video is returned as a byte array using the "outputStream.ToArray()" method.
from ffmpegcore.
Related Issues (20)
- Time parsing error when transcoding long than 24 hours
- Conversion M4A, MOV to MP3 file
- Cannot use HardwareAccelerationDevice.Auto with ffmpeg 6.1.0 HOT 1
- Cant convert Stream on Linux container HOT 1
- ThrowIfInputFileDoesNotExist when HTTP source is used HOT 1
- I need a sample how to add subtitles to video HOT 1
- Is there any documentation for FFMpegArgumentOptions?
- In memory snapshot is not available anymore ? HOT 2
- What ForceFormat for Libx265?
- Error getting snapshop from AVI file
- The type initializer for 'FFMpegCore.Enums.FileExtension' threw an exception HOT 4
- Issue with duration for audio - ffprobe
- moov atom not found
- Multiple pipeline input example HOT 1
- Subtitles not working on Azure Function
- Audio Filters HOT 1
- How did you release `Bitmap` when you're piping on the fly?
- Is it possible to convert wav to mp3 on ubuntu with FFMpegCore and .net core ?
- No .MultiOutput in FFMpegArguments in current (5.1.0) version from nuget
- How to Join Images Async with Progression Tracking?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ffmpegcore.