
Recherche avancée
Autres articles (43)
-
Keeping control of your media in your hands
13 avril 2011, parThe vocabulary used on this site and around MediaSPIP in general, aims to avoid reference to Web 2.0 and the companies that profit from media-sharing.
While using MediaSPIP, you are invited to avoid using words like "Brand", "Cloud" and "Market".
MediaSPIP is designed to facilitate the sharing of creative media online, while allowing authors to retain complete control of their work.
MediaSPIP aims to be accessible to as many people as possible and development is based on expanding the (...) -
Support audio et vidéo HTML5
10 avril 2011MediaSPIP utilise les balises HTML5 video et audio pour la lecture de documents multimedia en profitant des dernières innovations du W3C supportées par les navigateurs modernes.
Pour les navigateurs plus anciens, le lecteur flash Flowplayer est utilisé.
Le lecteur HTML5 utilisé a été spécifiquement créé pour MediaSPIP : il est complètement modifiable graphiquement pour correspondre à un thème choisi.
Ces technologies permettent de distribuer vidéo et son à la fois sur des ordinateurs conventionnels (...) -
HTML5 audio and video support
13 avril 2011, parMediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
For older browsers the Flowplayer flash fallback is used.
MediaSPIP allows for media playback on major mobile platforms with the above (...)
Sur d’autres sites (7131)
-
Segmentation fault caused by FFMPEG / SFML on Macos
12 avril 2024, par Med ali Damergi ReTr0I'm trying to code a basic video player function to use it in a game it's supposed to get a sfml window and a video link as inputs and run the video :


extern "C" {
#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>
#include <libswscale></libswscale>swscale.h>
#include <libavutil></libavutil>imgutils.h>
}

#include <sfml></sfml>Graphics.hpp>
#include <iostream>

const AVCodec* pCodec = nullptr;


void lecteurVideo(const std::string& videoPath, sf::RenderWindow& window) {
 // Open the video file
 AVFormatContext* pFormatCtx = avformat_alloc_context();
 if (avformat_open_input(&pFormatCtx, videoPath.c_str(), nullptr, nullptr) != 0) {
 std::cerr << "Failed to open video file" << std::endl;
 return;
 }

 // Retrieve stream information
 if (avformat_find_stream_info(pFormatCtx, nullptr) < 0) {
 std::cerr << "Failed to retrieve stream information" << std::endl;
 avformat_close_input(&pFormatCtx);
 return;
 }

 // Find the first video stream
 int videoStreamIndex = -1;
 for (unsigned int i = 0; i < pFormatCtx->nb_streams; i++) {
 if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
 videoStreamIndex = i;
 break;
 }
 }
 if (videoStreamIndex == -1) {
 std::cerr << "Failed to find video stream" << std::endl;
 avformat_close_input(&pFormatCtx);
 return;
 }

 // Get the codec parameters for the video stream
 AVCodecParameters* pCodecParams = pFormatCtx->streams[videoStreamIndex]->codecpar;

 // Find the decoder for the video stream
 const AVCodec* pCodec = avcodec_find_decoder(pCodecParams->codec_id);
 if (pCodec == nullptr) {
 std::cerr << "Failed to find video decoder" << std::endl;
 avformat_close_input(&pFormatCtx);
 return;
 }

 // Allocate a codec context for the decoder
 AVCodecContext* pCodecCtx = avcodec_alloc_context3(pCodec);
 if (pCodecCtx == nullptr) {
 std::cerr << "Failed to allocate codec context" << std::endl;
 avformat_close_input(&pFormatCtx);
 return;
 }

 // Initialize the codec context with the codec parameters
 if (avcodec_parameters_to_context(pCodecCtx, pCodecParams) < 0) {
 std::cerr << "Failed to initialize codec context" << std::endl;
 avcodec_free_context(&pCodecCtx);
 avformat_close_input(&pFormatCtx);
 return;
 }

 // Open the codec
 if (avcodec_open2(pCodecCtx, pCodec, nullptr) < 0) {
 std::cerr << "Failed to open codec" << std::endl;
 avcodec_free_context(&pCodecCtx);
 avformat_close_input(&pFormatCtx);
 return;
 }

 // Create a frame to hold the decoded video data
 AVFrame* pFrame = av_frame_alloc();
 if (pFrame == nullptr) {
 std::cerr << "Failed to allocate frame" << std::endl;
 avcodec_close(pCodecCtx);
 avformat_close_input(&pFormatCtx);
 return;
 }

 // Create a packet for reading compressed video data
 AVPacket* pPacket = av_packet_alloc();
 if (pPacket == nullptr) {
 std::cerr << "Failed to allocate packet" << std::endl;
 av_frame_free(&pFrame);
 avcodec_close(pCodecCtx);
 avformat_close_input(&pFormatCtx);
 return;
 }

 // Create a software scaler context for converting the video frame format
 SwsContext* pSwsCtx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt,
 pCodecCtx->width, pCodecCtx->height, AV_PIX_FMT_RGB24,
 SWS_BILINEAR, nullptr, nullptr, nullptr);
 if (pSwsCtx == nullptr) {
 std::cerr << "Failed to create software scaler context" << std::endl;
 av_packet_free(&pPacket);
 av_frame_free(&pFrame);
 avcodec_close(pCodecCtx);
 avformat_close_input(&pFormatCtx);
 return;
 }

 // Create an SFML texture and sprite for displaying the video frames
 sf::Texture texture;
 sf::Sprite sprite;

 // Read frames from the video file and display them in the SFML window
 while (av_read_frame(pFormatCtx, pPacket) >= 0) {
 if (pPacket->stream_index == videoStreamIndex) {
 // Decode the video packet into a frame
 if (avcodec_send_packet(pCodecCtx, pPacket) < 0) {
 std::cerr << "Failed to send packet to decoder" << std::endl;
 break;
 }
 if (avcodec_receive_frame(pCodecCtx, pFrame) < 0) {
 std::cerr << "Failed to receive frame from decoder" << std::endl;
 break;
 }

 // Convert the frame format to RGB24
 uint8_t* rgbBuffer = new uint8_t[pCodecCtx->width * pCodecCtx->height * 3];
 uint8_t* rgbPlanes[1] = { rgbBuffer };
 int rgbStrides[1] = { pCodecCtx->width * 3 };
 sws_scale(pSwsCtx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height,
 rgbPlanes, rgbStrides);

 // Update the SFML texture with the RGB24 data
 texture.create(pCodecCtx->width, pCodecCtx->height);
 texture.update(rgbBuffer);

 // Display the texture in the SFML window
 sprite.setTexture(texture);
 window.clear();
 window.draw(sprite);
 window.display();

 delete[] rgbBuffer;
 }

 av_packet_unref(pPacket);
 }

 // Clean up resources
 av_packet_free(&pPacket);
 av_frame_free(&pFrame);
 avcodec_close(pCodecCtx);
 avformat_close_input(&pFormatCtx);
 sws_freeContext(pSwsCtx);
}

int main() {
 sf::RenderWindow window(sf::VideoMode(800, 600), "Lecteur Video SFML");
 lecteurVideo("/Users/mac/cours/spaceRevolution/Videos/58e62585-c143-483a-9149-b401ebc01d02.mp4", window);
 return 0;
}
</iostream>


It works on my other computer running on ubuntu but not on my main laptop on macOS : It dosent open any window and instantly cause a segmentation fault.


I've tried tu run valgrind on it but valgrind dosent run well on macOS.


Could anybody help me with this ?


-
ffmpeg doesn't work, when starting up it doesn't play music, it gives errors
14 août 2024, par Оля Михееваimport discord
from discord import FFmpegPCMAudio
import os
import random
from gtts import gTTS
import asyncio

TOKEN="***"
VOICE_CHANNEL_ID=11122224444

class Voice_Bot(discord.Client):
 def __init__(self):
 intents = discord.Intents.default()
 intents.message_content = True
 intents.voice_states=True
 super().__init__(intents=intents)
 print(os.getcwd())
 self.sounds_hello = os.listdir(os.path.join('sounds','hello'))
 self.sounds_bye = os.listdir('sounds\\bye')
 self.sounds = os.listdir('sounds\\nature')

 async def on_ready(self): 
 self.voice_channel = self.get_channel(VOICE_CHANNEL_ID) 
 if self.voice_channel == None:
 print('Не удалось подключиться к голосовому каналу.')
 return
 self.voice_client = await self.voice_channel.connect()
 print('Бот подключен к голосовому каналу')
 await self.text_to_speech("Lets play Guess the Tune")
 
 async def on_message(self,message):
 if message.author==self.user:
 return
 if message.content.startswith("game"):
 await self.text_to_speech("let's start the game guess the melody")
 music=os.listdir("sounds\\music")
 self.melody=random.choice(music)
 await self.play_sound(f"sounds\\music\\{self.melody}")
 elif message.content==self.melody[0:len(self.melody)-4]:
 if (self.voice_client.is_playing()):
 self.voice_client.stop()
 await self.text_to_speech(f"Congratulations, {message.author.name} answered correctly! To continue, type game")
 else:
 if (self.voice_client.is_playing()):
 self.voice_client.stop()
 await self.text_to_speech(f"Unfortunately, {message.author.name} did not guess. To continue, write game")


 async def on_voice_state_update(self,member,before,after):
 if member.id ==self.user.id:
 print('Someone entered or left the voice channel.')
 else:
 try:
 if before.channel == None:
 print(f'{member.name} entered the voice channel {after.channel}.')
 await self.play_sound(f'sounds\\hello\\{random.choice(self.sounds_hello)}')
 elif after.channel == None:
 print(f'{member.name} left the voice channel {before.channel}.')
 await self.play_sound(f'sounds\\bye\\{random.choice(self.sounds_bye)}')
 except Exception as e:
 print(f"Error in on_voise_state_update: {e}")

 async def text_to_speech(self,text):
 try:
 tts = gTTS(text=text, lang ="en")
 tts.save("text.mp3")
 except Exception as e:
 print(f"Error e: {e}")
 await self.voice_channel.send(text)
 await self.play_sound("text.mp3")

 def play_sound(self,path):
 print(path)
 source=discord.FFmpegPCMAudio(source=path, executable="ffmpeg\\bin\\ffmpeg.exe")
 if (self.voice_client.is_playing()):
 self.voice_client.stop()
 self.voice_client.play(source) 

client = Voice_Bot()
client.run(TOKEN)



[enter image description here](https://i.sstatic.net/ys8Xza0w.jpg)


-
avcodec/sanm : better frame size detection for old codecs
11 mars, par Manuel Laussavcodec/sanm : better frame size detection for old codecs
The size of the video frame (FOBJ) of the old codecs (ANIMv0/1/2) can
very reliably be determined :ANIMv0/1 (=Rebel Assault 1) uses a 384x242 internal buffer for
everything. The codec parameters only describe the size and offset
of the specific FOBJ on that buffer.ANIMv2 titles usually use one of the fullscreen codecs (37/47/48)
as first FOBJ, and their dimensions can generally be trusted.RA2 uses 424x260 as internal buffer, use that if encountered :
08PLAY.SAN does not use codec37 so we need to guess using the
codec coordinates.ignore sizes smaller than 2x2 or larger than 800x600.
some game videos have an initial fobj with either 1x1 or -1x-1
pixels in size, ignore them with a warning (Full Throttle
and the Rebel Assault 2 xxRETRY.SAN videos).Once a known/valid dimension set has been discovered, use it and
don't change it for subsequent FOBJs, rather clamp the large frame
to the determined dimensions.Tested with RA1, RA2, Full Throttle, Dig, Outlaws, SotE and MotS
videos.Signed-off-by : Manuel Lauss <manuel.lauss@gmail.com>