Skip to main content
Topic: Reading codec info in some video files (Read 1520 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Reading codec info in some video files

Hi everybody,

I'm testing foobar as a tag manager for video files (with the m-TAGS component and also the FFmpeg Decoder Wrapper), and it works pretty well for the moment.
I'd like to read the codec info in some video files (mkv, mp4), to see if the used video codec is x264 or x265 for instance.
However, %codec% just gives me "mkv" or "mp4", not real codec info.

Is there some way I can achieve this ? Thanks !

Re: Reading codec info in some video files

Reply #1
Feature request noted.
%codec% is expected show the audio codec used in the files, so another field will be needed, such as %video_codec%.

Re: Reading codec info in some video files

Reply #2
Thanks Peter. I guess it's too late for version 1.4, but I hope the feature can make its way into the next one.
Thanks again for your great work over the years. Highly appreciated.

Re: Reading codec info in some video files

Reply #3
Hi, can somebody give us an update on the advancement of this %video_codec% feature ? Is it scheduled at least ? Thanks !

Re: Reading codec info in some video files

Reply #4
%video_codec% is now available (thanks devs!), please share your experience how use that ?
I added %video_codec% to the playlist field, but during .mkv playback displayed "?"
"Show codec names..." at FFmpeg Decoder Setup options - enabled.

Thanks!

Re: Reading codec info in some video files

Reply #5
$info(video_codec)
Seems that it only works with native mkv and mp4 readers, not with foo_input_ffmpeg.

Re: Reading codec info in some video files

Reply #6
$info(video_codec)
Seems that it only works with native mkv and mp4 readers, not with foo_input_ffmpeg.
Thanks!

Re: Reading codec info in some video files

Reply #7
Thanks ! I will check it out soon.

Now that we have a %video_codec% tag, was wondering if there would be a way to get the resolution info too (something like "1920x1080", you get the idea).
Maybe I should start a separate topic for that. What do you think ?

Alternatively, if somebody knows a way to recursively scan a video directory with hundreds of video files, get the resolution info for each of them and write it in one or two custom foobar tags, I'm all ears. Thanks.

Re: Reading codec info in some video files

Reply #8
In my opinion, the feature of playing video in fb2k needs to be develop and improve.
I would like to see fb2k advance in playing both local video files and internet video links.
Therefore, I will take part in any discussion with regards to that, as far as I can. Thanks!

Re: Reading codec info in some video files

Reply #9
In my opinion, the feature of playing video in fb2k needs to be develop and improve.
I would like to see fb2k advance in playing both local video files and internet video links.

And that would make foobar2000 to be media player instead of audio player like it is supposed to be.
Not so sure about that but I think foobar2000 main function is to be like it is now, an advanced audio player.
foobar2000 plays music

Re: Reading codec info in some video files

Reply #10
@Vicas, I absolutely agree with you.
I meant improve in supporting from fb2k for 3rd party components that play videos.

Re: Reading codec info in some video files

Reply #11
I meant improved support from fb2k for 3rd party components that play videos.

Ah yeah, that is another thing then. And if so, then we could say foobar by default is an audio player but with an additional component could be transformed into an media player. ;)
foobar2000 plays music

 

Re: Reading codec info in some video files

Reply #12
Guys, let's not start a debate in this topic over whether foobar2000's aim is to be an audio player or something else. Personally I don't care about foobar being a media player or not. I think it's a lot of work. More realistically, I'm just interested in foobar's TAGGING ABILITIES, which can make it arguably the best Video & TV show manager as far as only text, numbers and pictures are concerned. When I have time I will make a topic about the video config that I've achieved over the last months, and you'll see that it's pretty unique and shows how powerful foobar can be.

But that doesn't mean that foobar needs to play the videos itself. Currently when I want to play a video, I just right-click and go to the corresponding folder. I could also use foo_run and launch an external player, but I think it's better to just go to the folder.

What I'm currently interested in is for a way to read the video file resolution and somehow write it in the tags (either via foobar's core, or via a 3rd party component, or via a batch script using MediaInfo, etc.). That would help me improve my config even more. Any help appreciated !

I also made a topic some time ago about developing a TMDB scraping component for foobar, but there was no real interest. Another member threadjacked the newborn topic by posting endlessly when he had nothing to bring to the project (he didn't have any developing skills and didn't know what TMDB was), which probably discouraged other people to post.

Re: Reading codec info in some video files

Reply #13
I've come up with a way to read a video file's resolution using ffprobe (part of ffmpeg toolkit) :

Code: [Select]
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 input.mp4
Example output :
Code: [Select]
1280x720

Now I need a way to :
- Integrate this into a batch script, to scan recursively all videos that are, for example, mkv, mp4 or avi
- Write the results in each of the "!.tags" files that are in the same folder than each video file

Example of a "!.tags" file for a movie (single file in a folder), with the included WIDTH and HEIGHT info :

Code: [Select]
[
   {
      "@" : "Nerve 2016 1080p x265 10bit.mkv",
      "WIDTH" : "1920",
      "HEIGHT" : "1080",
      "AUDIO" : "English",
      "CREATION_TIME" : "2016-10-16T14:27:11.000000Z",
      "DATE" : "2016",
      "DURATION" : "5778.6650000",
      "ENCODER" : "libebml v1.3.3 + libmatroska v1.4.4",
      "GENRE" : "Action - Aventure",
       "SUBTITLES" : [ "English", "French" ],
      "TITLE" : "Nerve"
   }
]

Example of a "!.tags" file for its featurettes (several files in the same folder), with the included HEIGHT and WIDTH info for each featurette :

Code: [Select]
[
   {
      "@" : "Creating Nerve.mkv",
      "WIDTH" : "1920",
      "HEIGHT" : "1080",
      "CREATION_TIME" : "2016-10-16T15:51:50.000000Z",
      "DATE" : "2016",
      "DURATION" : "1606.3550000",
      "ENCODER" : "libebml v1.3.3 + libmatroska v1.4.4",
      "GENRE" : "Featurettes",
      "TITLE" : "Creating Nerve",
   },
   {
      "@" : "Player Profiles.mkv",
      "WIDTH" : "1920",
      "HEIGHT" : "1080",
      "CREATION_TIME" : "2016-10-16T16:03:56.000000Z",
      "DURATION" : "347.6030000",
      "TITLE" : "Player Profiles"
   },
   {
      "@" : "The Fat Jewish Gets Tattewish - Outtakes.mkv",
      "WIDTH" : "1920",
      "HEIGHT" : "1080",
      "CREATION_TIME" : "2016-10-16T16:11:23.000000Z",
      "DURATION" : "168.1040000",
      "TITLE" : "The Fat Jewish Gets Tattewish - Outtakes"
   },
   {
      "@" : "The Governor's Ball Takeover.mkv",
      "WIDTH" : "1920",
      "HEIGHT" : "1080",
      "CREATION_TIME" : "2016-10-16T16:24:23.000000Z",
      "DURATION" : "165.4590000",
      "TITLE" : "The Governor's Ball Takeover"
   }
]
Any help greatly appreciated ! Thanks.

Re: Reading codec info in some video files

Reply #14
I'm no help, but I'd be very interested in this too. I've added Music Videos to my foobar, but it is a bit of a nuisance to manage them with m-TAGS, appending new files and such.

Re: Reading codec info in some video files

Reply #15
Today I use only one way to play local video files - that with foo_yutube by 3dyd.
It has the ability to display resolution of the video file using %video_file_stats% in title field (only in playback mode).
For fb2k I have no experience, unfortunately, using other methods besides this.

Re: Reading codec info in some video files

Reply #16
Sergey, you mean that I would have to play each and every one of my hundreds of video files to read their resolution ? I guess that won't work for me, lol

I'm trying to create a Windows script that :
- Scans a given folder recursively for video files (mkv, mp4, avi, etc.)
- Extracts their width and height (using ffprobe)
- Inserts that info at the right places into already existing "!.tags" files that are in the same folders as the videos

So far I've managed to create a script that :
- Scans a given folder recursively for video files (mkv, mp4, avi)
- Extracts their width and height (using ffprobe)
- Writes that info to a bunch of "index.txt" files located in the same folder as the video files

Now I'd need another script to recursively :
- Parse every "index.txt" file for all lines starting with ""@"" (lines 1, 4, 7, 10, 13, 16, and so on)
- Parse the "!.tags" file located in the same folder for exactly the same text
- Append the two next lines of the "index.txt" file right after the found text in the "!.tags" file (lines 2,3, lines 5-6, lines 8-9, and so on)

If anybody has experience with Windows scripting, I will give him all the info. I know it's feasible, I just need some help to finish it. Thanks !

Re: Reading codec info in some video files

Reply #17
@wcs13 , if all video files would be in one folder
1) Create bat-file with command
Code: [Select]
FOR %%A IN (%*) DO "ffprobe" -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 %%A >"%~dp0%%~nA.txt"
and place it to folder with video files
2) Select all video files and drag-n-drop them on bat-file.
txt files with the same names as video files will be created.
3) Create in the same folder bat-file with command
Code: [Select]
copy /b *.txt out.txt
and just run it. File out.txt with many rows will be created.
4) Open out.txt, remove last empty row, select all and copy
5) Add all your !.tags files to playlist in fb2k sorted by name, (because copy /b command use sorting by name when merging txt files) select all, Properties->Tools->Automatically fill values->Source: Clipboard, Pattern %resolution% (or any name that you want)

Re: Reading codec info in some video files

Reply #18
Rollin, I have thousands of video files, located in hundreds of folders.
There is ONE root folder, but I can't move all video files to the same folder. That's impossible.
So I need a recursive script.

Here's the current state of my recursive script. What do you think ?

Code: [Select]
CALL :treeProcess
GOTO :eof

:treeProcess
FOR %%F IN (*.mkv, *.mp4, *.avi, *.wmv, *.mpg, *.ts) DO (
    ECHO "@" : "%%F", >> index.txt
    "C:\Program Files\FFmpeg\bin\ffprobe.exe" "%%F" -v error -of flat=s=_ -select_streams v:0 -show_entries stream=width -print_format xml >> index.txt
    "C:\Program Files\FFmpeg\bin\ffprobe.exe" "%%F" -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height -print_format xml >> index.txt
)
FOR /D %%d IN (*) DO (
    CD %%d
    cALL :treeProcess
    CD ..
)

EXIT /b

Re: Reading codec info in some video files

Reply #19
Rollin, I have thousands of video files, located in hundreds of folders.
There is ONE root folder, but I can't move all video files to the same folder. That's impossible.
So I need a recursive script.

Here's the current state of my recursive script. What do you think ?

Code: [Select]
CALL :treeProcess
GOTO :eof

:treeProcess
FOR %%F IN (*.mkv, *.mp4, *.avi, *.wmv, *.mpg, *.ts) DO (
    ECHO "@" : "%%F", >> index.txt
    "C:\Program Files\FFmpeg\bin\ffprobe.exe" "%%F" -v error -of flat=s=_ -select_streams v:0 -show_entries stream=width -print_format xml >> index.txt
    "C:\Program Files\FFmpeg\bin\ffprobe.exe" "%%F" -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height -print_format xml >> index.txt
)
FOR /D %%d IN (*) DO (
    CD %%d
    cALL :treeProcess
    CD ..
)

EXIT /b

Modified it a bit , I think this is what you asked for.

Code: [Select]
setlocal enableDelayedExpansion

CALL :treeProcess
GOTO :eof

:treeProcess
FOR %%f IN (*.mkv, *.mp4, *.avi, *.wmv, *.mpg, *.ts) DO (
ECHO [ > "%%~nf.tags"
ECHO { >> "%%~nf.tags"
    ECHO "@" : "%%f", >> "%%~nf.tags"
"C:\Program Files\FFmpeg\bin\ffprobe.exe" -v error -select_streams v:0 -show_entries stream=width -of csv=s=x:p=0 "%%f"  > "%%~nf.width.txt"
set /p width= < "%%~nf.width.txt"
"C:\Program Files\FFmpeg\bin\ffprobe.exe" -v error -select_streams v:0 -show_entries stream=height -of csv=s=x:p=0 "%%f"  > "%%~nf.height.txt"
set /p height= < "%%~nf.height.txt"
ECHO "WIDTH": "!width!", >> "%%~nf.tags"
ECHO "HEIGHT": "!height!" >> "%%~nf.tags"
del "%%~nf.width.txt"
del "%%~nf.height.txt"
ECHO } >> "%%~nf.tags"
ECHO ] >> "%%~nf.tags"
)
FOR /D %%d IN (*) DO (
    CD %%d
    CALL :treeProcess
    CD ..
)

EXIT /b

Re: Reading codec info in some video files

Reply #20
Thank you zeremy. :) I have just tested your script on some test files. It works... but not as it should  :D Maybe you don't know how the m-TAGS component for foobar works, so here it is :

1. All the .tags files generated by the m-TAGS component have the same exact name : "!.tags". Litterally, with an exclamation mark. Not "[nameofthevideo].tags".

2. Every "!.tags" file contains info for one or several video files. Like I said, here's an example when several video files are in the same folder (which is the case for the featurettes) :

Code: [Select]
[
   {
      "@" : "Creating Nerve.mkv",
      "CREATION_TIME" : "2016-10-16T15:51:50.000000Z",
      "DATE" : "2016",
      "DURATION" : "1606.3550000",
      "ENCODER" : "libebml v1.3.3 + libmatroska v1.4.4",
      "GENRE" : "Featurettes",
      "TITLE" : "Creating Nerve",
   },
   {
      "@" : "Player Profiles.mkv",
      "CREATION_TIME" : "2016-10-16T16:03:56.000000Z",
      "DURATION" : "347.6030000",
      "TITLE" : "Player Profiles"
   },
   {
      "@" : "The Fat Jewish Gets Tattewish - Outtakes.mkv",
      "CREATION_TIME" : "2016-10-16T16:11:23.000000Z",
      "DURATION" : "168.1040000",
      "TITLE" : "The Fat Jewish Gets Tattewish - Outtakes"
   },
   {
      "@" : "The Governor's Ball Takeover.mkv",
      "CREATION_TIME" : "2016-10-16T16:24:23.000000Z",
      "DURATION" : "165.4590000",
      "TITLE" : "The Governor's Ball Takeover"
   }
]
What I need is for the WIDTH and HEIGHT info to be inserted into each "!.tags" file, but always at the right places in the file ! Appending them at the end of the file simply won't work.

Here's an example of how the previous "!.tags" file should be once the WIDTH and HEIGHT info are inserted at the right places :

Code: [Select]
[
   {
      "@" : "Creating Nerve.mkv",
      "WIDTH" : "1920",
      "HEIGHT" : "1080",
      "CREATION_TIME" : "2016-10-16T15:51:50.000000Z",
      "DATE" : "2016",
      "DURATION" : "1606.3550000",
      "ENCODER" : "libebml v1.3.3 + libmatroska v1.4.4",
      "GENRE" : "Featurettes",
      "TITLE" : "Creating Nerve",
   },
   {
      "@" : "Player Profiles.mkv",
      "WIDTH" : "1920",
      "HEIGHT" : "1080",
      "CREATION_TIME" : "2016-10-16T16:03:56.000000Z",
      "DURATION" : "347.6030000",
      "TITLE" : "Player Profiles"
   },
   {
      "@" : "The Fat Jewish Gets Tattewish - Outtakes.mkv",
      "WIDTH" : "1920",
      "HEIGHT" : "1080",
      "CREATION_TIME" : "2016-10-16T16:11:23.000000Z",
      "DURATION" : "168.1040000",
      "TITLE" : "The Fat Jewish Gets Tattewish - Outtakes"
   },
   {
      "@" : "The Governor's Ball Takeover.mkv",
      "WIDTH" : "1920",
      "HEIGHT" : "1080",
      "CREATION_TIME" : "2016-10-16T16:24:23.000000Z",
      "DURATION" : "165.4590000",
      "TITLE" : "The Governor's Ball Takeover"
   }
]
Or this if you prefer, nevermind :

Code: [Select]
[
   {
      "@" : "Creating Nerve.mkv",
      "CREATION_TIME" : "2016-10-16T15:51:50.000000Z",
      "DATE" : "2016",
      "DURATION" : "1606.3550000",
      "ENCODER" : "libebml v1.3.3 + libmatroska v1.4.4",
      "GENRE" : "Featurettes",
      "TITLE" : "Creating Nerve",
      "WIDTH" : "1920",
      "HEIGHT" : "1080"
   },
   {
      "@" : "Player Profiles.mkv",
      "CREATION_TIME" : "2016-10-16T16:03:56.000000Z",
      "DURATION" : "347.6030000",
      "TITLE" : "Player Profiles",
      "WIDTH" : "1920",
      "HEIGHT" : "1080"
   },
   {
      "@" : "The Fat Jewish Gets Tattewish - Outtakes.mkv",
      "CREATION_TIME" : "2016-10-16T16:11:23.000000Z",
      "DURATION" : "168.1040000",
      "TITLE" : "The Fat Jewish Gets Tattewish - Outtakes",
      "WIDTH" : "1920",
      "HEIGHT" : "1080"
   },
   {
      "@" : "The Governor's Ball Takeover.mkv",
      "CREATION_TIME" : "2016-10-16T16:24:23.000000Z",
      "DURATION" : "165.4590000",
      "TITLE" : "The Governor's Ball Takeover",
      "WIDTH" : "1920",
      "HEIGHT" : "1080"
   }
]
So, we're making progress, but we're not there yet :) Thanks !

Re: Reading codec info in some video files

Reply #21
IMO for video files it is better to create the m-tags from scratch and separately for each file using the filename.
The !.tags format has its limitations in this case and not so practical for different video files in the same folder.
Artwork poster - background , video thumbnail , movie.nfo etc can be located and displayed in foobar2000 using the filename as reference.

The metadata can be retrieved by using ffprobe to ouput as json and then via cmd-line json parser jq create the valid .tags file.
sample ffprobe
https://gist.github.com/nrk/2286511

Using jq you can filter the required metadata from ffprobe and construct the <filename>.tags

jq
https://stedolan.github.io/jq/

A sample of a script using jq from @Bonaparte
http://pastebin.com/MMm1jCn8

I used his sample as a reference to create a script that create tags for radio streaming urls ( using jscript + shell script)

I think this is the best way to approach your issue. 

Re: Reading codec info in some video files

Reply #22
Thanks zeremy. Maybe I could implement this. Let me think about it.

Re: Reading codec info in some video files

Reply #23
OK, I have been though some testing, and it's not easy as it seems :

1. First, let's all understand that I've been through hundreds of hours of painful tagging to get all my actual "!.tags" files. So just deleting their contents and starting over is out of the question

2. I would have thought that foo_tags could automatically rename the existing "!.tags" files into "[filename].tags", but that's not what happens

3. So far, on a "TEST" root folder with some subfolders, I have managed to create "[filename].tags" files for every individual video file. Of course my existing "!.tags" files remain.

4. So now, how could I safely transfer all the information from my "!.tags" files :
- To the corresponding "[filename].tags" files in the same folder, when there is only ONE video file in that folder ?
- To all the "[filename].tags" files in the same folder, when there is more than one video file in that folder ?
That looks quite impossible to me.


 
SimplePortal 1.0.0 RC1 © 2008-2018