Notifications
Clear all

[Closed] video metadata

The great thing about getting the info in JSON format is that it is easily readable without having to resort to looking for any documentation.

If you uncomment the line

format "%
" l

You will get some output like this below. Without trying too hard, you can see that it contains two streams, one video, one audio. All the other data you would need is listed, so you can decide how to parse it based on the examples provided already.


{
    "streams": [
        {
            "index": 0,
            "codec_name": "h264",
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "profile": "Main",
            "codec_type": "video",
            "codec_time_base": "1/50",
            "codec_tag_string": "avc1",
            "codec_tag": "0x31637661",
            "width": 1280,
            "height": 720,
            "has_b_frames": 1,
            "sample_aspect_ratio": "0:1",
            "display_aspect_ratio": "0:1",
            "pix_fmt": "yuv420p",
            "level": 51,
            "r_frame_rate": "25/1",
            "avg_frame_rate": "25/1",
            "time_base": "1/25",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 31453,
            "duration": "1258.120000",
            "bit_rate": "441269",
            "nb_frames": "31453",
            "disposition": {
                "default": 0,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0
            },
            "tags": {
                "creation_time": "2012-03-24 09:25:52",
                "language": "eng",
                "handler_name": "Apple Video Media Handler"
            }
        },
        {
            "index": 1,
            "codec_name": "aac",
            "codec_long_name": "AAC (Advanced Audio Coding)",
            "codec_type": "audio",
            "codec_time_base": "1/44100",
            "codec_tag_string": "mp4a",
            "codec_tag": "0x6134706d",
            "sample_fmt": "fltp",
            "sample_rate": "44100",
            "channels": 2,
            "bits_per_sample": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/44100",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 55483392,
            "duration": "1258.126803",
            "bit_rate": "127999",
            "nb_frames": "54183",
            "disposition": {
                "default": 0,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0
            },
            "tags": {
                "creation_time": "2012-03-24 09:25:52",
                "language": "eng",
                "handler_name": "Apple Sound Media Handler"
            }
        }
    ],
    "format": {
        "filename": "C:\	emp\\TestFile.mp4",
        "nb_streams": 2,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "1258.120000",
        "size": "90237437",
        "bit_rate": "573792",
        "tags": {
            "major_brand": "mp42",
            "minor_version": "1",
            "compatible_brands": "mp42mp41",
            "creation_time": "2012-03-24 09:25:52"
        }
    }
}

Can’t seem to get frame rate to work:


 
 	struct vidOps (width,height,filename,duration,frame_rate,frames,sizeMB)
 	vidInfo = VidOps()
 	 
 	ffProbePath	= "C:\ffprobe.exe"
 	
 	theFile =  "C:\Documents and Settings\Owner\Desktop\video-example.mp4"
 	
 	if doesfileexist theFile then
 	(
 		args = " -v quiet -print_format json -show_format -show_streams " +"\""  + theFile +"\""
 			
 		proc = dotnetobject "system.diagnostics.process"			
 		proc.StartInfo.FileName = ffProbePath			
 		proc.StartInfo.Arguments = args 
 		proc.StartInfo.RedirectStandardOutput = true
 		-- needs UseShellExecute set to false in order to redirect IO streams	
 		proc.StartInfo.UseShellExecute = false		
 		proc.StartInfo.CreateNoWindow = true
 	
 		proc.Start()
 		reader = proc.StandardOutput
 									
 		while (l = reader.readline()) != undefined do
 		(
 		parseOutLine = trimright (trimleft l "\" ") "\""
 			
 			case of 
 			(
 				(matchpattern parseOutLine pattern:"*filename*"):(vidInfo.filename=(filterstring parseOutLine " ,\"")[3])
 				(matchpattern parseOutLine pattern:"*width*"):(vidInfo.width=((filterstring parseOutLine " ,")[2]) as integer)
 				(matchpattern parseOutLine pattern:"*height*"):(vidInfo.height=(filterstring parseOutLine " ,")[2] as integer)
 				(matchpattern parseOutLine pattern:"*duration\":*"):(vidInfo.duration=((filterstring parseOutLine " ,\"")[3] as float/60))
 								
 			--	"width": 1280,	
 			--	"duration": "1239.195267",
 			--	"r_frame_rate": "35029/1461",
 				
 				(matchpattern parseOutLine pattern:"*r_frame_rate\":*"):(vidInfo.frame_rate=((filterstring parseOutLine " ,\"")[3] as float))
 
 
 			--	(matchpattern parseOutLine pattern:"*r_frame_rate*"):(vidInfo.frame_rate=((filterstring parseOutLine " ,")[2]) as float)
 
 				
 				(matchpattern parseOutLine pattern:"*frames\":*"):(vidInfo.frames=((filterstring parseOutLine " ,\"")[3] as integer))
 
 				(matchpattern parseOutLine pattern:"*size\":*"):(vidInfo.sizeMB=((filterstring parseOutLine " ,\"")[3] as float/1024./1024.))
 			)
 		)
 		proc.Close()
 		vidInfo	
 			
 	)
 	
 	
 	
 
 
 
 
 
 

its because frame rate isnt stored as a float. Its a fraction. So you grab the string and execute it. you’ll have to make sure you don’t grab the audio frame rate as its stored under the same parameter name. The example I give here work on my file but im not sure how robust it is.

	struct vidOps (width,height,filename,duration,frame_rate,frames,sizeMB)
 	vidInfo = VidOps()
 	 
 	ffProbePath	= "C:\ffprobe.exe"
 	
 	theFile =  "C:\Documents and Settings\Owner\Desktop\video-example.mp4"
 	
 	if doesfileexist theFile then
 	(
 		args = " -v quiet -print_format json -show_format -show_streams " +"\""  + theFile +"\""
 			
 		proc = dotnetobject "system.diagnostics.process"			
 		proc.StartInfo.FileName = ffProbePath			
 		proc.StartInfo.Arguments = args 
 		proc.StartInfo.RedirectStandardOutput = true
 		-- needs UseShellExecute set to false in order to redirect IO streams	
 		proc.StartInfo.UseShellExecute = false		
 		proc.StartInfo.CreateNoWindow = true
 	
 		proc.Start()
 		reader = proc.StandardOutput
 									
 		while (l = reader.readline()) != undefined do
 		(
 		parseOutLine = trimright (trimleft l "\" ") "\""
 			
 			case of 
 			(
 				(matchpattern parseOutLine pattern:"*filename*"):(vidInfo.filename=(filterstring parseOutLine " ,\"")[3])
 				(matchpattern parseOutLine pattern:"*width*"):(vidInfo.width=((filterstring parseOutLine " ,")[2]) as integer)
 				(matchpattern parseOutLine pattern:"*height*"):(vidInfo.height=(filterstring parseOutLine " ,")[2] as integer)
 				(matchpattern parseOutLine pattern:"*duration\":*"):(vidInfo.duration=((filterstring parseOutLine " ,\"")[3] as float/60))
 				(matchpattern parseOutLine pattern:"*r_frame_rate\":*"):						
						(
						local rate = (filterstring parseOutLine " ,\"")[3] 
						if rate != "0/0" then vidInfo.frame_rate = (execute rate)
						)					
				(matchpattern parseOutLine pattern:"*frames\":*"):(vidInfo.frames=((filterstring parseOutLine " ,\"")[3] as integer))
  				(matchpattern parseOutLine pattern:"*size\":*"):(vidInfo.sizeMB=((filterstring parseOutLine " ,\"")[3] as float/1024./1024.))
 			)
 		)
 		proc.Close()
 		vidInfo	
 			
 	)
 	

Hi Artur, I hope you are well. Thanks! Symlinks are useful!

Everything works now. Thanks for help

Page 2 / 2