FFprobe and Windows Powershell

In a previous entry ( Link) I mentioned that by using the ‘grep’ command within the command line in Linux, you are able to select specific information and only output that from a FFprobe result. Grep stands for global / regular expression / print. This avoids having a lot of unnecessary data. Whilst dealing with the video format here, I was pushed into finding the Windows answer!

.mp4 is a hugely common file extension but when dealing with proprietary surveillance video streams, the existence of a common file extension means very little. Each file had a simple naming convention of Ch01_DateTime.mp4. They also came with a player TVR_Player.exe.

Player Interface

Player Interface

Player version

Player version

The player has a common interface and is very similar to the Alien DVR Export Player and LJD Colossus Player. There are a few menu differences though; in particular, the LJD has an option for rewrapping into avi. Loading the mp4 files supplied here into both of the other players produced a negative result. The player that they came with had an interesting option though, ‘drop B Frames’. Why an evidential export player should even allow you to drop frames is a little bit worrying but I digress….

The video files appeared to play fine within the supplied player and a nice surprise was that it also displayed frame numbers. Due to the amount of video files, playing each one within the supplied player would be time consuming.

Analysing the video data within FFprobe verified the total number of frames along with some useful information on the video dimension, duration and encoding .

I used the command:

ffprobe -show_streams -count_frames -pretty input.mp4 > out.txt

This resulted in a .txt file detailing all the information about the video along with the number of read frames:

[STREAM]

index=0

codec_name=h264

codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10

profile=Baseline

codec_type=video

codec_time_base=0/2

codec_tag_string=[0][0][0][0]

codec_tag=0x0000

width=704

height=288

has_b_frames=0

sample_aspect_ratio=0:1

display_aspect_ratio=0:1

pix_fmt=yuv420p

level=20

timecode=N/A

is_avc=0

nal_length_size=0

id=0x1e0

r_frame_rate=90000/1

avg_frame_rate=0/0

time_base=1/90000

start_pts=357488898

start_time=1:06:12.098867

duration_ts=291594374

duration=0:53:59.937489

bit_rate=N/A

nb_frames=N/A

nb_read_frames=48601

nb_read_packets=N/A

DISPOSITION:default=0

DISPOSITION:dub=0

DISPOSITION:original=0

DISPOSITION:comment=0

DISPOSITION:lyrics=0

DISPOSITION:karaoke=0

DISPOSITION:forced=0

DISPOSITION:hearing_impaired=0

DISPOSITION:visual_impaired=0

DISPOSITION:clean_effects=0

DISPOSITION:attached_pic=0

[/STREAM]

Before tidying the video streams up, I wanted to verify their GOP structure. By using the following ffprobe command, the resulting text file details all information about every single frame in the video – A LOT OF DETAIL!

ffprobe -show_frames -pretty in.mp4 > out.txt

In Linux, it is possible to alter the output by using Grep command but in windows, there is another method…..Windows Powershell.

This can be found in all Win7 and Win8 machines, hidden away in the Accessories. There is an Integrated Scripting Enviroment (ISE) that allows you to save commands and then run them as standalone commands. For this job though I kept with the basic Powershell  and used Cmdlets!

Cmdlets are very similar to using the individual commands in ffmpeg so once you get to grips with that you are good to go!

You can see a list of all the Cmdlets here:

http://technet.microsoft.com/library/ee176842.aspx

Windows Powershell

Windows Powershell

The script I needed to get rid of all the unnecessary information was

Get-Content C:\Users\David\Desktop\gop\in.txt | Select-String “pict_type”,”coded_picture_number” | Out-File C:\Users\David\Desktop\gop\out.txt

Breaking this down…..I needed to get the content from the in.txt file, I needed to select only the strings documented in the variable, I needed to output a file called out.txt

pict_type=I

coded_picture_number=0

pict_type=P

coded_picture_number=1

pict_type=P

coded_picture_number=2

pict_type=P

coded_picture_number=3

pict_type=P

coded_picture_number=4

pict_type=P

coded_picture_number=5

pict_type=P

coded_picture_number=6

pict_type=P

coded_picture_number=7

pict_type=P

coded_picture_number=8

pict_type=P

coded_picture_number=9

pict_type=P

coded_picture_number=10

etc etc etc……

It turned out I had a 60 frame Gop!

( I am working on using the ConvertTo-Html Cmdlet to output both FFprobe results into a single, formatted and headed HTML report. I will keep you posted on that one!)

The original mp4’s would not play well in Virtualdub or any other standard video tool so now that we had identified Duration, Frame count, GOP structure etc, it was back into FFmpeg to rewrap.

ffmpeg -i in.mp4 -vsync drop -f avi -vcodec copy -r 15 out.avi

This did the job nicely and the resulting avi played and scrubbed perfectly. However – I had a fair few to do. One at a time would have been tedious so I quickly wrote a FFmpeg preset using the command above in Another GUI. This is another handy tool and works really well with many other command line programs, not just FFmpeg. Another bonus is that it can run several processes concurrently.

The result was a folder full of video that had not been transcoded but was being read correctly and all dropped straight into Forevid with no effort……and because I knew the GOP structure I could navigate to I frames using Forevids frame number function.

The powershell is definitely going to become a very handy tool!

Advertisements
By Spreadys Posted in EEPIP

5 comments on “FFprobe and Windows Powershell

  1. Pingback: .264 files and FFmpeg | Spreadys Space

  2. Pingback: Stream Mapping from Vista Quantum Files | Spreadys Space

  3. Pingback: Update on I frame only extraction | Spreadys Space

  4. Pingback: SSF Files with BKPlayer.exe | Spreadys Space

  5. You could achieve something potentially similar (visualizing the number and types of frames ) using the plotframes tool in the latest ffmpeg distribution from git.

    .ffmpeg/tools/plotframes -i video.mp4 [-t svg -o video.svg]

    The -t and -o flags are optional and sets the terminal and the output file respectively. A lot of options are available to set the terminal from the gnuplot manual or typing set terminal within the gnuplot environment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s