@@ -1029,3 +1029,55 @@ def write(self, data):
10291029 RuntimeError , match = "File like object must implement a seek method"
10301030 ):
10311031 encoder .to_file_like (NoSeekMethod (), format = "mp4" )
1032+
1033+ def get_video_metadata_from_file (self , file_path ):
1034+ """Helper function to get video metadata from a file using ffprobe.
1035+
1036+ Returns a dict with codec_name, profile, pix_fmt, etc.
1037+ """
1038+ result = subprocess .run (
1039+ [
1040+ "ffprobe" ,
1041+ "-v" ,
1042+ "error" ,
1043+ "-select_streams" ,
1044+ "v:0" ,
1045+ "-show_entries" ,
1046+ "stream=codec_name,profile,pix_fmt" ,
1047+ "-of" ,
1048+ "default=noprint_wrappers=1" ,
1049+ str (file_path ),
1050+ ],
1051+ check = True ,
1052+ capture_output = True ,
1053+ text = True ,
1054+ )
1055+ # Parse output like "codec_name=h264\nprofile=Baseline\npix_fmt=yuv420p"
1056+ metadata = {}
1057+ for line in result .stdout .strip ().split ("\n " ):
1058+ if "=" in line :
1059+ key , value = line .split ("=" , 1 )
1060+ metadata [key ] = value
1061+ return metadata
1062+
1063+ @pytest .mark .skipif (in_fbcode (), reason = "ffprobe not available" )
1064+ def test_codec_options_profile (self , tmp_path ):
1065+ # Test that we can set the H.264 profile via codec_options
1066+ # and validate it was used by checking with ffprobe.
1067+ source_frames = torch .zeros ((5 , 3 , 64 , 64 ), dtype = torch .uint8 )
1068+ encoder = VideoEncoder (frames = source_frames , frame_rate = 30 )
1069+
1070+ # Encode with baseline profile (explicitly specified via codec_options)
1071+ output_path = tmp_path / "output_baseline.mp4"
1072+ encoder .to_file (
1073+ dest = str (output_path ),
1074+ codec_options = {"profile" : "baseline" },
1075+ )
1076+
1077+ # Validate the profile was used
1078+ metadata = self .get_video_metadata_from_file (output_path )
1079+ assert metadata .get ("codec_name" ) == "h264"
1080+ assert metadata .get ("profile" ) in (
1081+ "Baseline" ,
1082+ "Constrained Baseline" ,
1083+ ), f"Expected Baseline profile, got { metadata .get ('profile' )} "
0 commit comments