
Recherche avancée
Autres articles (68)
-
Gestion générale des documents
13 mai 2011, parMédiaSPIP ne modifie jamais le document original mis en ligne.
Pour chaque document mis en ligne il effectue deux opérations successives : la création d’une version supplémentaire qui peut être facilement consultée en ligne tout en laissant l’original téléchargeable dans le cas où le document original ne peut être lu dans un navigateur Internet ; la récupération des métadonnées du document original pour illustrer textuellement le fichier ;
Les tableaux ci-dessous expliquent ce que peut faire MédiaSPIP (...) -
Des sites réalisés avec MediaSPIP
2 mai 2011, parCette page présente quelques-uns des sites fonctionnant sous MediaSPIP.
Vous pouvez bien entendu ajouter le votre grâce au formulaire en bas de page. -
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 (5523)
-
Seeking with ffmpeg options fails or causes delayed playback in Discord bot
29 août 2022, par J PetersenMy Discord bot allows users to play a song starting from a timestamp.


The problem is that playback is delayed and audio plays faster and is jumbled if start times >= 30s are set.


Results from testing different start times. Same URL, 30 second duration :







 Entered Start Time (s) 

Playback Delay (s) 

Song Playback Time (s) 







 0 

3 

30 




 30 

10 

22 




 60 

17 

17 




 120 

31 

2 




 150 

120 

<1 









I am setting the start time using ffmpeg_options as suggested in this question.


Does anyone understand why the audio playback is being delayed/jumbled ? How can I improve playback delay and allow users to start in the middle of a multi-chapter YouTube video ?


Code :


import discord
import youtube_dl
import asyncio


# Suppress noise about console usage from errors
youtube_dl.utils.bug_reports_message = lambda: ""


ytdl_format_options = {
 "format": "bestaudio/best",
 "outtmpl": "%(extractor)s-%(id)s-%(title)s.%(ext)s",
 "restrictfilenames": True,
 "noplaylist": False,
 "yesplaylist": True,
 "nocheckcertificate": True,
 "ignoreerrors": False,
 "logtostderr": False,
 "quiet": True,
 "no_warnings": True,
 "default_search": "auto",
 "source_address": "0.0.0.0", # Bind to ipv4 since ipv6 addresses cause issues at certain times
}

ytdl = youtube_dl.YoutubeDL(ytdl_format_options)


class YTDLSource(discord.PCMVolumeTransformer):
 def __init__(self, source: discord.AudioSource, *, data: dict, volume: float = 0.5):
 super().__init__(source, volume)

 self.data = data

 self.title = data.get("title")
 self.url = data.get("url")

 @classmethod
 async def from_url(cls, url, *, loop=None, stream=False, timestamp = 0):
 ffmpeg_options = {
 "options": f"-vn -ss {timestamp}"}

 loop = loop or asyncio.get_event_loop()

 data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream))
 if "entries" in data:
 # Takes the first item from a playlist
 data = data["entries"][0]

 filename = data["url"] if stream else ytdl.prepare_filename(data)
 return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_options), data=data)


intents = discord.Intents.default()

bot = discord.Bot(intents=intents)

@bot.slash_command()
async def play(ctx, audio: discord.Option(), seconds: discord.Option(), timestamp: discord.Option()):
 channel = ctx.author.voice.channel
 voice = await channel.connect()
 player = await YTDLSource.from_url(audio, loop=bot.loop, stream=True, timestamp=int(timestamp))
 voice.play(player)
 await asyncio.sleep(int(seconds))
 await voice.disconnect()

token = token value
bot.run(token)



-
ffmpeg : programmatically use libavcodec and encode and decode raw bitmap, all in just few milliseconds and small compressed size on Raspberry Pi 4
15 mars 2023, par Jerry SwitalskiWe need to compress the size of the 1024x2048 image we produce, to size of about jpeg (200-500kb) from raw 32bits RGBA (8Mb) on Raspberry Pi 4. All in c/c++ program.


The compression needs to be just in few milliseconds, otherwise it is pointless to us.


We decided to try supported encoding using ffmpeg dev library and c/c++ code.


The problem we are facing is that when we edited example of the encoding, provided by ffmpeg developers, the times we are dealing are unacceptable.


Here you can see the edited code where the frames are created :


for (i = 0; i < 25; i++)
{
#ifdef MEASURE_TIME
 auto start_time = std::chrono::high_resolution_clock::now();
 std::cout << "START Encoding frame...\n";
#endif
 fflush(stdout);

 ret = av_frame_make_writable(frame);
 if (ret < 0)
 exit(1);

 //I try here, to convert our 32 bits RGBA image to YUV pixel format:

 for (y = 0; y < c->height; y++)
 {
 for (x = 0; x < c->width; x++)
 {
 int imageIndexY = y * frame->linesize[0] + x;

 uint32_t rgbPixel = ((uint32_t*)OutputDataImage)[imageIndexY];

 double Y, U, V;
 uint8_t R = rgbPixel << 24;
 uint8_t G = rgbPixel << 16;
 uint8_t B = rgbPixel << 8;

 YUVfromRGB(Y, U, V, (double)R, (double)G, (double)B);
 frame->data[0][imageIndexY] = (uint8_t)Y;

 if (y % 2 == 0 && x % 2 == 0)
 {
 int imageIndexU = (y / 2) * frame->linesize[1] + (x / 2);
 int imageIndexV = (y / 2) * frame->linesize[2] + (x / 2);

 frame->data[1][imageIndexU] = (uint8_t)U;
 frame->data[2][imageIndexV] = (uint8_t)Y;
 }
 }
 }

 frame->pts = i;

 /* encode the image */
 encode(c, frame, pkt, f);

#ifdef MEASURE_TIME
 auto end_time = std::chrono::high_resolution_clock::now();
 auto time = end_time - start_time;
 std::cout << "FINISHED Encoding frame in: " << time / std::chrono::milliseconds(1) << "ms.\n";

#endif
 }



Here are some important parts of the previous parts of that function :


codec_name = "mpeg4";

codec = avcodec_find_encoder_by_name(codec_name);

c = avcodec_alloc_context3(codec);
 
c->bit_rate = 1000000; 
c->width = IMAGE_WIDTH;
c->height = IMAGE_HEIGHT;
c->gop_size = 1;
c->max_b_frames = 1;
c->pix_fmt = AV_PIX_FMT_YUV420P; 



IMAGE_WIDTH and IMAGE_HEIGHT are 1024 and 2048 corresponding.


The result I have ran on Raspberry Pi 4 look like this :


START Encoding frame...
Send frame 0
FINISHED Encoding frame in: 40ms.
START Encoding frame...
Send frame 1
Write packet 0 (size=11329)
FINISHED Encoding frame in: 60ms.
START Encoding frame...
Send frame 2
Write packet 1 (size=11329)
FINISHED Encoding frame in: 58ms.



Since I am completely green in encoding and using codecs, my question will be how to do it the best way and correct way, meaning the way which would reduce timing to few ms, and I am not sure the codec was chosen the best for the job, or the pixel format.


The rest of the meaningful code you can see here (the encode() function you can find in the ffmpeg developer example I gave link to above) :


void RGBfromYUV(double& R, double& G, double& B, double Y, double U, double V)
{
 Y -= 16;
 U -= 128;
 V -= 128;
 R = 1.164 * Y + 1.596 * V;
 G = 1.164 * Y - 0.392 * U - 0.813 * V;
 B = 1.164 * Y + 2.017 * U;
}



-
avcodec/svq1enc : Add SVQ1EncDSPContext, make codec context private
10 octobre 2022, par Andreas Rheinhardtavcodec/svq1enc : Add SVQ1EncDSPContext, make codec context private
Currently, SVQ1EncContext is defined in a header that is also
included by the arch-specific code that initializes the one
and only dsp function that this encoder uses directly.But the arch-specific functions to set this dsp function
do not need anything from SVQ1EncContext. This commit therefore
adds a small SVQ1EncDSPContext whose only member is said
function pointer and renames svq1enc.h to svq1encdsp.h
to avoid exposing unnecessary internals to these init
functions (and the whole mpegvideo with it).Signed-off-by : Andreas Rheinhardt <andreas.rheinhardt@outlook.com>