using ffprobe to count number of audio channels in a video file - ffprobe

I am using this to get the number of audio channels in a video file:
ffprobe -i movie.mxf -show_entries stream=channels -select_streams a -of compact=p=0:nk=1 -v 0
Which outputs:
0
1
1
1
1
1
1
1
1
There are 8 audio channels, and I wanted to get that number as a variable. Is this possible?

Related

XDATA on a Programmatically Created DXF File

I have a small vb.net app that creates DXF files from scratch, containing polylines and some text objects. It is working as intented and does its job at the moment, making use of some "minimum dxf requirements" info I found online.
As an upgrade for the app, I have decided to add some xdata on the polylines and that's where I am having some trouble.
I have added the following lines inside the polyline definition in ENTITIES section:
1001
MYAPPID01
1002
{
1000
-Some string I want to associate with the polyline-
1002
}
And also created a table section for the appid as follows:
0
SECTION
2
TABLES
0
TABLE
2
APPID
2
MYAPPID01
70
0
0
ENDTAB
0
ENDSEC
I have also added an auto-load process in acaddoc lsp file to register the app:
(if (not (tblsearch "APPID" "MYAPPID01"))
(regapp "MYAPPID01")
)
My dxf files aren't loading and give the "Invalid application" error. What must I do to add this xdata with minimum addition to my normal dxf routine?
Any help about APPID's and their registrations would be great.
Thank you all in advance.
What's missing is the max table count tag (70, count) after the table type definition tag (2, APPID), the following table entries start with a (0, APPID) tag. (Solution for DXF R12)
0
SECTION <<< start table section
0
TABLE <<< start table
2 <<< group code 2 for
APPID <<< table type definition
70
10 <<< max table entry count
0 <<< group code 0 for
APPID <<< 1. table entry
2
ACAD <<< application name
70
0 <<< flags, 0 is good
0
APPID <<< 2. table entry
2
MYAPPID01 <<< application name
70
0 <<< flags
... and so on
0
ENDTAB
0
ENDSEC
You can find more information here (valid for DXF R13 and later):

How to do a low RAM full cross join?

I have a hope to perform a full self-cross join on a large data file of points. However, I cannot use programming language to perform the operation because I cannot store it in memory. I would like to find all combinations of points within the set. Below would be an example of my dataset.
x y
1 9
2 8
3 7
4 6
5 5
I would like to cross join on this data to generate 25-row table containing all the combination of points. Would there be a low memory solution? perhaps with awk ?
Thank you,
Nicholas Hayden
P.S. I am a novice programmer.
perhaps in two steps, create a header, column1 and column2 files and join the column1 and column2 and append to header file
awk 'NR==1{print > "cross"} NR>1 {print $1 > "col1"; print $2 > "col2"}' file
join -j9 col1 col2 -o1.1,2.1 >> cross
rm col1, col2
obviously make sure the temp and final file names won't clash with the existing ones.
Note, the join command on MacOS doesn't have the -j option, so change it to equivalent long form
join -19 -29 col1 col2 -o1.1,2.1 >> cross
in both alternatives we're asking join to use the non-existent 9th field as the key which matches every line of the first file to every line in the second to generate the cross product of the two files.
If the memory usage wasn't an issue I'd probably do this:
$ awk 'NR==1 { print; next } # print the header
{ x[NR]=$1; y[NR]=$2 } # read data ro two hashes x and y
END { for(i=2;i<=NR;i++)
for(j=2;j<=NR;j++)
print x[i],y[j] # print all combinations of x and y
}' file
Keeping the memory usage low obviously requires keeping data out of memory and that means accessing the file a lot. So while processing FILENAME for x, open the same file with another name (file below) and process that record by record for y:
$ awk 'NR==1 { print; next } # print header
{ file=FILENAME; x=$1; nr=1 # duplicate FILENAME, keep $1, create local nr
while((getline <file) > 0) # process file record by record
if(nr++>1) {print x,$2 } # print $1 of FILENAME and $2 of file
close(file) }' file # close the file
x y
1 9
1 8
1 7
1 6
1 5
2 9
...
I'd probably never use that code as it is for anything useful but maybe you can mix those 2 solutions to create something suitable.

ffmpeg txt from audio levels

Regards community,
I want to use ffmpeg to generate a file (txt, csv) from audio values.
Any idea?
I use this code to generate the audio levels:
ffplay -f lavfi "amovie=input.aac, asplit [a][out1]; [a] showvolume=f=1:b=4:w=800:h=70 [out0]"
Thank you a lot
The command below will generate a CSV format where the first column represents the audio frame time in seconds, the second column the overall RMS dB volume for that frame, the 3rd column RMS volume for the first channel and the last column the RMS volume for the 2nd channel.
ffprobe -f lavfi -i amovie=input.aac,astats=metadata=1:reset=1 -show_entries frame=pkt_pts_time:frame_tags=lavfi.astats.Overall.RMS_level,lavfi.astats.1.RMS_level,lavfi.astats.2.RMS_level -of csv=p=0
Output:
Duration: N/A, start: 0.023220, bitrate: N/A
Stream #0:0: Audio: pcm_f64le, 44100 Hz, stereo, dbl, 5644 kb/s
0.023220,-inf,-inf,-inf
0.046440,-inf,-inf,-inf
0.069660,-inf,-inf,-inf
0.092880,-27.330401,-22.685612,-24.414572
0.116100,-21.141091,-18.986082,-19.931269
0.139320,-20.955719,-18.549085,-19.587788
0.162540,-20.938002,-18.198237,-19.355561
0.185760,-19.852306,-20.032553,-19.941494
0.208980,-20.495281,-21.684953,-21.049508
The reset determines how often the stats are calculated. I've set the value to 1 i.e. calculated for each audio frame in isolation.

html5 video tag codecs attribute

I am trying to specify a specific video/audio codec in the video tag using
<video poster="movie.jpg" controls>
<source src="movie.mp4" type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'/>
<p>This is fallback content</p>
</video>
but can't find the right codecs statement to play the video , i have downloaded a video analyser and can see that its an avc1 and can see that the audio map.40.2 but can work out the rest of the codec, what does the 4d401e mean in the above ?
Cheers
Toby
The codecs parameter is specified by RFC 6381. Specifically, see section 3.3 for the meaning of avc1 and mp4a values.
In the case of avc1.4D401E, avc1 indicates H.264 video, and this is followed by a dot and three 2-digit hexadecimal numbers defined by the H.264 standard:
profile_idc
the byte containing the constraint_set flags (currently constraint_set0_flag through constraint_set5_flag, and the reserved_zero_2bits)
level_idc
Some examples:
avc1.42E01E: H.264 Constrained Baseline Profile Level 3
avc1.4D401E: H.264 Main Profile Level 3
avc1.64001E: H.264 High Profile Level 3
These are also the second, third, and fourth bytes of the Sequence Parameter Set and the AVC Configuration Box in an MP4 file. You can dump these bytes using a program such as mp4file: mp4file --dump movie.mp4. Look for the avcC (AVC Configuration) Box and the hexadecimal values for AVCProfileIndication, profile_compatibility, and AVCLevelIndication.
As for mp4a.40.2, mp4a indicates MPEG-4 audio. It is followed by a dot and a hexadecimal ObjectTypeIndication (objectTypeId in mp4file output), which can be looked up on the MPEG4 registration site. If this hexadecimal value is 40 (ISO/IEC 14496-3 Audio), it is followed by another dot and an audio object type in decimal. These are listed in the ISO/IEC 14496-3 standard and on Wikipedia, and correspond to the first 5 bits of the DecoderSpecificInfo (decSpecificInfo) (unless these bits equal 31, in which case add 32 to the next 6 bits). mp4a.40.2 indicates AAC LC audio, which is what is usually used with H.264 HTML5 video.
For example, codecs="avc1.42E01E, mp4a.40.2" would be correct for the movie below:
$ mp4file --dump movie.mp4
...
type avcC (moov.trak.mdia.minf.stbl.stsd.avc1.avcC) ◀━━ avc1
configurationVersion = 1 (0x01)
AVCProfileIndication = 66 (0x42) ◀━━ 42
profile_compatibility = 224 (0xe0) ◀━━ E0
AVCLevelIndication = 30 (0x1e) ◀━━ 1E
...
type esds (moov.trak.mdia.minf.stbl.stsd.mp4a.esds) ◀━━ mp4a
version = 0 (0x00)
flags = 0 (0x000000)
ESID = 2 (0x0002)
streamDependenceFlag = 0 (0x0) <1 bits>
URLFlag = 0 (0x0) <1 bits>
OCRstreamFlag = 0 (0x0) <1 bits>
streamPriority = 0 (0x00) <5 bits>
decConfigDescr
objectTypeId = 64 (0x40) ◀━━ 40
streamType = 5 (0x05) <6 bits>
upStream = 0 (0x0) <1 bits>
reserved = 1 (0x1) <1 bits>
bufferSizeDB = 0 (0x000000) <24 bits>
maxBitrate = 78267 (0x000131bb)
avgBitrate = 78267 (0x000131bb)
decSpecificInfo
info = <2 bytes> 11 90 |..| ◀━━ 2 (first 5 bits in decimal)
...
You can use MP4Box tool to find out codec strings in RFC6381 format. Still you have to join them with commas.
You can use this command:
MP4Box -info big.mp4 2>&1 | grep RFC6381 | awk '{print $4}' | paste -sd , -
mark4o gives by far the best explanation I've seen of how to decipher codec information. Excellent.
One piece which may require a little more detail is how to break out the specific audio object type from the decSpecificInfo value. Finding the "mp4a.40" part is very clear, the ".2" section can be a little tricky.
We start with a sequence of single byte hexadecimal values: "11 90" in mark4o’s example or "12 08" in my case. Both of those are a total of 2 bytes... there may be more values but only the first 2 matter for finding the object type (and usually only the first byte). We're looking for individual bits so convert each digit in the hexadecimal values to binary; there should be 4 binary digits for each hexadecimal digit. Take the first 5 binary digits — 4 from the first hex digit, 1 from the next — and convert that binary value to decimal. Here are the steps:
Example 1 (11 90):
Starting value: 11 90
Separate the hex digits: 1 1 9 0
Convert each digit to binary: 0001 0001 1001 0000
Take the first 5 bits: 0001 0
Combine into binary value: 00010
Convert to decimal: 2
Example 2 (12 08):
Starting value: 12 08
Separate the hex digits: 1 2 0 8
Convert each digit to binary: 0001 0010 0000 1000
Take the first 5 bits: 0001 0
Combine into binary value: 00010
Convert to decimal: 2
They are the same object type in spite of having different decSpecificInfo values.
You could also simply do this to find the right codec infor:
go to the folder containing your video file, lets assume the file is called movie.mp4,
The run the command:
vlc movie.mp4
assuming you have vlc installed, if the video plays vlc will have the correct codec information,
Click on the tools menu above, a drop down list will be displayed with an option to view the codec information as below.

Where might I begin on this optimization problem?

I have a simple program which reads a bunch of things from the filesystem, filters the results , and prints them. This simple program implements a domain specific language to make selection easier. This DSL "compiles" down into an execution plan that looks like this (Input was C:\Windows\System32\* OR -md5"ABCDEFG" OR -tf):
Index Success Failure Description
0 S 1 File Matches C:\Windows\System32\*
1 S 2 File MD5 Matches ABCDEFG
2 S F File is file. (Not directory)
The filter is applied to the given file, and if it succeeds, the index pointer jumps to the index indicated in the success field, and if it fails, the index pointer jumps to the number indicated in the failure field. "S" means that the file passes the filter, F means that the file should be rejected.
Of course, a filter based upon a simple file attribute (!FILE_ATTRIBUTE_DIRECTORY) check is much faster than a check based upon the MD5 of the file, which requires opening and performing the actual hash of the file. Each filter "opcode" has a time class associated with it; MD5 gets a high timing number, ISFILE gets a low timing number.
I would like to reorder this execution plan so that opcodes that take a long time are executed as rarely as possible. For the above plan, that would mean it would have to be:
Index Success Failure Description
0 S 1 File is file. (Not directory)
1 S 2 File Matches C:\Windows\System32\*
2 S F File MD5 Matches ABCDEFG
According to the "Dragon Book", picking the best order of execution for three address code is an NP-Complete problem (At least according to page 511 of the second edition of that text), but in that case they are talking about register allocation and other issues of the machine. In my case, the actual "intermediate code" is much simpler. I'm wondering of a scheme exists that would allow me to reorder the source IL into the optimal execution plan.
Here is another example:
{ C:\Windows\Inf* AND -tp } OR { -tf AND NOT C:\Windows\System32\Drivers* }
Parsed to:
Index Success Failure Description
0 1 2 File Matches C:\Windows\Inf\*
1 S 2 File is a Portable Executable
2 3 F File is file. (Not directory)
3 F S File Matches C:\Windows\System32\Drivers\*
which is optimally:
Index Success Failure Description
0 1 2 File is file. (Not directory)
1 2 S File Matches C:\Windows\System32\Drivers\*
2 3 F File Matches C:\Windows\Inf\*
3 S F File is a Portable Executable
It sounds like it might be easier to pick an optimal order before compiling down to your opcodes. If you have a parse tree, and it is as "flat" as possible, then you can assign a score to each node and then sort each node's children by the lowest total score first.
For example:
{ C:\Windows\Inf* AND -tp } OR { -tf AND NOT C:\Windows\System32\Drivers* }
1 2 3 4
OR
/ \
AND AND
/ \ / \
1 2 3 4
You could sort the AND nodes (1, 2) and (3, 4) by the lowest score and then assign that score to each node. Then sort the children of the OR node by the lowest score of their children.
Since AND and OR are commutative, this sorting operation won't change the meaning of your overall expression.
#Greg Hewgill is right, this is easier to perform on the AST than on the Intermediate code. As you want to work on the Intermediate code, the first goal is to transform it into a dependency tree (which will look like the AST /shrug).
Start with the leaves - and it is probably easiest if you use negative-predicates for NOT.
Index Success Failure Description
0 1 2 File Matches C:\Windows\Inf\*
1 S 2 File is a Portable Executable
2 3 F File is file. (Not directory)
3 F S File Matches C:\Windows\System32\Drivers\*
Extract Leaf (anything with both children as S, F, or an extracted Node; insert NOT where required; Replace all references to Leaf with reference to parent node of leaf)
Index Success Failure Description
0 1 2 File Matches C:\Windows\Inf\*
1 S 2 File is a Portable Executable
2 L1 F File is file. (Not directory)
L1=NOT(cost(child))
|
Pred(cost(PATH))
Extract Node (If Success points to Extracted Node use conjunction to join; Failure uses disjunction; Replace all references to Node with reference to resulting root of tree containing Node).
Index Success Failure Description
0 1 L3 File Matches C:\Windows\Inf\*
1 S L3 File is a Portable Executable
L3=AND L1 L2 (cost(Min(L1,L2) + Selectivity(Min(L1,L2)) * Max(L1,L2)))
/ \
L1=NOT(cost(child)) L2=IS(cost(child))
| |
3=Pred(cost(PATH)) 2=Pred(cost(ISFILE))
Extract Node
Index Success Failure Description
0 L5 L3 File Matches C:\Windows\Inf\*
L5=OR L3 L4 (cost(Min(L3,L4) + (1.0 - Selectivity(Min(L3,L4))) * Max(L3,L4)))
/ \
| L4=IS(cost(child))
| |
| 1=Pred(cost(PORT_EXE))
|
L3=AND L1 L2 (cost(Min(L1,L2) + Selectivity(Min(L1,L2)) * Max(L1,L2)))
/ \
L1=NOT(cost(child)) L2=IS(cost(child))
| |
3=Pred(cost(PATH)) 2=Pred(cost(ISFILE))
Extract Node (In the case where Success and Failure both refer to Nodes, you will have to inject the Node into the tree by pattern matching on the root of the sub-tree defined by the Node)
If root is OR, invert predicate if necessary to ensure reference is Success and inject as conjunction with child not referenced by Failure.
If root is AND, invert predicate if necessary to ensure reference is Failure and inject as disjunction with child root referenced by Success.
Resulting in:
L5=OR L3 L4 (cost(Min(L3,L4) + (1.0 - Selectivity(Min(L3,L4))) * Max(L3,L4)))
/ \
| L4=AND(cost(as for L3))
| / \
| L6=IS(cost(child)) L7=IS(cost(child))
| | |
| 1=Pred(cost(PORT_EXE)) 0=Pred(cost(PATH))
|
L3=AND L1 L2 (cost(Min(L1,L2) + Selectivity(Min(L1,L2)) * Max(L1,L2)))
/ \
L1=NOT(cost(child)) L2=IS(cost(child))
| |
3=Pred(cost(PATH)) 2=Pred(cost(ISFILE))