The result of the power shell window
I saw a post on here about converting m4s to mp4 and I have followed the steps of concatenating all the files into another m4s file that I called all.m4s and when I use the command ffmpeg -i allm4s.m4s -c copy video.mp4. I made the combined m4s file by coding an exe to add all the m4s files that have the word video in them to the m4s file. Here is the source code written in c# if you compile the code then that is the code I have used to make the m4s
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace files
{
class Program
{
static void Main(string[] args)
{
string dir = Directory.GetCurrentDirectory();
string[] info = Directory.GetFiles(dir);
Console.WriteLine(dir + "\\allm4s.m4s");
Console.ReadKey();
foreach (string name in info)
{
if (Path.GetFileName(name).Contains(".m4s") && Path.GetFileName(name).Contains("video"))
{
using (Stream srcStream = File.OpenRead(name))
{
using (Stream destStream = File.OpenWrite(dir+"\\allm4s.m4s"))
{
srcStream.CopyTo(destStream);
Console.WriteLine(destStream+name);
}
}
}
}
Console.ReadKey();
}
}
}
I think if there is to be an issue it is to do with this allm4s.m4s file as the file size is about 1.5mb even though each segment m4s is about 750kb each and there are quite a lot.If anyone has a way of adding concatenating lots of files together through a program/application that would be useful.
You are getting that error because you might be concatenating videos of different dimensions.
all your input file's full names are stored in input array
Java Program
String inputStr="";
String stream="";
for(int index=0;index<input.length;index++){
inputStr=inputStr+" -i "+input[index];
stream =stream +"["+index+":v]"+"["+index+":a]"; //gets audio and video stream of file
}
String command = "ffmpeg "+inputStr+" -filter_complex \" "+stream+" concat=n="+(index-1)+ \
":v=1:a=1 [v] [a] \" "+ "-map \"[v]\" -map \"[a]\" outputfile.m4s"
Runtime.getRuntime(command).exec().waitFor();//runs ffmpeg command to concat all files
Related
I am creating a console application that will modify dicom tags. I will load up a single dicom file and update the PatientID tag.
I can not seem to to get anything to modify. I am able to read tags, but updating/adding does not seem to work for me. Previously I have used the DICOM ToolKit on powershell and it is very straight forward and easy, but I want to start developing in c# and so far I am failing.
using System;
using System.IO;
using SpiromicsImporterPrep.FileMethods;
using Dicom;
namespace SpiromicsImporterPrep
{
class Program
{
static void Main(string[] args)
{
string filename = #"Z:\SPIROMICS\Human_Scans\Dispatch_Received\NO_BACKUP_DONE_HERE\MIFAR\FORCE\JH114062-FU4\119755500\Non_Con_FRC__0.75__Qr40__5_7094\IM001139";
var file = DicomFile.Open(filename, readOption: FileReadOption.ReadAll);
var dicomDataset = file.Dataset;
dicomDataset.AddOrUpdate(DicomTag.PatientID, "TEST-PATIENT");
}
}
}
I expect after running the code when I look at the Dicom Header tags for this file with ImageJ or and other dicom reader that the value for the PatientID tag will be "TEST-PATIENT" The code runs with no errors but nothing seems to be updated or changed when I look at the dicom header.
you should invoke DicomFile.Save() Method.
string[] files = System.IO.Directory.GetFiles(#"D:\AcquiredImages\20191107\1.2.826.0.1.3680043.2.461.11107149.3266627937\1.2.276.0.7230010.3.1.3.3632557514.6848.1573106796.739");
foreach (var item in files)
{
DicomFile dicomFile = DicomFile.Open(item,FileReadOption.ReadAll);
dicomFile.Dataset.AddOrUpdate<string>(DicomTag.PatientName, "abc");
dicomFile.Save(item);
}
FileReadOption.ReadAll is required.
I have created a high score file for my game and I am having problems reading it.
When I change computers my USB drive changes letter .eg from drive E to drive G.
This is causing problems with reading the file. (as I use string path = #"g:\Scores.txt";)
So my question is.... can I set a default path to the program location??
My current code:-
string path = #"g:\Scores.txt";
StringBuilder sb = new StringBuilder();
using (StreamReader sr = new StreamReader(path))
{
while (sr.Peek() >= 0)
{
sb.Append(sr.ReadLine());
}
}
any help is appreciated.
Is the game on your USB drive as well? Do you want to save the file in the same directory as the game, or in a directory somewhere around it? Do something like this:
using System;
using System.IO;
using System.Reflection;
...
string thisAsmFile = Assembly.GetExecutingAssembly().Location;
string thisAsmDir = Path.GetDirectoryName(thisAsmPath);
string highScoreFile = Path.Combine(thisAsmDir, "scores.txt");
If your program is in the same folder as the file ( Eg. in G:\ ), then you can simply access the file with his name : `path = "Scores.txt".
In that case there is no need to know where is the file
You should use your application path, not an absolute path.
You may do something like this:
using System.IO;
using System.Windows.Forms;
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
I'm creating a simple program that takes a string, sends it to Google's text to speech server, and downloads the text to speech in a mp3/wav file on the computer. I have the code below, but it only works with up to 100 characters (Google's limit). How can I make a loop to cut the string into 100 character parts and then save it in one mp3/wav file on the computer? I know this is possible with javascript and actionscript (as I have seen them) but how can I do this in C#?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Threading;
namespace TestCSharp
{
class Program
{
static void Main(string[] args)
{
WebClient web = new WebClient();
web.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/4.0 (compatible; MSIE 9.0; Windows;)");
string encstr = string.Empty;
string filename = "tts.mp3"; //could also be tts.wav
string s = "This string cannot be more than 100 characters.";
encstr = Uri.EscapeDataString(s);
Console.WriteLine(encstr);
web.DownloadFile("http://translate.google.com/translate_tts?tl=en&q=" + encstr, ".\\" + filename);
}
}
}
This is not a direct answer, but I think the splitting is not good because TTS has word intonation as well as sentence intonation. Instead, I recommend you use SpeechSynthesizer Class with free TTS engine. However, I don't know which TTS engine is good as free and where it is. If finding goodness, I'll post it.
UPDATED
MP3 files are just concatenated without a problem, from this question.
well, before I get to concatenating the mp3 files, how would the while
loop look like to first get those mp3 files on the computer? if i go
through my loop, the tts.mp3 file would be overwritten and i would be
left with only the last 100 character string that was received..
You can merge the two files like the code below.
Finally, the fs1 will get all content.
string tts1 = "tts1.mp3";
string tts2 = "tts2.mp3";
FileStream fs1 = null;
FileStream fs2 = null;
try
{
fs1 = File.Open(tts1, FileMode.Append);
fs2 = File.Open(tts2, FileMode.Open);
byte[] fs2Content = new byte[fs2.Length];
fs2.Read(fs2Content, 0, (int)fs2.Length);
fs1.Write(fs2Content, 0, (int)fs2.Length);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + " : " + ex.StackTrace);
}
finally
{
fs1.Close();
fs2.Close();
}
Basically I'm trying to compress a file "sample.doc" into the .gz file format. When this happens, it is told to remove the extension of the file so instead of appearing as
"sample.doc.gz" it appears as "sample.gz". However, when the file is extracted it has also lost its ".doc" file extension. eg. filename is just "sample". Any ideas?
using System;
using System.IO;
using System.IO.Compression;
using System.Text;
namespace gzipexample
{
class Program
{
public static void Main()
{
CompressFile(#"C:\sample.doc");
}
//Compresses the file into a .gz file
public static void CompressFile(string path)
{
string compressedPath = path;
Console.WriteLine("Compressing: " + path);
int extIndex = compressedPath.LastIndexOf(".");
FileStream sourceFile = File.OpenRead(path);
FileStream destinationFile = File.Create(compressedPath.Replace(compressedPath.Substring(extIndex), "") + ".gz");
byte[] buffer = new byte[sourceFile.Length];
sourceFile.Read(buffer, 0, buffer.Length);
using (GZipStream output = new GZipStream(destinationFile,
CompressionMode.Compress))
{
Console.WriteLine("Compressing {0} to {1}.", sourceFile.Name,
destinationFile.Name, false);
output.Write(buffer, 0, buffer.Length);
}
// Close the files.
sourceFile.Close();
destinationFile.Close();
}
}
}
If I'm understanding your question correctly, there is no solution as stated. A gzip'ed file (at least, a file gzip'ed the way you're doing it) doesn't store its name, so if you compress a file named sample.doc and the output is named sample.gz, the ".doc" part is gone forever. That's why if you compress a file with the gzip command-line utility, it the compressed version sample.doc.gz.
In some constrained situations, you might be able to guess an appropriate extension by looking at the contents of the file, but that isn't very reliable. If you just need compression, and the file format isn't constrained, you could just build a .zip file instead, which does store filenames.
I am not a programmer, but I am a researcher and I need to modify some files.
I have a number of text files with *.mol extension located in c:\abc\ directory . I need to append line containing following text "M END" to each file in this list. I tried following in C# but without any result:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
StreamWriter sw = new StreamWriter("c:\\abc\\*.mol", true);
sw.WriteLine("M END");
sw.Close();
}
}
}
Please, suggest the solution.
Thank You!
Would you be satisfied with this oneliner that you can put in any DOS batch (.bat) file:
FOR %%I IN (c:\abc\*.mol) DO ECHO M END>>%%I
foreach (string fileName in Directory.GetFiles("directory", "*.mol"))
{
File.AppendAllText(fileName, Environment.NewLine + "M END");
}
You'll need to loop through all the files matching that pattern and write to them individually. The StreamWriter constructor you're using only supports writing to an individual file (source).
You can get a list of files using:
string[] filePaths = Directory.GetFiles("c:\\abc\\", "*.mol");
You need to iterate over the files in the directory. DirectoryInfo / FileInfo makes it easy to do this. Also, since you want to append to the end, you need to seek the stream before writing your signature at the end.
Here's a solution that works solely at that location. You will need to add recursive support to descend into subdirectories if desired.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace appender
{
class Program
{
static void AppendToFile(FileInfo fi)
{
if (!fi.Exists) { return; }
using (Stream stm = fi.OpenWrite())
{
stm.Seek(0, SeekOrigin.End);
using (StreamWriter output = new StreamWriter(stm))
{
output.WriteLine("M END");
output.Close();
}
}
}
static void Main(string[] args)
{
DirectoryInfo di = new DirectoryInfo("C:\\abc\\");
FileInfo[] fiItems = di.GetFiles("*.mol");
foreach (FileInfo fi in fiItems)
{
AppendToFile(fi);
}
}
}
}