Im using Xabe.FFmpeg with .Net Core for writing AWS Lambda function and it will be dockrized.
Initially the file needs to be resized using FFMpeg is saved in the /tmp/c69fa491523147c2a92d9ef11a68982e/input.mp4 location from S3 before starting the conversion. I manually checked the physical existant of that file and it is a valid .mp4 file.
But, while starting the Process with FFMpeg, Im getiing this error Invalid file. Cannot load file "/tmp/c69fa491523147c2a92d9ef11a68982e/input.mp4"
The code I used for resizing is -
var localInputFile = "/tmp/c69fa491523147c2a92d9ef11a68982e/input.mp4";
var localOutputFile= "/tmp/c69fa491523147c2a92d9ef11a68982e/output.mp4";
var conversion = await FFmpeg.Conversions.FromSnippet.ChangeSize(localInputFile, localOutputFile, VideoSize.Hd720);
conversion.OnProgress += (object sender, Xabe.FFmpeg.Events.ConversionProgressEventArgs args) =>
{
context.Logger.LogInformation($"{args.Percent}%");
};
context.Logger.LogInformation($"Starting conversion - {localOutputFile}");
Any idea why I'm getting this?
Note:
Docker base image is - public.ecr.aws/lambda/dotnet:6
FFMpeg.exe location is /tmp/ffmpeg.exe
sd
The code dll is on /var/task location
Related
I am writing a Dart package (not Flutter). I have included a few bitmap images as public assets, e.g., lib/assets/empty.png. When this package is running as a command-line app for an end-user, how can I get the file path to these assets on the user's system?
Use-case: My Dart package calls out to FFMPEG, and I need to tell FFMPEG where to find these asset files on the system that's using my package. For example, the call to FFMPEG might look like:
ffmpeg -i "path/to/lib/assets/empty.png" ...
Accessing a Dart package's assets can happen in two modalities:
Running a Dart CLI app with the dart tool and accessing a dependency's assets, or
Running an executable CLI app
The difference between these two situations is that when you're running a CLI app using the dart tool, all of your dependencies are available as structured packages in a local cache on your system. However, when you're running an executable, all relevant code is compiled into a single binary, which means you no longer have access at runtime to your dependencies' packages, you only have access to your dependencies' tree-shaken, compiled code.
Accessing assets when running with dart
The following code will resolve a package asset URI to a file system path.
final packageUri = Uri.parse('package:your_package/your/asset/path/some_file.whatever');
final future = Isolate.resolvePackageUri(packageUri);
// waitFor is strongly discouraged in general, but it is accepted as the
// only reasonable way to load package assets outside of Flutter.
// ignore: deprecated_member_use
final absoluteUri = waitFor(future, timeout: const Duration(seconds: 5));
final file = File.fromUri(absoluteUri);
if (file.existsSync()) {
return file.path;
}
This resolution code was adapted from Tim Sneath's winmd package: https://github.com/timsneath/winmd/blob/main/lib/src/metadatastore.dart#L84-L106
Accessing assets when running an executable
When compiling a client app to an executable, that client app simply cannot access any asset files that were stored with the dependent package. However, there is a work around that may work for some people (it did for me). You can store Base64 encoded versions of your assets in your Dart code, within your package.
First, encode each of your assets into a Base64 string and store those strings somewhere in your Dart code.
const myAsset = "iVBORw0KGgoAAA....kJggg==";
Then, at runtime, decode the string back to bytes, and then write those bytes to a new file on the local file system. Here's the method I used in my case:
/// Writes this asset to a new file on the host's file system.
///
/// The file is written to [destinationDirectory], or the current
/// working directory, if no destination is provided.
String inflateToLocalFile([Directory? destinationDirectory]) {
final directory = destinationDirectory ?? Directory.current;
final file = File(directory.path + Platform.pathSeparator + fileName);
file.createSync(recursive: true);
final decodedBytes = base64Decode(base64encoded);
file.writeAsBytesSync(decodedBytes);
return file.path;
}
This approach was suggested by #passsy
Have a look at the dcli package.
It has a 'pack' command designed to solve exactly this problem.
It encodes assets into dart files that can be unpacked at runtime.
When I try to convert video using MediaToolkit in the local system, then it's working fine, but the same project when I run in docker then output file not saved in the given path.
Also, the output file is not saved in the directory so I am getting null metadata.
Here is my code
using (var engine = new Engine())
{
engine.Convert(inputFile, outputFile, conversionOptions);
engine.GetMetadata(outputFile);
engine.Dispose();
}
FileInfo outputFileInfo = new FileInfo(outputFile.Filename);
Error - Could not find file '/app/e77f2017-ef6e-4115-ba00-73a5c09941a9.mp4'
Can anyone please help me with this?
check the current path (you are working relative)
the program might not run from you think and then "app" directory is not found.
I am working on asp.net MVC project.
I use ExcelDataReader component to read excel file records.
Now when I published my project to server and upload a .xlsx file with uploader I get below mentioned exception message. There are no errors with local deployment but server.
Access to the path '\Microsoft Corporation\Internet Information
Services\7.5.7600.16385' is denied.
and code where I am getting error is:
if (personsFile.FileExtension == ".xls")
{
Stream st = new MemoryStream(personsFile.FileArray);
reader = ExcelReaderFactory.CreateBinaryReader(st);
}
else if (personsFile.FileExtension == ".xlsx")
{
Stream st = new MemoryStream(personsFile.FileArray);
//exception occured on under line
reader = ExcelReaderFactory.CreateOpenXmlReader(st);
}
But when I upload a .xls file, I dont have any error.
How to resolve issue with .xlsx extenstion?
This is most likely due to ExcelDataReader 2.x extracting the xlsx archive to %TEMP% before processing it. The current pre-alpha of 3.0 no longer does this. See https://github.com/ExcelDataReader/ExcelDataReader/releases.
I have a .swf file which throws this error when I attempt to load it in a browser. Similar to other posts here this is the code:
var mySpite:Sprite = new Sprite();
var button:Loader = new Loader();
var url:String = "images/btnImage.png";
var urlReq:URLRequest = new URLRequest(url);
button.load(urlReq);
....
When I run the actionscript in Flex Build it works fine. Also when I double click the .swf file in the folder where it is stored, it works fine. I don't know why it only doesn't work and throws this error when I load it in a .jsp page.
It's most likely an issue with your path. Remember that the path to the image will be relative to the page which embeds the SWF.
In answer to your comment about having to change the paths when deploying, depending on how you're building and debugging your SWF, it might be possible to use Capabilities.playerType (see docs) to choose the correct path for the current environment. Another alternative might be to put all your image references in a couple of XML files (one local and one remote). As long as the path to the XML file is consistent between local and remote environments, you can update the SWF without worrying about the image paths.
I am new to Struts and working on File Upload using Struts.
Client:
It is Java Program which hits my Strut app by using apache HttpClient API and provides me
File.
Client as per need sometime gives me .wav file and sometime .zip file and sometime both.
Server:
Struts app which got the request from client app and upload the file.
Here, problem comes as I upload the file, it get uploaded using ".tmp" extension, which I want to get uploaded with the same extension what client has passed.
Or there is any other way by which we can check what is the extension of the file client has sent....?
I am stuck in this problem and not able to go ahead.
Please Find the code attached and tell me what modification I have to do:
Server Code:
MultiPartRequestWrapper multiWrapper=null;
File baseFile=null;
System.out.println("inside do post");
multiWrapper = ((MultiPartRequestWrapper)request);
Enumeration e = multiWrapper.getFileParameterNames();
while (e.hasMoreElements()) {
// get the value of this input tag
String inputValue = (String) e.nextElement();
// Get a File object for the uploaded File
File[] file = multiWrapper.getFiles(inputValue);
// If it's null the upload failed
if (file != null) {
FileInputStream fis=new FileInputStream(file[0]);
System.out.println(file[0].getAbsolutePath());
System.out.println(fis);
int ch;
while((ch=fis.read())!=-1){
System.out.print((char)ch);
}
}
}
System.out.println("III :"+multiWrapper.getParameter("method"));
Client code:
HttpClient client = new HttpClient();
MultipartPostMethod mPost = new MultipartPostMethod(url);
File zipFile = new File("D:\\a.zip");
File wavFile = new File("D:\\b.wav");
mPost.addParameter("recipientFile", zipFile);
mPost.addParameter("promptFile", wavFile);
mPost.addParameter("method", "addCampaign");
statusCode1 = client.executeMethod(mPost);
actually Client is written long back and cant be modified and I want to identify something at server side only to find the extension.
Please help, Thanks.
Struts2 File Uploader interceptor when uploading file pass the content type information to the Action class and one can easily find the file type by comparing contentType with MIME type.
If you want to can create a map with key as content type and file type as its value like
map.Add("image/bmp",".bmp", )
map.Add("image/gif",".gif", )
map.Add("image/jpeg",".jpeg", )
and can easily fetch the type based on the extension provides.Hope this will help you.