How to find duration of a video file using mediainfo in seconds or other formats?
This page only shows how to print the duration of a media file. I want to show both filename and duration for many media files.
The output should in the format of the following.
filename<TAB>duration
How can I call mediainfo to get this result?
This page only shows how to print the duration of a media file.
Actually it shows also how to print more than one item, see e.g. "iv)" in the best answer, you may adapt it for your needs.
filename<TAB>duration
Example:
$ mediainfo mediainfo --Inform="General;%CompleteName%,%Duration%" [inputfile]
tab is replaced by a comma, the command line interface does not permit the tab.
for a tab, you need to create a file e.g. template.csv with:
General;%CompleteName%<TAB>%Duration%
(replace "<TAB>" by a real tab character)
Then:
$ mediainfo mediainfo --Inform=file://template.csv [inputfile]
Jérôme, main developer of MediaInfo.
Related
I want to be able to quickly view (with F3) the content of Word doc/docx files in Midnight Commander. MC's extensions file calls /usr/lib/mc/ext.d/doc.sh, which contains wv, antiword, catdoc, and word2x as helper programs. On my system (debian), the first three are available, but none of them are able to deal with the newer docx format.
The obvious solution is to use LibreOffice:
libreoffice --headless --convert-to "txt:Text (encoded):UTF8" filename.docx
This works well, but how do I tell MC to use it and display the result of the conversion? If I put this in ~/.config/mc/mc.ext, replacing the lines
View=%view{ascii} /usr/lib/mc/ext.d/doc.sh view msdoc
with
View=libreoffice --headless --convert-to "txt:Text (encoded):UTF8" "${MC_EXT_FILENAME}"
then I end up with a filename.txt file in the current directory, and nothing is displayed. What I want to happen is for mc to do the conversion when I press F3 and discard it when I quit the viewer. (I guess the converted file would be written to /tmp/ and removed on quit.)
Bonus: it would be nice if the displayed file would be word-wrapped, I suppose that could be done by using the wrap command?
Can I do this without having to modify /usr/lib/mc/ext.d/doc.sh, in my ~/.config/mc/mc.ext?
I use docx2txt:
View=%view{ascii} docx2txt %f -
Also you don't need such a long conversion string in libreoffice.
libreoffice --cat %f
is enough.
I have this radare2 running on my windows10, and trying to get the .text section of a PE format executable file. Shall I first have to know what is the size of .text section and do a dump within the address range? Thank you for sharing your knowledge!
There's a couple of ways you could do this.
You can dump the .text section to file as a C style string of bytes using the command:
pcs section_end..text-section..text # section..text > myfile.txt
ie "\x90\x90\x41\x41".
See 'pc?' for help about other output formats.
'section_end..text' and 'section..text' are markers or bookmarks of the addresses of the start and end of your .text section. radare2 identifies the sections and creates the markers for you (called flags in radare2). So we're suubtraction .text end address from .text start address to get length of the section
You could also use 'wtf' for raw binary dump. Something like:
wtf myfile section_end..text-section..text # section..text
'wtf' for write to file
myfile is your filename
subtract end from start to get length
'# section..text' to tell it what seek position to begin dumping
from.
What's your .text sections name? In a file I see .text.0 as there were more than one section in the PE file. So add the number following - .text.<##>
e.g., pcs section_end..text.0-section..text.0 # section..text.0 > myfile.txt
Although this outputs one long text line of the .text section in the file:
"\x8b\x9c ... \x67\xf1\xff\x00\x00"
to write the .text.<##> section to a file change the command a bit too:
wtf section_end..text.0-section..text.0 # section..text.0
Change the number, 0, to that for your .text.<##> section number. Use the command:
S
to list all the sections
On Windows Notepad.exe, I simply press F5 and it inserts the date and time like this:
11:05 AM 1/14/2015
Can I add similarly simple functionality to Notepad++?
If your Notepad++ shipped with TextFX, you can find this in TextFX > TextFX Insert > Date & Time - short format, which will insert a string in the exact same format. If you don't see a TextFX menu, install it via the plugin manager and it will appear.
You can then bind it to a keyboard shortcut in Settings > Shortcut Mapper... > Plugin Commands. Look for I:Date & Time - short format in the mappings.
Step 1 : Install plugin TextFX
Step 2 : Insert Date & time
Try "Python Script" plugin
I prefer to use the Python Script plugin as documented here: https://ardamis.com/2014/03/09/adding-an-insert-datestamp-or-timestamp-macro-to-notepad-plus-plus/
because it gives me total control over how I want to the datetime stamp formatting to look, and it also allows me to create macro scripts for inserting other types of values that I want to compute.
Install "Python Script" MANUALLY
Please note that you must download the Python Script plugin from http://npppythonscript.sourceforge.net/download.shtml because downloading it from the Plugin Manager in Notepad++ doesn't always work. (See this thread for details.)
Write "Time.py" script
Then you can write a simple script like this:
import time
# import sys
timeStr = time.strftime( '%Y-%m-%d' + ' # ' + '%I:%M %p' )
# sys.stdout.write(timeStr)
editor.addText( timeStr )
You can change the format string as you wish. This allows you to have total control over the text output. (See Python 2's time.strftime documentation for details.)
Then save the script to this filename:
"%AppData%\Notepad++\plugins\Config\PythonScript\scripts\Time.py"
Create "menu item" inside "Python Script"
Navigate here: Menu bar -> Plugins -> Python Script -> Configuration like this:
Then you can add the script like this:
Assign hotkey
Then, when you restart Notepad++, you can assign the script to a shortcut like this by going to Menu bar -> Settings -> Shortcut Mapper -> Plugin Commands -> Time:
Further reading
More documentation on the Python Script plugin is available here: PythonScript plugin documentation for Notepad++
This features has been added in Notepad++ v8.1.4.
Menu > Edit > Insert >
Date Time (short)
Date Time (long)
That answers this question without the need for a plugin.
Can you find a way to map it to a shortcut? Currently, the shortcut mapper does not have an entry to map it to. When I try to record and playback a macro for it, I get gibberish on the screen (looks like a bug).
It looks like the TextFX plugin proposed here is not available for 64bit any more.
The alternative as of today is to install the Notepad++ Plugin Demo plugin, which provides Date Time - short format and Date Time - long format. Map to shortcuts as desired. In my German locale, the results are, respectively:
12:10 01.07.2020
12:10 Mittwoch, 1. Juli 2020
With the TextFx add on there's an option to insert date and time. I guess you can assign a keyboard shortcut to it.
A simple method through LuaScript (https://github.com/notepad-plus-plus/notepad-plus-plus/issues/497 and https://www.lua.org/pil/22.1.html): install LuaScript plugin first, then in LuaScript Edit Startup Script past the following:
npp.AddShortcut("Insert Current Date/Time", "Ctrl+Shift+D", function()
editor:ReplaceSel(os.date("%I:%M %p %m/%d/%Y"))
end)
After restart npp, the Ctrl-Shift-D will do as F5 in notepad.
Starting with Notepad++ 8.1.5, you can insert a custom date/time format using Edit/Insert/Date Time (customized). You can customize it in Settings/Preferences/Multi-Instance & Date.
In one of the recent N++ updates, my previous shortcut of CTRL + SHIFT + D, stopped working. I then rechecked and had to remap the custom date shortcut to ALT+ SHIFT + D. This is how it looks:
Make sure your customized date match your expectations:
A more generic answer using "Autohotkey":
https://autohotkey.com/board/topic/21387-how-to-insert-current-date-into-a-hotkey/
Examples:
;//will replace ddd keystroke with yyyy-MM-dd formatted date
:R*?:ddd:
FormatTime, CurrentDateTime,, yyyy-MM-dd
SendInput %CurrentDateTime%
return
;//will replace ttt keystroke with yyyy-MM-dd HH:mm formatted date/time
:R*?:ttt::
FormatTime, CurrentDateTime,, yyyy-MM-dd HH:mm
SendInput %CurrentDateTime%
return
Here's an easy and flexible way to insert a date/time stamp in any format you like.
Like many other developers, I used the FingerText plugin which allows you to insert customizable snippets of code or text by typing a "trigger" word and pressing the tab key.
One of my snippets is to insert a date/time stamp that I use in code comments:
I just type stamptab and it inserts a date like this: 2020-07-31 # 11:45
Here is the FingerText code I use to generate the stamp, which you can modify for any datetime format you choose:
$[![(key)DATE:yyyy-MM-dd]!] # $[![(key)TIME:HH:mm]!] $[0[]0][>END<]
You can download FingerText through the Plugins Admin dialog.
The quickest way that comes to my mind is to open Windows Notepad, press F5, copy/paste. No need to install anything...
To clarify, I mean the icon that is displayed when the app is running (e.g. inside the dock).
With trial and error, I found out that it uses "/usr/share/pixmap/xfce4-terminal.xpm" as the icon (tested by replacing this file with some other icon).
I was unable to find where it maps the running xterm to this icon.
If I copy the xterm binary to a different name and run that one, it gets a different icon, which shows that there is a possibility to change it.
I already tried setting the "xterm*iconPixmap:" resource, but that appears to have no effect at all.
You could try using xseticon
usage: xseticon [options] path/to/icon.png
options:
-name : apply icon to the window of the name supplied
-id : apply icon to the window id supplied
Sets the window icon to the specified .png image. The image is loaded from
the file at runtime and sent to the X server; thereafter the file does not
need to exist, and can be deleted/renamed/modified without the X server or
window manager noticing.
If no window selection option is specified, the window can be interactively
selected using the cursor.
Hints: xseticon -id "$WINDOWID" path/to/icon.png Will set the icon for an xterm.
********** EDIT **********
I think you need the imagemagick program installed to access the convert command. Then, find an icon that you like and convert it to an xbm file:
Code:
convert /path/to/icon/file /path/to/xterm.xbm
Create an ~/.Xresources file with the following content:
Code:
xterm*iconPixmap: /path/to/xterm.xbm
Then merge in the ~/Xresources file:
Code:
xrdb -merge ~/.Xresources
The update came from: http://forum.xfce.org/viewtopic.php?id=6779
I finally managed to do by setting *iconHint on the xterm resource.
The value needs to be a path to an .xpm file WITHOUT the extension.
X resources that you want to be loaded at login time need to go into an ~/.Xdefaults file.
So a complete solution for an icon my-xterm.xpm would be:
mkdir ~/.icons
mv my-xterm.xpm ~/.icons/
echo 'xterm*iconHint: '$HOME'/.icons/my-xterm' >> ~/.Xdefaults
If you want your changed ~/.Xdefaults to become active without logging in, run xrdb -merge ~/.Xdefaults
If you just want one xterm to have a different icon, you can start the xterm like this:
xterm -xrm 'xterm*iconHint: /full/path/to/icon' …
Not 100% sure that changing the .desktop file would help in XFCE. But it's a worth a shot.
Find the path to your local icons, here is in the sub path of
/usr/local/share/icons.
Then simply copy the .desktop file to you home dir eg:
cp /usr/share/applications/xterm-color.desktop ~/.local/share/applications/
Then edit the .dekstop fil in an editor, there is a line like this:
Icon=xterm-color
Replace this with a icon name from your icons path and logout and back in and you should be good to go. (The icon should not have the file extention like .png or .svg).
I have a 5GB 1 liner file with JSON data and each line starts from this pattern "{"created". I need to be able to use Unix commands on my Mac to convert this monster of a 1 liner into as many lines as it deserves. Any commands?
ASCII English text, with very long lines, with no line terminators
If you have enough memory you can open the file once with the TextWrangler application (the free BBEdit cousin) and use regular search/replace on the whole file. Use \r in replace to add a return. Will be very slow at opening the file, may even hang if low on memory, but in the end it may probably work. No scripting, no commands,.. etc.. I did this with big SQL files and sometimes it did the job.
You have to replace your line-start string with the same string with \n or \r or \r\n in front of it.
Unclear how it can be a “one liner” file but then each line starts with "{"created", but perhaps python -mjson.tool can help you get started:
cat your_source_file.json | python -mjson.tool > nicely_formatted_file.json
Piping raw JSON through ``python -mjson.tool` will cleanly format the JSON to be more human readable. More info here.
OS X ships with both flex and bison, you can use those to write a parser for your data.
You can use PHP as a shell command (if PHP is installed), just save a text file with name "myscript" and appropriate code (I cannot test code now, but the idea is as follows)
UNTESTED CODE
#!/usr/bin/php
<?php
$REPLACE_STRING='{"created'; // anything you like
// open input file with fopen() in read mode
$inFp=fopen('big_in_file.txt', "r");
// open output file with fopen() in write mode
$outFp=fopen('big_out_file.txt', "w+");
// while not end of file
while (!feof($inFp)) {
// read file chunks here with fread() in variable $chunk
$chunk = fread($inFp, 8192);
// do a $chunk=str_replace($REPLACE_STRING,"\r".$REPLACE_STRING; // to add returns
// (or use \r\n for windows end of lines)
$chunk=str_replace($REPLACE_STRING,"\r".$REPLACE_STRING,$chunk);
// problem: if chunk contains half the string at the end
// easily solved if $REPLACE_STRING is a one char like '{'
// otherwise test for fist char { in the end of $chunk
// remove final part and save it in a var for nest iteration
// write $chunk to output file
fwrite($outFp, $chunk);
// End while
}
?>
After you save it you must make it executable whith sudo chmod a+x ./myscript
and then launch it as ./myscript in terminal
After this, the myscript file is a full unix command