INPUT_FILES=(
 "cbcs/tos-8s-1.cmfv"
 "cbcs/tos-8s-2.cmfv"
 "cbcs/tos-8s-3.cmfv"
 "cbcs/tos-8s-4.cmfv"
 "cbcs/tos-8s-64k.cmfa"
 "cbcs/tos-8s-128k.cmfa"
)

for file in "${INPUT_FILES[@]}"; do
  echo "Processing $file"
  ffmpeg -i "$file" -c:v libx264 -preset ultrafast -crf 23 -c:a aac -b:a 128k -ar 48000 -ac 2 -f mp4 -movflags +faststart -y "${file%.cmfv}.mp4"
done


        // // Function to parse DASH manifest and add subtitles
        // async function addSubtitlesFromDASH(player, manifestUrl) {
        //   try {
        //     console.log('Fetching DASH manifest:', manifestUrl);
        //     const response = await fetch(manifestUrl);
        //     const manifestText = await response.text();
        //     console.log('DASH manifest loaded');
            
        //     // Parse XML manifest
        //     const parser = new DOMParser();
        //     const manifestDoc = parser.parseFromString(manifestText, 'text/xml');
            
        //     // Find all AdaptationSet with contentType="text"
        //     const textAdaptationSets = manifestDoc.querySelectorAll('AdaptationSet[contentType="text"]');
        //     console.log('Found text adaptation sets:', textAdaptationSets.length);
            
        //     for (let i = 0; i < textAdaptationSets.length; i++) {
        //       const adaptationSet = textAdaptationSets[i];
        //       const roleElement = adaptationSet.querySelector('Role[schemeIdUri="urn:mpeg:dash:role:2011"]');
              
        //       if (roleElement && roleElement.getAttribute('value') === 'subtitle') {
        //         const representation = adaptationSet.querySelector('Representation');
        //         if (representation) {
        //           const representationId = representation.getAttribute('id');
        //           const baseUrl = adaptationSet.querySelector('BaseURL')?.textContent || '';
                  
        //           // Extract language from representation ID (e.g., "textstream_eng=1000" -> "eng")
        //           const langMatch = representationId.match(/textstream_([^=]+)/);
        //           const language = langMatch ? langMatch[1] : 'unknown';
                  
        //           // Create subtitle URL
        //           const subtitleUrl = manifestUrl.replace('.mpd', '') + '/' + baseUrl + representationId + '.vtt';
                  
        //           console.log('Adding subtitle:', {
        //             language: language,
        //             url: subtitleUrl,
        //             representationId: representationId
        //           });
                  
        //           // Add subtitle track
        //           player.addRemoteTextTrack({
        //             kind: 'subtitles',
        //             language: language,
        //             label: language === 'eng' ? 'English' : language === 'zh-hans' ? 'Chinese' : language,
        //             src: subtitleUrl,
        //             default: false
        //           }, false);
        //         }
        //       }
        //     }
            
        //     console.log('Subtitles added from DASH manifest');
        //   } catch (error) {
        //     console.error('Error adding subtitles from DASH manifest:', error);
        //   }
        // }

        // Add subtitles when player is ready
        drmPlayer.on("ready", function () {
          console.log("DRM Player ready, adding test subtitles...");
          addTestSubtitles(drmPlayer.player);
        });

        // Function to add test subtitles
        function addTestSubtitles(player) {
          try {
            // English subtitle
            const englishVTT = `WEBVTT

00:00:01.000 --> 00:00:04.000
This is a test English subtitle

00:00:05.000 --> 00:00:08.000
Testing subtitle functionality

00:00:10.000 --> 00:00:13.000
English subtitles are working!`;

            // Vietnamese subtitle
            const vietnameseVTT = `WEBVTT

00:00:01.000 --> 00:00:04.000
Đây là phụ đề tiếng Việt thử nghiệm

00:00:05.000 --> 00:00:08.000
Đang kiểm tra chức năng phụ đề

00:00:10.000 --> 00:00:13.000
Phụ đề tiếng Việt đang hoạt động!`;

            // Add English subtitle
            const englishTrack = player.addRemoteTextTrack({
              kind: 'subtitles',
              language: 'en',
              label: 'English',
              src: 'data:text/vtt;base64,' + btoa(englishVTT),
              default: false
            }, false);

            // Add Vietnamese subtitle
            const vietnameseTrack = player.addRemoteTextTrack({
              kind: 'subtitles',
              language: 'vi',
              label: 'Tiếng Việt',
              src: 'data:text/vtt;base64,' + btoa(vietnameseVTT),
              default: false
            }, false);

            console.log('Test subtitles added:', {
              english: englishTrack.track,
              vietnamese: vietnameseTrack.track
            });

          } catch (error) {
            console.error('Error adding test subtitles:', error);
          }
        }