Search This Blog

Tuesday, September 27, 2022

Exporting SRT file from an existing MP4 file

 I was wrestling with Handbrake to convert multiple large MP4 files into smaller, lower-resolution versions -- I would put the files to be processed into its queue, then specify that I wanted it to include the subtitle track as an option for the output file.

The method indicated in the documentation for Handbrake works so long as I'm doing it for one file at a time, but once I load up a queue and run multiple jobs the subtitle settings just don't seem to work -- the files video components are converted perfectly, but the subtitles don't come across in the new, smaller version of the file.

I gave it an hour trying every combination I could think of and had to give up and try something else.

The easier solution in my case was to process the video files using Handbrake but then to independently generate a SRT for each video file which the user (who'd be using VLC as their player) could load on their own if they wanted to view subtitles.

The answer lay with FFMPEG (again) -- this command would read the (single) subtitle track from my video file and then write it out to a "SRT" file:

ffmpeg -i myvideofile.mp4 -map 0:s:0 myvideofile.srt

I could see that this will get more complicated if the video file had multiple subtitle tracks (for different languages).  In that case you can try and wade through the full index of the video file looking for the correct track by using:

ffmpeg -i myvideofile.mp4

Or, if you're lazy like me, start the video file up in VLC and look for the listing of subtitle options.  You can then guess the correct track to use:

ffmpeg -i m.m4v -map 0:s:0 eng.srt
ffmpeg -i m.m4v -map 0:s:1 ita.srt
ffmpeg -i m.m4v -map 0:s:2 fre.srt

Thursday, November 19, 2015

"Can't connect to FTP: (553) File name not allowed" error

I had a need to develop a small C# app to dynamically configure static webpages from a database (simple tables of phone numbers) and then push them to a webserver using FTP.

Using the new .NET 4.5 FTP tools in "System.Net" I coded the app (example in https://msdn.microsoft.com/en-us/library/ms229715%28v=vs.110%29.aspx) and I immediately ran into a problem pushing a file to a directory on the webserver where I knew I had rights. 

The error message was "Can't connect to FTP: (553) File name not allowed" on the line which creates the file on the remote server:           

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(@"ftp://servername.albany.edu/www/prod/biology/phone_numbers/test1.html");

My mistake was forgetting that my target was a UNIX server and not a Microsoft IIS server -- after a UNIX servername you need a double-slash to indicate the server's root directory -- in my case, I needed to change it to:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(@"ftp://servername.albany.edu//www/prod/biology/phone_numbers/test1.html");

Tuesday, March 18, 2014

Sorting a C# Dictionary Collection

When working with Active Directory searches I often stream matches into a C# Dictionary object (e.g., using "samaccountname" as the key and ", ()" as the value).   Since it's searching a linked list the data comes in fast but unsorted.

Unfortunately the Dictionary object doesn't support a native sort() function, but it's easy to do using a LINQ function:

/// /// Sort Dictionary structure 
/// 
public static Dictionary SortDictionaryByValue(Dictionary data)
{
        List li = new List>(data);
        li.Sort((x, y) => x.Value.CompareTo(y.Value));
        return li.ToDictionary(p => p.Key, p => p.Value);
}

Thanks to mindfiresolutions for this function.

Saturday, May 11, 2013

Dumping the org-unit structure of an Active Directory namespace

The utility required is "LDIFDE" and the syntax and explanation can be found at:

http://support.microsoft.com/kb/237677

The upshot is the statement:

ldifde -f exportOu.ldf -s Server1 -d "dc=Export,dc=com" -p subtree -r "(objectCategory=organizationalUnit)" -l "cn,objectclass,ou" 

Where 1) "exportOU.ldf" is the file you're outputting to; 2) "Server1" is a dc in the domain; 3) "dc=Export,dc=com" is the root of the area in the namespace you want to dump; 4) "subtree" is your search scope; 5) "(object...Unit)" is the search term; and 6) "cn ...ou" is the list of attributes in the search.

When you get it, you turn it around and import it with:

ldifde -i -f exportOu.ldf -s Server2


Where 1) "exportOu.ldf" is the file you output earlier; and 2) "Server" is a DC in the domain where you want to build the OU structure.

Way easier than writing it oneself.

Wednesday, March 27, 2013

How to determine which NT groups I am in

So useful for debugging security problems but so forgettable ...

The easy one:

whoami /groups

The really detailed one:

gpresult /V

Friday, March 15, 2013

Visual Studio error: "Unable to delete folder . This function is not supported on this system."

This is a problem I've had when using VS2010 and am trying to get rid of service references so I can re-add them. 

It seems like a rights issue:  The answer is to go to the folder in question using Explorer and delete it manually, then go back into VS2010 and delete it.

Saturday, March 2, 2013

WCF error: "Custom tool warning: Cannot import wsdl.portType"

An error that comes up when moving code which calls a WCF service from development to production:

"Custom tool warning:  Cannot import wsdl:portType"

It also details a number of "custom tool" errors.

The problem stems from when I pull some Visual Studio Solution code over from my development lab, delete the service references in the projects in the solution (which point to the WCF service in the devlab) and re-add them as service references pointing to the WCF service in the production lab.

Evidently a lot is going on during the creation of these service references -- when Googling for information on it other users recommend completely shutting down and restarting Visual Studio; the best recommendation comes from stackoverflow and recommends re-adding these references while specifying not to reuse types in reference assemblies:

http://stackoverflow.com/questions/1872865/what-does-this-wcf-error-mean-custom-tool-warning-cannot-import-wsdlporttype

http://www.lukepuplett.com/2010/07/note-to-self-don-let-wcf-svcutil-reuse.html