Recherche avancée

Médias (2)

Mot : - Tags -/doc2img

Autres articles (60)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

  • Contribute to documentation

    13 avril 2011

    Documentation is vital to the development of improved technical capabilities.
    MediaSPIP welcomes documentation by users as well as developers - including : critique of existing features and functions articles contributed by developers, administrators, content producers and editors screenshots to illustrate the above translations of existing documentation into other languages
    To contribute, register to the project users’ mailing (...)

  • Submit bugs and patches

    13 avril 2011

    Unfortunately a software is never perfect.
    If you think you have found a bug, report it using our ticket system. Please to help us to fix it by providing the following information : the browser you are using, including the exact version as precise an explanation as possible of the problem if possible, the steps taken resulting in the problem a link to the site / page in question
    If you think you have solved the bug, fill in a ticket and attach to it a corrective patch.
    You may also (...)

Sur d’autres sites (5540)

  • Error initializing FFmpegKit : "TypeError : Cannot read property 'getLogLevel' of null" in React Native

    9 janvier, par Md Monirozzaman khan

    I'm developing a React Native application where I need to process videos using the ffmpeg-kit-react-native library. However, I'm encountering an issue during the initialization of FFmpegKitConfig. The error message is :

    


    ERROR  Error initializing FFmpegKit: [TypeError: Cannot read property 'getLogLevel' of null]


    


    Here is my App.js code

    


    

    

    import React, { useState, useEffect } from &#x27;react&#x27;;&#xA;import { StyleSheet, Text, View, TouchableOpacity, Alert, Dimensions, ScrollView, LayoutAnimation, UIManager, Platform } from &#x27;react-native&#x27;;&#xA;import * as ImagePicker from &#x27;expo-image-picker&#x27;;&#xA;import * as FileSystem from &#x27;expo-file-system&#x27;;&#xA;import { Video } from &#x27;expo-av&#x27;;&#xA;import { MaterialIcons } from &#x27;@expo/vector-icons&#x27;;&#xA;import { FFmpegKit, FFmpegKitConfig, ReturnCode } from &#x27;ffmpeg-kit-react-native&#x27;;&#xA;&#xA;const windowWidth = Dimensions.get(&#x27;window&#x27;).width;&#xA;&#xA;if (Platform.OS === &#x27;android&#x27;) {&#xA;  UIManager.setLayoutAnimationEnabledExperimental &amp;&amp; UIManager.setLayoutAnimationEnabledExperimental(true);&#xA;}&#xA;&#xA;export default function App() {&#xA;  const [videoFiles, setVideoFiles] = useState([]);&#xA;  const [isGridView, setIsGridView] = useState(false);&#xA;  const [isConverting, setIsConverting] = useState(false);&#xA;&#xA;  useEffect(() => {&#xA;    FFmpegKitConfig.init()&#xA;      .then(() => {&#xA;        console.log(&#x27;FFmpegKit initialized&#x27;);&#xA;      })&#xA;      .catch((error) => {&#xA;        console.error(&#x27;Error initializing FFmpegKit:&#x27;, error);&#xA;      });&#xA;  }, []);&#xA;&#xA;  const pickVideo = async () => {&#xA;    const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();&#xA;    if (status !== &#x27;granted&#x27;) {&#xA;      alert(&#x27;Sorry, we need media library permissions to make this work!&#x27;);&#xA;      return;&#xA;    }&#xA;&#xA;    let result = await ImagePicker.launchImageLibraryAsync({&#xA;      mediaTypes: ImagePicker.MediaTypeOptions.Videos,&#xA;      allowsMultipleSelection: true,&#xA;    });&#xA;&#xA;    if (!result.canceled &amp;&amp; result.assets.length > 0) {&#xA;      const newFiles = result.assets.filter(&#xA;        (newFile) => !videoFiles.some((existingFile) => existingFile.uri === newFile.uri)&#xA;      );&#xA;&#xA;      if (newFiles.length &lt; result.assets.length) {&#xA;        Alert.alert(&#x27;Duplicate Files&#x27;, &#x27;Some files were already added.&#x27;);&#xA;      }&#xA;&#xA;      LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);&#xA;      setVideoFiles([...videoFiles, ...newFiles]);&#xA;    }&#xA;  };&#xA;&#xA;  const convertVideos = async () => {&#xA;    setIsConverting(true);&#xA;    const outputDir = `${FileSystem.documentDirectory}Output`;&#xA;&#xA;    const dirInfo = await FileSystem.getInfoAsync(outputDir);&#xA;    if (!dirInfo.exists) {&#xA;      await FileSystem.makeDirectoryAsync(outputDir, { intermediates: true });&#xA;    }&#xA;&#xA;    for (const video of videoFiles) {&#xA;      const { uri } = video;&#xA;      const filename = uri.split(&#x27;/&#x27;).pop();&#xA;      const outputFilePath = `${outputDir}/${filename.split(&#x27;.&#x27;).slice(0, -1).join(&#x27;.&#x27;)}_modified.mp4`;&#xA;&#xA;      const ffmpegCommand = `-y -i "${uri}" -af "atempo=1.02, bass=g=4:f=80:w=3, treble=g=4:f=3200:w=3, firequalizer=gain_entry=&#x27;entry(0,0);entry(62,2);entry(125,1.5);entry(250,1);entry(500,1);entry(1000,1);entry(2000,1.5);entry(4000,2.5);entry(8000,3);entry(16000,4)&#x27;, compand=attacks=0.05:decays=0.25:points=-80/-80-50/-15-30/-10-10/-2:soft-knee=4:gain=2, deesser, highpass=f=35, lowpass=f=17000, loudnorm=I=-16:LRA=11:TP=-1.5, volume=3.9dB" -c:v copy -c:a aac -b:a 224k -ar 48000 -threads 0 "${outputFilePath}"`;&#xA;&#xA;      try {&#xA;        const session = await FFmpegKit.execute(ffmpegCommand);&#xA;        const returnCode = await session.getReturnCode();&#xA;&#xA;        if (ReturnCode.isSuccess(returnCode)) {&#xA;          console.log(`Video converted: ${outputFilePath}`);&#xA;        } else if (ReturnCode.isCancel(returnCode)) {&#xA;          console.log(&#x27;Conversion cancelled&#x27;);&#xA;        } else {&#xA;          console.error(`FFmpeg process failed: ${session.getFailStackTrace()}`);&#xA;        }&#xA;      } catch (error) {&#xA;        console.error(`Error converting video: ${error.message}`);&#xA;      }&#xA;    }&#xA;&#xA;    setIsConverting(false);&#xA;    Alert.alert(&#x27;Conversion Complete&#x27;, &#x27;All videos have been converted.&#x27;);&#xA;  };&#xA;&#xA;  const deleteVideo = (uri) => {&#xA;    LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);&#xA;    setVideoFiles(videoFiles.filter((video) => video.uri !== uri));&#xA;  };&#xA;&#xA;  const clearAllVideos = () => {&#xA;    LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);&#xA;    setVideoFiles([]);&#xA;  };&#xA;&#xA;  const toggleLayout = () => {&#xA;    LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);&#xA;    setIsGridView(!isGridView);&#xA;  };&#xA;&#xA;  return (&#xA;    <view style="{styles.container}">&#xA;      <text style="{styles.header}">Video Converter App</text>&#xA;      <touchableopacity style="{styles.addButton}">&#xA;        <text style="{styles.addButtonText}">Select or Browse Videos</text>&#xA;      </touchableopacity>&#xA;      <view style="{styles.headerContainer}">&#xA;        <text style="{styles.videoCount}">Total Videos: {videoFiles.length}</text>&#xA;        {videoFiles.length > 0 &amp;&amp; (&#xA;          &lt;>&#xA;            <touchableopacity style="{styles.clearButtonContainer}">&#xA;              <materialicons size="{24}" color="red" style="{styles.clearIcon}"></materialicons>&#xA;              <text style="{styles.clearAllText}">Clear All</text>&#xA;            </touchableopacity>&#xA;            <touchableopacity style="{styles.toggleLayoutButton}">&#xA;              <materialicons size="{24}" color="#fff"></materialicons>&#xA;            </touchableopacity>&#xA;          >&#xA;        )}&#xA;      </view>&#xA;      {isGridView ? (&#xA;        <scrollview contentcontainerstyle="{styles.gridContainer}">&#xA;          {videoFiles.map((item, index) => (&#xA;            <view key="{index}" style="{styles.videoItemGrid}">&#xA;              &#xA;              <touchableopacity>> deleteVideo(item.uri)} style={styles.deleteButtonGrid}>&#xA;                <materialicons size="{24}" color="red"></materialicons>&#xA;              </touchableopacity>&#xA;            </view>&#xA;          ))}&#xA;        </scrollview>&#xA;      ) : (&#xA;        <view style="{styles.list}">&#xA;          {videoFiles.map((item, index) => (&#xA;            <view key="{index}" style="{styles.videoItem}">&#xA;              &#xA;              <text style="{styles.fileName}">{decodeURI(item.fileName || item.uri.split(&#x27;/&#x27;).pop() || &#x27;Unknown File&#x27;)}</text>&#xA;              <touchableopacity>> deleteVideo(item.uri)} style={styles.deleteButton}>&#xA;                <materialicons size="{24}" color="red"></materialicons>&#xA;              </touchableopacity>&#xA;            </view>&#xA;          ))}&#xA;        </view>&#xA;      )}&#xA;      {videoFiles.length > 0 &amp;&amp; (&#xA;        <touchableopacity style="{styles.convertButton}" disabled="{isConverting}">&#xA;          <text style="{styles.convertButtonText}">{isConverting ? &#x27;Converting...&#x27; : &#x27;Convert&#x27;}</text>&#xA;        </touchableopacity>&#xA;      )}&#xA;    </view>&#xA;  );&#xA;}&#xA;&#xA;const styles = StyleSheet.create({&#xA;  container: {&#xA;    flex: 1,&#xA;    backgroundColor: &#x27;#fff&#x27;,&#xA;    alignItems: &#x27;center&#x27;,&#xA;    padding: 10,&#xA;  },&#xA;  header: {&#xA;    fontSize: 24,&#xA;    fontWeight: &#x27;bold&#x27;,&#xA;    marginBottom: 5,&#xA;  },&#xA;  addButton: {&#xA;    backgroundColor: &#x27;#007BFF&#x27;,&#xA;    padding: 15,&#xA;    borderRadius: 10,&#xA;    alignItems: &#x27;center&#x27;,&#xA;    marginBottom: 5,&#xA;    width: &#x27;100%&#x27;,&#xA;    elevation: 2,&#xA;    shadowColor: &#x27;#000&#x27;,&#xA;    shadowOffset: { width: 0, height: 5 },&#xA;    shadowOpacity: 0.8,&#xA;    shadowRadius: 2,&#xA;  },&#xA;  addButtonText: {&#xA;    color: &#x27;#fff&#x27;,&#xA;    fontSize: 18,&#xA;    fontWeight: &#x27;bold&#x27;,&#xA;  },&#xA;  headerContainer: {&#xA;    flexDirection: &#x27;row&#x27;,&#xA;    alignItems: &#x27;center&#x27;,&#xA;    justifyContent: &#x27;space-between&#x27;,&#xA;    width: &#x27;100%&#x27;,&#xA;    marginBottom: 10,&#xA;  },&#xA;  videoCount: {&#xA;    fontSize: 18,&#xA;  },&#xA;  clearButtonContainer: {&#xA;    flexDirection: &#x27;row&#x27;,&#xA;    alignItems: &#x27;center&#x27;,&#xA;    marginRight: 10,&#xA;  },&#xA;  clearIcon: {&#xA;    marginRight: 5,&#xA;  },&#xA;  clearAllText: {&#xA;    fontSize: 16,&#xA;    color: &#x27;red&#x27;,&#xA;    textDecorationLine: &#x27;underline&#x27;,&#xA;  },&#xA;  toggleLayoutButton: {&#xA;    backgroundColor: &#x27;#007BFF&#x27;,&#xA;    padding: 1,&#xA;    borderRadius: 8,&#xA;    alignItems: &#x27;center&#x27;,&#xA;    justifyContent: &#x27;center&#x27;,&#xA;  },&#xA;  list: {&#xA;    flex: 1,&#xA;    width: &#x27;100%&#x27;,&#xA;  },&#xA;  videoItem: {&#xA;    padding: 5,&#xA;    borderBottomColor: &#x27;#ccc&#x27;,&#xA;    borderBottomWidth: 0.7,&#xA;    flexDirection: &#x27;row&#x27;,&#xA;    alignItems: &#x27;center&#x27;,&#xA;  },&#xA;  videoItemGrid: {&#xA;    flexDirection: &#x27;column&#x27;,&#xA;    alignItems: &#x27;center&#x27;,&#xA;    margin: 4,&#xA;    borderWidth: 1,&#xA;    borderColor: &#x27;#ccc&#x27;,&#xA;    borderRadius: 8,&#xA;    padding: 2,&#xA;    position: &#x27;relative&#x27;,&#xA;  },&#xA;  thumbnail: {&#xA;    width: 70,&#xA;    height: 70,&#xA;    marginRight: 10,&#xA;  },&#xA;  thumbnailGrid: {&#xA;    width: 80,&#xA;    height: 80,&#xA;    marginBottom: 0,&#xA;  },&#xA;  fileName: {&#xA;    fontSize: 16,&#xA;    marginLeft: 10,&#xA;    flex: 1,&#xA;  },&#xA;  deleteButton: {&#xA;    marginLeft: 60,&#xA;    width: 20,&#xA;    height: 20,&#xA;  },&#xA;  deleteButtonGrid: {&#xA;    position: &#x27;absolute&#x27;,&#xA;    bottom: 5,&#xA;    right: 5,&#xA;  },&#xA;  convertButton: {&#xA;    backgroundColor: &#x27;#007BFF&#x27;,&#xA;    padding: 15,&#xA;    borderRadius: 10,&#xA;    alignItems: &#x27;center&#x27;,&#xA;    marginTop: 20,&#xA;    width: &#x27;100%&#x27;,&#xA;  },&#xA;  convertButtonText: {&#xA;    color: &#x27;#fff&#x27;,&#xA;    fontSize: 18,&#xA;    fontWeight: &#x27;bold&#x27;,&#xA;  },&#xA;  gridContainer: {&#xA;    flexDirection: &#x27;row&#x27;,&#xA;    flexWrap: &#x27;wrap&#x27;,&#xA;    justifyContent: &#x27;flex-start&#x27;,&#xA;    paddingVertical: 5,&#xA;    paddingHorizontal: 5,&#xA;    width: &#x27;100%&#x27;,&#xA;  },&#xA;});

    &#xD;&#xA;

    &#xD;&#xA;

    &#xD;&#xA;&#xA;

    App.json

    &#xA;

    &#xD;&#xA;
    &#xD;&#xA;
    {&#xA;  "expo": {&#xA;    "name": "VidoeConvert",&#xA;    "slug": "VidoeConvert",&#xA;    "version": "1.0.0",&#xA;    "orientation": "portrait",&#xA;    "icon": "./assets/icon.png",&#xA;    "userInterfaceStyle": "light",&#xA;    "splash": {&#xA;      "image": "./assets/splash.png",&#xA;      "resizeMode": "contain",&#xA;      "backgroundColor": "#ffffff"&#xA;    },&#xA;    "ios": {&#xA;      "supportsTablet": true&#xA;    },&#xA;    "android": {&#xA;      "adaptiveIcon": {&#xA;        "foregroundImage": "./assets/adaptive-icon.png",&#xA;        "backgroundColor": "#ffffff"&#xA;      },&#xA;      "package": "com.anonymous.VidoeConvert"&#xA;    },&#xA;    "web": {&#xA;      "favicon": "./assets/favicon.png"&#xA;    },&#xA;    "plugins": [&#xA;      "@config-plugins/ffmpeg-kit-react-native",&#xA;      "expo-build-properties"&#xA;    ]&#xA;  }&#xA;}

    &#xD;&#xA;

    &#xD;&#xA;

    &#xD;&#xA;&#xA;

    Package.json

    &#xA;

    &#xD;&#xA;
    &#xD;&#xA;
    {&#xA;  "name": "vidoeconvert",&#xA;  "version": "1.0.0",&#xA;  "main": "expo/AppEntry.js",&#xA;  "scripts": {&#xA;    "start": "expo start",&#xA;    "android": "expo run:android",&#xA;    "ios": "expo run:ios",&#xA;    "web": "expo start --web"&#xA;  },&#xA;  "dependencies": {&#xA;    "@config-plugins/ffmpeg-kit-react-native": "^8.0.0",&#xA;    "@expo/metro-runtime": "~3.2.1",&#xA;    "expo": "~51.0.17",&#xA;    "expo-asset": "~10.0.10",&#xA;    "expo-av": "^14.0.6",&#xA;    "expo-document-picker": "~12.0.2",&#xA;    "expo-file-system": "~17.0.1",&#xA;    "expo-image-picker": "~15.0.7",&#xA;    "expo-media-library": "~16.0.4",&#xA;    "expo-status-bar": "~1.12.1",&#xA;    "ffmpeg-kit-react-native": "^6.0.2",&#xA;    "react": "18.2.0",&#xA;    "react-dom": "18.2.0",&#xA;    "react-native": "^0.74.3",&#xA;    "react-native-document-picker": "^9.3.0",&#xA;    "react-native-ffmpeg": "^0.5.2",&#xA;    "react-native-vector-icons": "^10.1.0",&#xA;    "react-native-web": "~0.19.10",&#xA;    "expo-build-properties": "~0.12.3"&#xA;  },&#xA;  "devDependencies": {&#xA;    "@babel/core": "^7.20.0"&#xA;  },&#xA;  "private": true&#xA;}

    &#xD;&#xA;

    &#xD;&#xA;

    &#xD;&#xA;&#xA;

    Has anyone encountered a similar issue or can point me in the right direction to resolve this error ? Any help would be greatly appreciated !

    &#xA;

    How to remove the error ?

    &#xA;

    any configruation required for this project ?

    &#xA;

  • "FFmpeg : Error not transitioning to the next song in Discord Bot's queue."

    1er avril 2024, par noober

    I have 3 modules, but I'm sure the error occurs within this module, and here is the entire code within that module :

    &#xA;

    import asyncio&#xA;import discord&#xA;from discord import FFmpegOpusAudio, Embed&#xA;import os&#xA;&#xA;async def handle_help(message):&#xA;    embed = discord.Embed(&#xA;        title="Danh s&#xE1;ch lệnh cho B&#xE9; M&#xE8;o",&#xA;        description="Dưới đ&#xE2;y l&#xE0; c&#xE1;c lệnh m&#xE0; chủ nh&#xE2;n c&#xF3; thể bắt B&#xE9; M&#xE8;o phục vụ:",&#xA;        color=discord.Color.blue()&#xA;    )&#xA;    embed.add_field(name="!play", value="Ph&#xE1;t một b&#xE0;i h&#xE1;t từ YouTube.", inline=False)&#xA;    embed.add_field(name="!pause", value="Tạm dừng b&#xE0;i h&#xE1;t đang ph&#xE1;t.", inline=False)&#xA;    embed.add_field(name="!resume", value="Tiếp tục b&#xE0;i h&#xE1;t đang bị tạm dừng.", inline=False)&#xA;    embed.add_field(name="!skip", value="Chuyển đến b&#xE0;i h&#xE1;t tiếp theo trong danh s&#xE1;ch chờ.", inline=False)&#xA;    embed.add_field(name="!stop", value="Dừng ph&#xE1;t nhạc v&#xE0; cho ph&#xE9;p B&#xE9; M&#xE8;o đi ngủ tiếp.", inline=False)&#xA;    # Th&#xEA;m c&#xE1;c lệnh kh&#xE1;c theo c&#xF9;ng mẫu tr&#xEA;n&#xA;    await message.channel.send(embed=embed)&#xA;&#xA;class Song:&#xA;    def __init__(self, title, player):&#xA;        self.title = title  # Lưu trữ ti&#xEA;u đề b&#xE0;i h&#xE1;t ở đ&#xE2;y&#xA;        self.player = player&#xA;&#xA;# Th&#xEA;m đối tượng Song v&#xE0;o h&#xE0;ng đợi&#xA;def add_song_to_queue(guild_id, queues, song):&#xA;    queues.setdefault(guild_id, []).append(song)&#xA;&#xA;async def handle_list(message, queues):&#xA;    log_file_path = "C:\\Bot Music 2\\song_log.txt"&#xA;    if os.path.exists(log_file_path):&#xA;        with open(log_file_path, "r", encoding="utf-8") as f:&#xA;            song_list = f.readlines()&#xA;&#xA;        if song_list:&#xA;            embed = discord.Embed(&#xA;                title="Danh s&#xE1;ch b&#xE0;i h&#xE1;t",&#xA;                description="Danh s&#xE1;ch c&#xE1;c b&#xE0;i h&#xE1;t đ&#xE3; ph&#xE1;t:",&#xA;                color=discord.Color.blue()&#xA;            )&#xA;&#xA;            for i, song in enumerate(song_list, start=1):&#xA;                if i == 1:&#xA;                    song = "- Đang ph&#xE1;t: " &#x2B; song.strip()&#xA;                embed.add_field(name=f"B&#xE0;i h&#xE1;t {i}", value=song, inline=False)&#xA;&#xA;            await message.channel.send(embed=embed)&#xA;        else:&#xA;            await message.channel.send("Hiện kh&#xF4;ng c&#xF3; dữ liệu trong file log.")&#xA;    else:&#xA;        await message.channel.send("File log kh&#xF4;ng tồn tại.")&#xA;&#xA;async def handle_commands(message, client, queues, voice_clients, yt_dl_options, ytdl, ffmpeg_options=None, guild_id=None, data=None):&#xA;    # Nếu kh&#xF4;ng c&#xF3; ffmpeg_options, sử dụng c&#xE1;c thiết lập mặc định&#xA;    if ffmpeg_options is None:&#xA;        ffmpeg_options = {&#xA;            &#x27;before_options&#x27;: &#x27;-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5&#x27;,&#xA;            &#x27;options&#x27;: &#x27;-vn -filter:a "volume=0.25"&#x27;&#xA;        }&#xA;    &#xA;    # Khởi tạo voice_client&#xA;    if guild_id is None:&#xA;        guild_id = message.guild.id&#xA;&#xA;    if guild_id in voice_clients:&#xA;        voice_client = voice_clients[guild_id]&#xA;    else:&#xA;        voice_client = None&#xA;&#xA;    # Xử l&#xFD; lệnh !play&#xA;    if message.content.startswith("!play"):&#xA;        try:&#xA;            # Kiểm tra xem người gửi tin nhắn c&#xF3; đang ở trong k&#xEA;nh voice kh&#xF4;ng&#xA;            voice_channel = message.author.voice.channel&#xA;            # Kiểm tra xem bot c&#xF3; đang ở trong k&#xEA;nh voice của guild kh&#xF4;ng&#xA;            if voice_client and voice_client.is_connected():&#xA;                await voice_client.move_to(voice_channel)&#xA;            else:&#xA;                voice_client = await voice_channel.connect()&#xA;                voice_clients[guild_id] = voice_client&#xA;        except Exception as e:&#xA;            print(e)&#xA;&#xA;        try:&#xA;            query = &#x27; &#x27;.join(message.content.split()[1:])&#xA;            if query.startswith(&#x27;http&#x27;):&#xA;                url = query&#xA;            else:&#xA;                query = &#x27;ytsearch:&#x27; &#x2B; query&#xA;                loop = asyncio.get_event_loop()&#xA;                data = await loop.run_in_executor(None, lambda: ytdl.extract_info(query, download=False))&#xA;                if not data:&#xA;                    raise ValueError("Kh&#xF4;ng c&#xF3; dữ liệu trả về từ YouTube.")&#xA;                url = data[&#x27;entries&#x27;][0][&#x27;url&#x27;]&#xA;&#xA;            player = FFmpegOpusAudio(url, **ffmpeg_options)&#xA;            # Lấy th&#xF4;ng tin của b&#xE0;i h&#xE1;t mới đang được y&#xEA;u cầu&#xA;            title = data[&#x27;entries&#x27;][0][&#x27;title&#x27;]&#xA;            duration = data[&#x27;entries&#x27;][0][&#x27;duration&#x27;]&#xA;            creator = data[&#x27;entries&#x27;][0][&#x27;creator&#x27;] if &#x27;creator&#x27; in data[&#x27;entries&#x27;][0] else "Unknown"&#xA;            requester = message.author.nick if message.author.nick else message.author.name&#xA;                    &#xA;            # Tạo embed để th&#xF4;ng b&#xE1;o th&#xF4;ng tin b&#xE0;i h&#xE1;t mới&#xA;            embed = discord.Embed(&#xA;                title="Th&#xF4;ng tin b&#xE0;i h&#xE1;t mới",&#xA;                description=f"**B&#xE0;i h&#xE1;t:** *{title}*\n**Thời lượng:** *{duration}*\n**T&#xE1;c giả:** *{creator}*\n**Người y&#xEA;u cầu:** *{requester}*",&#xA;                color=discord.Color.green()&#xA;            )&#xA;            await message.channel.send(embed=embed)&#xA;            &#xA;            # Sau khi lấy th&#xF4;ng tin của b&#xE0;i h&#xE1;t diễn ra, gọi h&#xE0;m log_song_title với title của b&#xE0;i h&#xE1;t&#xA;            # V&#xED; dụ:&#xA;            title = data[&#x27;entries&#x27;][0][&#x27;title&#x27;]&#xA;            await log_song_title(title)&#xA;&#xA;            # Th&#xEA;m v&#xE0;o danh s&#xE1;ch chờ nếu c&#xF3; b&#xE0;i h&#xE1;t đang ph&#xE1;t&#xA;            if voice_client.is_playing():&#xA;                queues.setdefault(guild_id, []).append(player)&#xA;            else:&#xA;                voice_client.play(player)&#xA;                &#xA;        except Exception as e:&#xA;            print(e)&#xA;            &#xA;    if message.content.startswith("!link"):&#xA;            try:&#xA;                voice_client = await message.author.voice.channel.connect()&#xA;                voice_clients[voice_client.guild.id] = voice_client&#xA;            except Exception as e:&#xA;                print(e)&#xA;&#xA;            try:&#xA;                url = message.content.split()[1]&#xA;&#xA;                loop = asyncio.get_event_loop()&#xA;                data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=False))&#xA;&#xA;                song = data[&#x27;url&#x27;]&#xA;                player = discord.FFmpegOpusAudio(song, **ffmpeg_options)&#xA;&#xA;                voice_clients[message.guild.id].play(player)&#xA;            except Exception as e:&#xA;                print(e)&#xA;&#xA;    # Xử l&#xFD; lệnh !queue&#xA;    elif message.content.startswith("!queue"):&#xA;        queue = queues.get(guild_id, [])&#xA;        if queue:&#xA;            await message.channel.send("Danh s&#xE1;ch chờ:")&#xA;            for index, item in enumerate(queue, 1):&#xA;                await message.channel.send(f"{index}. {item.title}")&#xA;        else:&#xA;            await message.channel.send("Kh&#xF4;ng c&#xF3; b&#xE0;i h&#xE1;t n&#xE0;o trong danh s&#xE1;ch chờ.")&#xA;&#xA;    # Xử l&#xFD; lệnh !skip&#xA;    elif message.content.startswith("!skip"):&#xA;        try:&#xA;            if voice_client and voice_client.is_playing():&#xA;                voice_client.stop()&#xA;                await play_next_song(guild_id, queues, voice_client, skip=True)&#xA;                await remove_first_line_from_log()&#xA;        except Exception as e:&#xA;            print(e)&#xA;&#xA;    # Xử l&#xFD; c&#xE1;c lệnh như !pause, !resume, !stop&#xA;    elif message.content.startswith("!pause"):&#xA;        try:&#xA;            if voice_client and voice_client.is_playing():&#xA;                voice_client.pause()&#xA;        except Exception as e:&#xA;            print(e)&#xA;&#xA;    elif message.content.startswith("!resume"):&#xA;        try:&#xA;            if voice_client and not voice_client.is_playing():&#xA;                voice_client.resume()&#xA;        except Exception as e:&#xA;            print(e)&#xA;&#xA;    elif message.content.startswith("!stop"):&#xA;        try:&#xA;            if voice_client:&#xA;                voice_client.stop()&#xA;                await voice_client.disconnect()&#xA;                del voice_clients[guild_id]  # X&#xF3;a voice_client sau khi dừng&#xA;        except Exception as e:&#xA;            print(e)&#xA;&#xA;async def log_song_title(title):&#xA;    log_file_path = "C:\\Bot Music 2\\song_log.txt"&#xA;    try:&#xA;        # Kiểm tra xem tệp tin log đ&#xE3; tồn tại chưa&#xA;        if not os.path.exists(log_file_path):&#xA;            # Nếu chưa tồn tại, tạo tệp tin mới v&#xE0; ghi title v&#xE0;o tệp tin đ&#xF3;&#xA;            with open(log_file_path, &#x27;w&#x27;, encoding=&#x27;utf-8&#x27;) as file:&#xA;                file.write(title &#x2B; &#x27;\n&#x27;)&#xA;        else:&#xA;            # Nếu tệp tin log đ&#xE3; tồn tại, mở tệp tin v&#xE0; ch&#xE8;n title v&#xE0;o cuối tệp tin&#xA;            with open(log_file_path, &#x27;a&#x27;, encoding=&#x27;utf-8&#x27;) as file:&#xA;                file.write(title &#x2B; &#x27;\n&#x27;)&#xA;    except Exception as e:&#xA;        print(f"Error logging song title: {e}")&#xA;&#xA;async def remove_first_line_from_log():&#xA;    log_file_path = "C:\\Bot Music 2\\song_log.txt"&#xA;    try:&#xA;        with open(log_file_path, "r", encoding="utf-8") as f:&#xA;            lines = f.readlines()&#xA;        # X&#xF3;a d&#xF2;ng đầu ti&#xEA;n trong list lines&#xA;        lines = lines[1:]&#xA;        with open(log_file_path, "w", encoding="utf-8") as f:&#xA;            for line in lines:&#xA;                f.write(line)&#xA;    except Exception as e:&#xA;        print(f"Error removing first line from log: {e}")&#xA;        &#xA;async def clear_log_file():&#xA;    log_file_path = "C:\\Bot Music 2\\song_log.txt"&#xA;    try:&#xA;        with open(log_file_path, "w", encoding="utf-8") as f:&#xA;            f.truncate(0)&#xA;    except Exception as e:&#xA;        print(f"Error clearing log file: {e}")&#xA;&#xA;&#xA;async def play_next_song(guild_id, queues, voice_client, skip=False):&#xA;    queue = queues.get(guild_id, [])&#xA;    if queue:&#xA;        player = queue.pop(0)&#xA;        voice_client.play(player, after=lambda e: asyncio.run_coroutine_threadsafe(play_next_song(guild_id, queues, voice_client, skip=False), voice_client.loop))&#xA;        if skip:&#xA;            return&#xA;        else:&#xA;            await remove_first_line_from_log()  # X&#xF3;a d&#xF2;ng đầu ti&#xEA;n trong file log&#xA;    elif skip:&#xA;        await remove_first_line_from_log()  # X&#xF3;a d&#xF2;ng đầu ti&#xEA;n trong file log&#xA;        await voice_client.disconnect()&#xA;        del voice_client[guild_id]  # X&#xF3;a voice_client sau khi dừng&#xA;    else:&#xA;        await clear_log_file()  # X&#xF3;a d&#xF2;ng đầu ti&#xEA;n trong file log&#xA;        await voice_client.disconnect()&#xA;        del voice_client[guild_id]  # X&#xF3;a voice_client sau khi dừng&#xA;

    &#xA;

    I have tried asking ChatGPT, Gemini, or Bing, and they always lead me into a loop of errors that cannot be resolved. This error only occurs when the song naturally finishes playing due to its duration. If the song is playing and I use the command !skip, the next song in the queue will play and function normally. I noticed that it seems like if a song ends naturally, the song queue is also cleared immediately. I hope someone can help me with this

    &#xA;

  • Using Accord.Video.FFMPEG, I get "parameter is not valid exception". How can I solve it ?

    31 mai 2023, par Sheron Blumental

    I want to extract all the frames from an MP4 video file and display them on a PictureBox.

    &#xA;

    The original code comes from this Q&A : How can I time the presentation and extraction of frames from a video file ?

    &#xA;

    The exception happens after clicking the start button on the line :

    &#xA;

    var frame = videoReader.ReadVideoFrame();&#xA;

    &#xA;

    The message

    &#xA;

    System.ArgumentException&#xA;  HResult=0x80070057&#xA;  Message=Parameter is not valid.&#xA;  Source=System.Drawing&#xA;  StackTrace:&#xA;   at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)&#xA;   at Accord.Video.FFMPEG.VideoFileReader.DecodeVideoFrame(BitmapData bitmapData)&#xA;   at Accord.Video.FFMPEG.VideoFileReader.readVideoFrame(Int32 frameIndex, BitmapData output)&#xA;   at Accord.Video.FFMPEG.VideoFileReader.ReadVideoFrame()&#xA;   at Extract_Frames.Form1.<getvideoframesasync>d__15.MoveNext() in D:\Csharp Projects\Extract Frames\Form1.cs:line 114&#xA;   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&#xA;   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&#xA;   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()&#xA;   at Extract_Frames.Form1.d__17.MoveNext() in D:\Csharp Projects\Extract Frames\Form1.cs:line 151&#xA;</getvideoframesasync>

    &#xA;

    The full code

    &#xA;

    using Accord.IO;&#xA;using Accord.Video;&#xA;using Accord.Video.FFMPEG;&#xA;using System;&#xA;using System.Collections.Generic;&#xA;using System.ComponentModel;&#xA;using System.Data;&#xA;using System.Drawing;&#xA;using System.IO;&#xA;using System.Linq;&#xA;using System.Reflection;&#xA;using System.Reflection.Emit;&#xA;using System.Text;&#xA;using System.Threading;&#xA;using System.Threading.Tasks;&#xA;using System.Windows.Forms;&#xA;&#xA;namespace Extract_Frames&#xA;{&#xA;    public partial class Form1 : Form&#xA;    {&#xA;        Bitmap frame = null;&#xA;        Graphics frameGraphics = null;&#xA;        bool isVideoRunning = false;&#xA;        IProgress<bitmap> videoProgress = null;&#xA;        private CancellationTokenSource cts = null;&#xA;        private readonly object syncRoot = new object();&#xA;        private static long pause = 0;&#xA;        private int frameRate = 0;&#xA;        private List<bitmap> frames = new List<bitmap>();&#xA;        string fileName;&#xA;&#xA;        public Form1()&#xA;        {&#xA;            InitializeComponent();&#xA;&#xA;        }&#xA;&#xA;        private void Form1_Load(object sender, EventArgs e)&#xA;        {&#xA;&#xA;        }&#xA;&#xA;        private void StopPlayback(bool cancel)&#xA;        {&#xA;            lock (syncRoot)&#xA;            {&#xA;                if (cancel) cts?.Cancel();&#xA;                cts?.Dispose();&#xA;                cts = null;&#xA;            }&#xA;        }&#xA;&#xA;        int counter =1;&#xA;        private void Updater(Bitmap videoFrame)&#xA;        {&#xA;            frames.Add(videoFrame);&#xA;&#xA;            label1.Text = "Current Frame Number : " &#x2B; counter;&#xA;            trackBar1.Value = counter;&#xA;            counter&#x2B;&#x2B;;&#xA;&#xA;            //Size size = new Size(videoFrame.Width, videoFrame.Height);&#xA;            //pictureBox1.ClientSize = size;&#xA;            using (videoFrame) frameGraphics.DrawImage(videoFrame, Point.Empty);&#xA;&#xA;            pictureBox1.Invalidate();&#xA;        }&#xA;&#xA;        private async Task GetVideoFramesAsync(IProgress<bitmap> updater, string fileName, int intervalMs, CancellationToken token = default)&#xA;        {&#xA;            using (var videoReader = new VideoFileReader())&#xA;            {&#xA;                if (token.IsCancellationRequested) return;&#xA;                videoReader.Open(fileName);&#xA;&#xA;                videoReader.ReadVideoFrame(1);&#xA;                trackBar1.Value = 1;&#xA;&#xA;                label1.Text = "Current Frame Number : " &#x2B; counter.ToString();&#xA;&#xA;                while (true)&#xA;                {&#xA;                    if (Interlocked.Read(ref pause) == 0)&#xA;                    {&#xA;                        var frame = videoReader.ReadVideoFrame();&#xA;&#xA;                        if (token.IsCancellationRequested || frame is null) break;&#xA;                        updater.Report(frame);&#xA;                    }&#xA;                    await Task.Delay(frameRate).ConfigureAwait(false);&#xA;                }&#xA;            }&#xA;        }&#xA;&#xA;        private void trackBar2_Scroll(object sender, EventArgs e)&#xA;        {&#xA;            frameRate = trackBar2.Value / 25;&#xA;        }&#xA;&#xA;        private async void buttonStart_Click(object sender, EventArgs e)&#xA;        {&#xA;            string fileName = textBox1.Text;&#xA;&#xA;            if (isVideoRunning) return;&#xA;            isVideoRunning = true;&#xA;&#xA;            using (var videoReader = new VideoFileReader())&#xA;            {&#xA;                videoReader.Open(fileName);&#xA;                frame = new Bitmap(videoReader.Width &#x2B; 2, videoReader.Height &#x2B; 2);&#xA;                trackBar1.Maximum = (int)videoReader.FrameCount;&#xA;            }&#xA;&#xA;            videoProgress = new Progress<bitmap>((bitmap) => Updater(bitmap));&#xA;            cts = new CancellationTokenSource();&#xA;            pictureBox1.Image = frame;&#xA;            try&#xA;            {&#xA;                frameGraphics = Graphics.FromImage(frame);&#xA;                // Set the fame rate to 25 frames per second&#xA;                //int frameRate = 1000 / 25;&#xA;                await GetVideoFramesAsync(videoProgress, fileName, frameRate, cts.Token);&#xA;            }&#xA;            finally&#xA;            {&#xA;                frameGraphics?.Dispose();&#xA;                StopPlayback(false);&#xA;                isVideoRunning = false;&#xA;            }&#xA;        }&#xA;&#xA;        private void buttonPause_Click(object sender, EventArgs e)&#xA;        {&#xA;            if (pause == 0)&#xA;            {&#xA;                buttonPause.Text = "Resume";&#xA;                Interlocked.Increment(ref pause);&#xA;            }&#xA;            else&#xA;            {&#xA;                Interlocked.Decrement(ref pause);&#xA;                buttonPause.Text = "Pause";&#xA;            }&#xA;        }&#xA;&#xA;        private void buttonStop_Click(object sender, EventArgs e)&#xA;        {&#xA;            StopPlayback(true);&#xA;        }&#xA;&#xA;        protected override void OnFormClosing(FormClosingEventArgs e)&#xA;        {&#xA;            if (isVideoRunning) StopPlayback(true);&#xA;            pictureBox1.Image?.Dispose();&#xA;            base.OnFormClosing(e);&#xA;        }&#xA;&#xA;        private void pictureBox1_Paint(object sender, PaintEventArgs e)&#xA;        {&#xA;            ControlPaint.DrawBorder(e.Graphics, pictureBox1.ClientRectangle, Color.Red, ButtonBorderStyle.Solid);&#xA;        }&#xA;&#xA;        private void trackBar1_Scroll(object sender, EventArgs e)&#xA;        {&#xA;            pictureBox1.Image = frames[trackBar1.Value];&#xA;        }&#xA;&#xA;        private void button1_Click(object sender, EventArgs e)&#xA;        {&#xA;            using (OpenFileDialog openFileDialog = new OpenFileDialog())&#xA;            {&#xA;                openFileDialog.InitialDirectory = "c:\\";&#xA;                openFileDialog.Filter = "video files (*.mp4)|*.mp4|All files (*.*)|*.*";&#xA;                openFileDialog.FilterIndex = 2;&#xA;                openFileDialog.RestoreDirectory = true;&#xA;&#xA;                if (openFileDialog.ShowDialog() == DialogResult.OK)&#xA;                {&#xA;                    // Get the path of specified file&#xA;                    textBox1.Text = openFileDialog.FileName;&#xA;                }&#xA;            }&#xA;        }&#xA;    }&#xA;}&#xA;</bitmap></bitmap></bitmap></bitmap></bitmap>

    &#xA;