Showing posts with label Boxoft. Show all posts
Showing posts with label Boxoft. Show all posts

Saturday, June 2, 2012

Batch Verifying or Validating Scattered WAV Files

I had previously looked for ways to test MP3 files.  Now I wanted to test some WAVs.  This post describes one approach that seemed to work.

Initially, I tried using IrfanView, before rediscovering that IrfanView did not do audio file conversions.  After some searching around, I tried the command-line option in Boxoft WAV to MP3 Converter (freeware).  This looked promising.

To run the Boxoft converter, I used this syntax:

WavToMp3Cmd "D:\Folder\File Name.wav" -O"D:\Test\Output Filename.mp3"
This syntax seemed a little awkward, because (as shown) there was no space after the -O. (That's an oh, not a zero.)  Of course, I had to use quotation marks, as shown, because I had spaces in the folder and/or file names.  I had to run this command in the folder where the Boxoft program was installed (i.e., where WavToMp3Cmd.exe was located). That is, I had to run my batch file from there. That installation folder, on my x64 system, was C:\Program Files (x86)\Boxoft Wav to MP3 (freeware).

The foregoing command was pretty bare-bones.  I would have had to add more parameters, as described in the Boxoft help file, if I had wanted to produce high-quality output MP3s.  I was just creating the output MP3s to see whether the input WAVs were valid.  I would be deleting the output MP3s when the test was done.

I wasn't sure how the Boxoft converter would deal with a flawed WAV file.  To find out, I created a TXT file, changed its extension to WAV, and ran the foregoing command on it.  Boxoft produced an unplayable Test.mp3 in the output folder, so in that sense the test failed:  I would have preferred that it would not produce junk files.  Fortunately, Boxoft did register an error message on the command line. I captured that error to a log file by adding some stuff to the foregoing command.  That command now looked like this:
WavToMp3Cmd "D:\Folder\File Name.wav" -O"D:\Test\Output Filename.mp3" >> D:\Test\Log.txt
That was all on one command line.  Now I would have a Log.txt file that would capture error messages produced by the converter.  The next step was to work up my list of commands.  My WAV files were scattered in various folders around the computer, so as described in more detail in another post (and in several prior posts listed at the start of that one), I used a DIR command to identify the files I wanted to test (in this case, they were of the form 2010*.wav), and then I used Microsoft Excel formulas to create the relevant commands.  So now, for each file to be tested, I had an Excel row containing something like the command shown above.  I copied all those commands into a text file in Notepad, renamed that file's extension to be BAT (so that it would run), saved it in the Boxoft folder as noted above, and ran it.

In 10 or 15 minutes, the batch file was done; I had tested about 2,800 WAVs.  I verified that the number of output MP3 files equaled the number of input WAV files.  I wasn't sure how Log.txt would register errors, so I copied and pasted the entire log into a Microsoft Word document and reduced its size by doing global search-and-replace operations to remove the lines pertaining to the Title, Artist, and other settings that didn't matter to me.  (Word's special character to remove line breaks was ^p.)  I changed the remaining output to fit on one line (that is, I changed "^pSave to" to be just "Save to"), so that the file name and the result (e.g., "Success") would all be on one line.  I pasted this remaining text into Excel, did a FIND for lines containing "Success," and sorted the list according to whether "Success" appeared.  There was only one non-Success line.  It said, "Set the error bit rate. Please run WavToMp3Cmd to get help."  In the Word doc, I searched for that text.  I played the original WAV file whose name appeared just before that text.  It played OK.  I looked for the output MP3 file of similar name.  It wasn't there.  In this case, Boxoft hadn't created the failing file.  But then why did my file count agree?  Oh, of course, because the Log.txt file was in the output folder.  I wasn't sure why Boxoft had balked at the input WAV; but now that I had manually tested it and found it was OK, I didn't really care.

It occurred to me that Boxoft had produced an error when confronted with the obvious impossibility of converting a TXT file to MP3; but what about if some of the input files were mislabeled as WAVs when, in fact, they were MP3s or WMAs or some other kind of audio file?  I wasn't sure whether Boxoft would produce an error message or warning for such files.  I ran a version of the foregoing command on an input WMA, not renamed to WAV.  That crashed Boxoft.  I tried again after renaming the WMA to WAV.  That crashed Boxoft too.  I also tried with an input MP3.  Same results:  crashes.  I re-checked that the command did work with a genuine input WAV.  So apparently Boxoft would have crashed if my list of WAVs to be tested had contained an MP3 or WMA that was accidentally misnamed as a WAV.

To sum up, it seemed that the Boxoft command line converter, using a command with syntax shown above, was able to test large numbers of WAV files by converting them to MP3s, with error messages captured in a log file.

Sunday, March 18, 2012

Troubleshooting Some Options for Converting PDF to JPG or Other Image Formats

I had a bunch of PDFs.  I wanted to glance at just the first page of each.  This post describes some steps I took to find a way of extracting those first pages and making them easily available.

I believed it was going to be a simple matter to export from PDF to JPG using either Adobe Acrobat or IrfanView.  I had used both successfully in the past for this kind of purpose.  Unfortunately, for some reason Acrobat's Advanced > Document Processing > Batch Processing option was not working for me on this particular day.  Instead, I went into IrfanView > File > Batch Conversion/Rename, set the output format to JPG, selected the folder containing the newly created PDFs, clicked "Add All," set the output directory, and clicked Start Batch. Yet here, again, unknown causes were conspiring against me. IrfanView said, "Error! Can't load [filename]" for each of the PDFs. I tried exporting to PNG instead of JPG; same result. Was I mistaken in believing that IrfanView could produce JPGs from PDFs?  It had worked in a previous post.  Why not now?

A search led to a thread that raised the question of whether the source files were corrupt. I checked several of these newly created PDFs and they did seem to open OK in Acrobat.  So corruption didn't seem to be the issue.

At first, in that previous post, I had gotten that "Can't load" error.  The solution there was to download an upgrade to Ghostscript. Maybe I had updated IrfanView since then and, in the process, had somehow broken the Ghostscript update? I'd also gotten the error, another time, when trying to use IrfanView for audio conversions, which it apparently couldn't do.  So, ah, maybe what I was trying to do was confusing IrfanView.  I tried again with just one PDF.  There didn't seem to be much that could go wrong with that.  But it still didn't work.  When I tried to open a PDF with IrfanView, it gave me a message:

"Decode error! Can't load Ghostscript or Ghostscript error. Install Ghostscript from http://sourceforge.net/projects/ghostscript or http://sourceforge.net.
I went to the former. It pointed me to another page, and that one pointed me to yet another. It looked like Ghostscript had indeed been updated within the past month or so. I downloaded and installed the update. It didn't solve the problem, though possibly a reboot would have helped.

Was there another way to export JPGs or PNGs from PDFs? I tried XnView, which Irfan claimed was somehow built on code appropriated from him. Its interface certainly was very similar in this particular task. It didn't produce any JPGs either. A post reminded me that I hadn't tried IrfanView in command-line mode. The formula I had worked out previously was like this:
i_view32 D:\Folder1\File35.pdf /c=d:\TestFolder\File35.jpg
but now that was giving me Ghostscript errors too. A search led to suggestions to try ImageMagick and iTextSharp. The latter seemed beyond me. There were also a couple of suggestions on using scripting in GhostScript. They were a bit technical for my taste at this time.

It looked like ImageMagick had been around for a long time -- there were books about it -- and I had run across a number of references to it. So I decided to start there. The copy I downloaded from CNET was corrupted, so I got another from the ImageMagick FTP site. Unzipped, the ImageMagick program folder was 146MB and contained 5,694 files. This was no little alternative to IrfanView. This was a doctoral dissertation.  I immediately cast about for a GUI front end -- I couldn't even find its executables -- and alighted on Converseen.  I downloaded it from Softpedia and installed it.  Would it convert my PDFs to JPGs? I named three PDFs to try it. All three failed with this error:
Error: Magick: Postscript delegate failed [filename]: No such file or directory @ error/pdf.c/ReadPDFImage/664
Now, what do you suppose that meant? I tried a search and got a couple of very helpful sites in Chinese. I modified the search and, lo, it looked like that was an ImageMagick error, not a Converseen error. I gathered there could be a couple of possibilities. One was that, as someone reported, this error was likely (for some unknown reason) when converting PDFs that were mostly text, as mine were, rather than mostly image. Also, there seemed to be a regular cascade of programs: Converseen was a front end for ImageMagick which used GhostScript. So I couldn't necessarily be sure which one was responsible. For that matter, I didn't even know where to put ImageMagick; I wasn't seeing a manual. Further reading suggested that resolving problems in these programs could be challenging.

I tried another search. At the top of the list: Boxoft PDF to JPG Converter. Its installation process said, "Requires Ghostscript. Do you want to get a free GPL Ghostscript?" It seemed I was destined to have a computer full of copies of Ghostscript.  Or maybe this installation would be the answer to all of the problems described above.  I downloaded and installed the proffered Ghostscript 8.71.  The process didn't look familiar.  I wasn't sure what I had been doing with Ghostscript previously, but this wasn't it.  So would this perchance fix IrfanView?  I opened IrfanView and, wow, now it ran, no reboot necessary.  The way to fix IrfanView was to install Boxoft (or, possibly, to reinstall IrfanView).

But something was wrong.  Didn't IrfanView normally give me multiple pages, one PDF per page, when I used it to convert PDFs to JPGs?  This time, I was getting only one JPG per PDF, no matter how many pages it had.  I assumed that later Ghostscript installations replaced earlier ones, but now I saw that was not necessarily so.  I went into Control Panel > Programs and Features.  I saw three different Ghostscript items.  I wasn't sure if I could uninstall two of them without screwing up the third one.  I tried it, keeping only the Ghostscript 8.71 that I had just installed.  Boxoft and IrfanView both ran as before.  So cleanup accomplished, but IrfanView problem not fixed.

Since I now had Boxoft installed, I tried that.  Like IrfanView, it had a command-line mode and a GUI mode.  I tried the GUI.  It had multiple options.  I liked it.  It did produce multiple JPGs per PDF.  They looked good.  I ran it again, this time selecting only page 1 (Settings > Common tab > PDF Convert Range), and that's exactly what it gave me.  So I wouldn't have to take a separate step of deleting JPGs for the pages other than page 1 of each PDF.  IrfanView didn't have that option, though it did have image editing options (if e.g., I wanted to change the dots per inch, size, or coloring of the resulting JPGs).

I could have continued to look at other options appearing in that search, but it appeared a working conclusion was to go with Boxoft and/or IrfanView, depending on the kind of output desired, and to make sure I was using just one stable, recent version of Ghostscript.

Saturday, March 10, 2012

Using Screenshots to Examine Many Files Quickly

I had a couple of projects that called for a way to examine a large number of files.  It seemed that screenshots could help in those projects.  This post describes the techniques I used.

EML Analysis

In one project, I was working with various email files that I had exported from Thunderbird.  These files had an EML extension.  Typically, if I viewed an EML file in Notepad, I would see various codes and other information that wouldn't be visible if I viewed it in an email program like Thunderbird.

I was interested in seeing the header codes in these EML files.  Those codes appeared at the tops of the files.  I felt that I could probably see what I needed to see in the first screenful of a Notepad session, opened maximized.

In other words, the concept was that I would open the EML file in Notepad; I would take a screenshot; I would save the screenshot; and then I would close the file and repeat the process with the next EML file on my list.  Then I would combine all those screenshots into one file, and flip through it or perhaps use other tools to analyze it further.  I wouldn't have to sit there, maintaining constant attention while the process continued in real time; I could just review the outcome afterwards.  (For some purposes, an alternative would have been to combine or select from the text, without a graphical view.)

The first step was to build the list of EML files that I wanted to examine.  I moved them all into a single folder and used DIR and Excel to give me the list and to convert it into a series of batch commands.  There was one such command for each such EML file.  Before running those commands, I had to open Notepad once, turn on its Format > Word Wrap option, and then close it.  The format of the command was as follows:

start /max notepad "D:\Folder Name\Email Name.eml"
That command was sufficient to open the EML file.  Next, I needed to pause the system for a moment, so that the file would have time to come onscreen. Among numerous suggestions, I favored a command involving PING ("ping 1.1.1.1 -n 1 -w 1500 > nul") because of its fine-tunable setting (in the example just given, 1500 milliseconds).  Unfortunately, that command's output component (" > nul") would have prevented me from adding more commands on the same line.  So I had to go with "TIMEOUT /T 1" for a one-second delay.

Next, I needed a command to take a snapshot.  It looked like there were multiple options here.  I had already installed NirCmd and had found it useful for other things, so I used this command:
start NirCmd savescreenshot "D:\Folder Name\Screenshots\Email Name.png"
NirCmd came with an option to copy its executable (nircmd.exe) to C:\Windows, so that this command could run without any need to specify the location of NirCmd, to put a copy of it in the current working folder, or to modify the computer's Path.  NirCmd wasn't saving to subfolders properly, so in the end I had to modify that part of the command.

Finally, I needed a command to close Notepad.  The advice that worked for me was:
taskkill /f /im notepad.exe
Note that this would close all currently open Notepad sessions.  These three steps (i.e., open the EML in Notepad, take a picture with NirCmd, close Notepad) would give me a screenshot of the first screenful's worth of the file's contents.  Collectively, those screenshots would give me a visual impression of the various kinds of codes appearing at the start of my EML files.

I used && to combine multiple commands on the same line, as a single (long) batch command. If that had failed, I could have added index columns next to the spreadsheet columns in which I built those two commands, with alternating even and odd numbers in those columns:  1 for the first Notepad command, 2 for the first NirCmd command, 3 for the second Notpad command, and so forth.  These index numbers would allow the various commands to be sorted into proper sequence in a single column, for copying and pasting into a batch file.

In short, for each EML file, I combined four commands with &&, into a single long command like this:
start /max notepad "D:\Folder Name\Email Name.eml" && timeout /t 1 && start NirCmd savescreenshot "Email Name.png" && taskkill /f /im notepad.exe
This gave me some PNGs.  Now there was the question of what to do with them.  One option was to simply stitch them together in a slideshow (using e.g., IrfanView) or a single PDF (using e.g., Acrobat).  I did a brief investigation of OCR software for that purpose.  Ultimately, I just used IrfanView, without even creating a slideshow, to arrow down through those PNGs, one at a time, at whatever pace I chose.  So I could look at whether each page came through OK.

PDF Analysis

In another project, I had a bunch of PDFs that I had created in a conversion process.  I wanted to check if the PDFs came through OK.  It would have been very slow to open them, one at a time, and page through them.  Combining them all into a single large PDF, which I could also page through, would have produced a huge file.  Also, if I was working with large PDFs or many PDFs (or both), I might have to look at huge numbers of pages.  Boredom or haste could lead me to flip past an important one-page document, while checking hundreds or thousands of less important pages.

Based on various factors (including the number of PDFs, their importance, and the time available), I decided to examine just the first page of each PDF.  I might not be able to tell if the whole document printed properly, but at least I could eliminate those instances where printing failed completely.

For this purpose, the process described in the previous section offered one possibility.  I could probably work up a set of commands to open a PDF, take a screenshot, and then close it, and then flip through the resulting screenshots.

I did not actually pursue that approach in this case, however.  Instead, I wanted to see if I could convert the PDF documents to JPG and then flip through just the first page from each such document.  If I had a hundred documents to check, I would have a hundred pages to look at -- not a thousand.  A separate post discusses that investigation.  The tool I chose was  Boxoft PDF to JPG Converter.  Another way to proceed might have been to split the PDFs first, using something like PDFsam, and then combine the PDFs of each resulting first page into a larger PDF that I could flip through.