Quantcast
Channel: MediaSPIP
Viewing all 117718 articles
Browse latest View live

Evolution #4412: Ajout d'un site : récuperer son icone en logo

$
0
0

De plus, si le site est bien fait, il dispose d'un flux RSS, et ce dernier contient un lien vers le logo du site, et SPIP récupère bien ce logo.

Donc, il faut militer pour que les sites aient des flux RSS bien configurés ;-)


User custom private data in AVPacket

$
0
0

Is there a way to attach some user private data to AVPacket before decoding to be able to match input AVPacket and decoded output AVFrame? Some sort of AVFrame::opaque.

Specifically, decoding process of h264 codestream can do reorder in a case B-frames are present and I would like to identify which AVPacket was decoded to which AVFrame.

How do I upscale an iOS App Preview video to 1080 x 1920?

$
0
0

I just captured a video of my new app running on an iPhone 6 using QuickTime Player and a Lightning cable. Afterwards I created an App Preview project in iMovie, exported it and could successfully upload it to iTunes Connect.

Apple requires developers to upload App Previews in different resolutions dependent on screen size, namely:

  • iPhone 5(S): 1080 x 1920 or 640 x 1136
  • iPhone 6: 750 x 1334 (what I have)
  • iPhone 6+: 1080 x 1920

Obviously, 1080 x 1920 is killing two birds with one stone. I know that upscaling isn't the perfect solution, but it's meeting my needs. Since I don't own a 6+, another recording session won't do the trick.

Unfortunately, iTunes Connect is extremely picky about what to accept. Here's what I tried, to no avail:

  • Handbrake, iMovie, QuickTime do not support upscaling
  • MPEG Streamclip
  • ffmpeg -i input.mp4 -acodec copy -vf scale=1080:1920 output.mp4

Strangely enough, iTunes Connect keeps complaining about the wrong resolution when I try to upload the output.mp4 of ffmpeg.

Why image decoded by ffmpeg has a boder?

$
0
0

After decoding some videos from iphone, I find the image has a strange border on the right.

It is not black but some random pix (width:4). why i get the border? how to cut this border or to turn it to black?

Most of videos dont have this problem.

enter image description here

here is the sample code: the code will load a video from memory, and decode it

int VideoParseFFmpeg::read_packet(void *opaque, uint8_t *buf, int buf_size) { struct buffer_data *bd = (struct buffer_data *) opaque; buf_size = FFMIN(buf_size, bd->size_); if (!buf_size) return AVERROR_EOF; memcpy(buf, bd->ptr_, buf_size); bd->ptr_ += buf_size; bd->size_ -= buf_size; return buf_size;
} int VideoParseFFmpeg::LoadContent(const std::string &video_content) { int ret = 0; ... video_size_ = video_content.size(); avio_ctx_buffer_size_ = video_size_ + AV_INPUT_BUFFER_PADDING_SIZE; avio_ctx_buffer_ = static_cast(av_malloc(avio_ctx_buffer_size_)); bd_.ptr_ = (uint8_t *)(video_content.c_str()); bd_.size_ = video_content.size(); av_register_all(); input_ctx_ = avformat_alloc_context(); avio_ctx_ = avio_alloc_context(avio_ctx_buffer_, avio_ctx_buffer_size_, 0, &bd_, &read_packet, NULL, NULL); if ((ret = av_probe_input_buffer(avio_ctx_, &in_fmt_, "", NULL, 0, 0)) < 0) { LOGGER_WARN(Log::GetLog(), "fail to prob input, err [{}]", AVERROR(ret)); return -1; } input_ctx_->pb = avio_ctx_; /* open the input file */ if ((ret = avformat_open_input(&input_ctx_, "", in_fmt_, NULL)) != 0) { LOGGER_WARN(Log::GetLog(), "fail to open input, err [{}]", AVERROR(ret)); return -1; } if ((ret = avformat_find_stream_info(input_ctx_, NULL)) < 0) { LOGGER_WARN(Log::GetLog(), "fail to find input stream information, err[{}]", AVERROR(ret)); return -1; } /* find the video stream information */ if ((ret = av_find_best_stream(input_ctx_, AVMEDIA_TYPE_VIDEO, -1, -1, &decoder_, 0)) < 0) { LOGGER_WARN(Log::GetLog(), "fail to find a video stream from input, err[{}]", ret); return -1; } video_stream_idx_ = ret; if (!(decoder_ctx_ = avcodec_alloc_context3(decoder_))) { LOGGER_WARN(Log::GetLog(), "fail to alloc avcodec context"); return -1; } video_stream_ = input_ctx_->streams[video_stream_idx_]; if ((ret = avcodec_parameters_to_context(decoder_ctx_, video_stream_->codecpar)) < 0) { LOGGER_WARN(Log::GetLog(), "fail to convert parameters to context, err [{}]", ret); return -1; } if ((ret = avcodec_open2(decoder_ctx_, decoder_, NULL)) < 0) { LOGGER_WARN(Log::GetLog(), "fail to open decodec, err[{}]", ret); return -1; } return 0;
} void VideoParseFFmpeg::GetFrames(std::vector&frames) { while (1) { ... decode_write(decoder_ctx_, &packet_, &buffer, frames); ... }
//flush
...
} cv::Mat VideoParseFFmpeg::avFrame2Mat(AVFrame *pAvFrame, AVCodecContext *pCodecCtx, AVPixelFormat src_fmt) { AVFrame *pFrameBGR = av_frame_alloc(); // 存储解码后转换的BGR数据 int w = pAvFrame->width; int h = pAvFrame->height; auto size = av_image_get_buffer_size(AV_PIX_FMT_BGR24, w, h, 1); cv::Mat out(h, w, CV_8UC3); int ret = av_image_fill_arrays(pFrameBGR->data, pFrameBGR->linesize, out.data, AV_PIX_FMT_BGR24, w, h, 1); img_convert_ctx_ = sws_getCachedContext(img_convert_ctx_, w, h, ConvertDeprecatedFormat(src_fmt), w, h, AV_PIX_FMT_BGR24, SWS_BICUBIC, NULL, NULL, NULL); sws_scale(img_convert_ctx_, (const uint8_t *const *) pAvFrame->data, pAvFrame->linesize, 0, pCodecCtx->height, pFrameBGR->data, pFrameBGR->linesize); av_free(pFrameBGR); return out;
} int VideoParseFFmpeg::decode_write(AVCodecContext *avctx, AVPacket *packet, uint8_t **buffer, std::vector&p_mat_out) { AVFrame *frame = NULL, *sw_frame = NULL; AVFrame *tmp_frame = NULL; int ret = 0; ret = avcodec_send_packet(avctx, packet); ... while (1) { auto clear = [&frame, &sw_frame, this] { if (frame != NULL) av_frame_free(&frame); if (sw_frame != NULL) av_frame_free(&sw_frame); av_packet_unref(&packet_); }; ... ret = avcodec_receive_frame(avctx, frame); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { clear(); return 0; } else if (ret < 0) { LOGGER_WARN(Log::GetLog(), "error while decoding, err[{}]", AVERROR(ret)); clear(); return ret; } tmp_frame = frame; p_mat_out.push_back(avFrame2Mat(tmp_frame, avctx, (AVPixelFormat) tmp_frame->format)); clear(); }
}

After replacing lib tcmalloc with a newer version, the border turns to be a black line (used to be a random line), like this.

enter image description here

-- enter image description here, enter image description here

How to fix out of bounds error in to_soundarray in moviepy?

$
0
0

The code works with the default youtube_dl name but not outtmpl name that I put in ydl_opts

the solution given here - https://www.reddit.com/r/moviepy/comments/dwc27w/to_sound_array_issue/ doesnt seem to work

here is the code -

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import moviepy.editor as mpy
!pip install youtube_dl
import youtube_dl url = 'https://www.youtube.com/watch?v=5pIpVK3Gecg' start_ts = 170
end_ts = 180 ydl_opts = { 'format': 'bestaudio/best', 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'wav', 'preferredquality': '192', }], 'outtmpl': 'original.wav', } with youtube_dl.YoutubeDL(ydl_opts) as ydl: ydl.download([url]) from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip ffmpeg_extract_subclip('original.wav' ,170, 180, targetname='clipped.wav') talk = mpy.AudioFileClip('clipped.wav') plt.axis('off') sample_rate = talk.fps NFFT = sample_rate /25
audio_data = talk.to_soundarray() fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(2.44, 2.44), dpi=100.) ax.axis('off')
spectrum, freqs, time, im = ax.specgram(audio_data.mean(axis=1), NFFT=NFFT, pad_to=4096, Fs=sample_rate, noverlap=512, mode='magnitude', )

and here is the error -

 [youtube] 5pIpVK3Gecg: Downloading webpage
[youtube] 5pIpVK3Gecg: Downloading video info webpage
[download] original.wav has already been downloaded
[download] 100% of 48.12MiB
[ffmpeg] Correcting container in "original.wav"
[ffmpeg] Post-process file original.wav exists, skipping [MoviePy] Running:
>>> /root/.imageio/ffmpeg/ffmpeg-linux64-v3.3.1 -y -i original.wav -ss 170.00 -t 10.00 -vcodec copy -acodec copy clipped.wav
... command successful. --------------------------------------------------------------------------- IndexError Traceback (most recent call last) /usr/local/lib/python3.6/dist-packages/moviepy/audio/io/readers.py in get_frame(self, tt) 189 indices = indices - (self.buffersize // 2 - len(self.buffer) + 1)
--> 190 result[in_time] = self.buffer[indices] 191 return result IndexError: index -59041 is out of bounds for axis 0 with size 40960 During handling of the above exception, another exception occurred: IndexError Traceback (most recent call last) 10 frames  in () 30 31 NFFT = sample_rate /25
---> 32 audio_data = talk.to_soundarray() 33 34 fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(2.44, 2.44), dpi=100.)  in to_soundarray(self, tt, fps, quantize, nbytes, buffersize) /usr/local/lib/python3.6/dist-packages/moviepy/decorators.py in requires_duration(f, clip, *a, **k) 52 raise ValueError("Attribute 'duration' not set") 53 else:
---> 54 return f(clip, *a, **k) 55 56 /usr/local/lib/python3.6/dist-packages/moviepy/audio/AudioClip.py in to_soundarray(self, tt, fps, quantize, nbytes, buffersize) 115 if self.duration > max_duration: 116 return stacker(self.iter_chunks(fps=fps, quantize=quantize,
--> 117 nbytes=2, chunksize=buffersize)) 118 else: 119 tt = np.arange(0, self.duration, 1.0/fps) <__array_function__ internals> in vstack(*args, **kwargs) /usr/local/lib/python3.6/dist-packages/numpy/core/shape_base.py in vstack(tup) 277 # raise warning if necessary 278 _arrays_for_stack_dispatcher(tup, stacklevel=2)
--> 279 arrs = atleast_2d(*tup) 280 if not isinstance(arrs, list): 281 arrs = [arrs] /usr/local/lib/python3.6/dist-packages/moviepy/audio/AudioClip.py in generator() 82 tt = (1.0/fps)*np.arange(pospos[i], pospos[i+1]) 83 yield self.to_soundarray(tt, nbytes=nbytes, quantize=quantize,
---> 84 fps=fps, buffersize=chunksize) 85 86 if progress_bar:  in to_soundarray(self, tt, fps, quantize, nbytes, buffersize) /usr/local/lib/python3.6/dist-packages/moviepy/decorators.py in requires_duration(f, clip, *a, **k) 52 raise ValueError("Attribute 'duration' not set") 53 else:
---> 54 return f(clip, *a, **k) 55 56 /usr/local/lib/python3.6/dist-packages/moviepy/audio/AudioClip.py in to_soundarray(self, tt, fps, quantize, nbytes, buffersize) 128 #print tt.max() - tt.min(), tt.min(), tt.max() 129 --> 130 snd_array = self.get_frame(tt) 131 132 if quantize:  in get_frame(self, t) /usr/local/lib/python3.6/dist-packages/moviepy/decorators.py in wrapper(f, *a, **kw) 87 new_kw = {k: fun(v) if k in varnames else v 88 for (k,v) in kw.items()}
---> 89 return f(*new_a, **new_kw) 90 return decorator.decorator(wrapper) 91 /usr/local/lib/python3.6/dist-packages/moviepy/Clip.py in get_frame(self, t) 92 return frame 93 else:
---> 94 return self.make_frame(t) 95 96 def fl(self, fun, apply_to=None, keep_duration=True): /usr/local/lib/python3.6/dist-packages/moviepy/audio/io/AudioFileClip.py in (t) 76 self.buffersize = self.reader.buffersize 77 ---> 78 self.make_frame = lambda t: self.reader.get_frame(t) 79 self.nchannels = self.reader.nchannels 80 /usr/local/lib/python3.6/dist-packages/moviepy/audio/io/readers.py in get_frame(self, tt) 200 # repeat the last frame instead 201 indices[indices>=len(self.buffer)] = len(self.buffer) -1
--> 202 result[in_time] = self.buffer[indices] 203 return result 204 IndexError: index -59041 is out of bounds for axis 0 with size 40960 

it seems to work when I don't set outtmpl option in ydl_opts and manually enter the name that ydl auto assigns to ffmpeg_extract_subclip

import matplotlib.pyplot as plt
%matplotlib inline
import moviepy.editor as mpy
!pip install youtube_dl
import youtube_dl ydl_opts = { 'format': 'bestaudio/best', 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'wav', 'preferredquality': '192', }],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl: ydl.download(['https://www.youtube.com/watch?v=5pIpVK3Gecg']) #Tyler, The Creator - 'IGOR,' Odd Future and Scoring a Number 1 Album _ Apple Music-5pIpVK3Gecg.wav is the name
#that youtube_dl auto assigns. I got it from the output of ydl.download command from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
ffmpeg_extract_subclip("Tyler, The Creator - 'IGOR,' Odd Future and Scoring a Number 1 Album _ Apple Music-5pIpVK3Gecg.wav", 170, 180, targetname="talk.wav") talk = mpy.AudioFileClip('talk.wav') sample_rate = talk.fps
NFFT = sample_rate /25
audio_data = talk.to_soundarray()
-- https://www.reddit.com/r/moviepy/comments/dwc27w/to_sound_array_issue/

subprocess.Popen() write stdout to logfile

$
0
0

I am using the following command to redirect ffmpeg output to terminal and text file.

p1 = subprocess.Popen (['ffmpeg', 'some_ffmpeg_command', '-f', 'mpegts', 'outfile.ts'], stdout=subprocess.PIPE, stderr=STDOUT, universal_newlines=True)
for line in p1.stdout: sys.stdout.write(line) logfile.write(line)
p1.stdout.close()
p1.wait()

The code works fine until a scenario where manual intervention is required. For example, if the file outfile.ts already exists, then the following dialogue is not displayed in console, File 'Desktop/mytestfolder/outfile.ts' already exists. Overwrite ? [y/N]

Any idea what's wrong with the above please?

Why image decoded by ffmpeg has a border?

$
0
0

After decoding some videos from iphone, I find the image has a strange border on the right.

It is not black but some random pix (width:4). why i get the border? how to cut this border or to turn it to black?

Most of videos dont have this problem.

enter image description here

here is the sample code: the code will load a video from memory, and decode it

int VideoParseFFmpeg::read_packet(void *opaque, uint8_t *buf, int buf_size) { struct buffer_data *bd = (struct buffer_data *) opaque; buf_size = FFMIN(buf_size, bd->size_); if (!buf_size) return AVERROR_EOF; memcpy(buf, bd->ptr_, buf_size); bd->ptr_ += buf_size; bd->size_ -= buf_size; return buf_size;
} int VideoParseFFmpeg::LoadContent(const std::string &video_content) { int ret = 0; ... video_size_ = video_content.size(); avio_ctx_buffer_size_ = video_size_ + AV_INPUT_BUFFER_PADDING_SIZE; avio_ctx_buffer_ = static_cast(av_malloc(avio_ctx_buffer_size_)); bd_.ptr_ = (uint8_t *)(video_content.c_str()); bd_.size_ = video_content.size(); av_register_all(); input_ctx_ = avformat_alloc_context(); avio_ctx_ = avio_alloc_context(avio_ctx_buffer_, avio_ctx_buffer_size_, 0, &bd_, &read_packet, NULL, NULL); if ((ret = av_probe_input_buffer(avio_ctx_, &in_fmt_, "", NULL, 0, 0)) < 0) { LOGGER_WARN(Log::GetLog(), "fail to prob input, err [{}]", AVERROR(ret)); return -1; } input_ctx_->pb = avio_ctx_; /* open the input file */ if ((ret = avformat_open_input(&input_ctx_, "", in_fmt_, NULL)) != 0) { LOGGER_WARN(Log::GetLog(), "fail to open input, err [{}]", AVERROR(ret)); return -1; } if ((ret = avformat_find_stream_info(input_ctx_, NULL)) < 0) { LOGGER_WARN(Log::GetLog(), "fail to find input stream information, err[{}]", AVERROR(ret)); return -1; } /* find the video stream information */ if ((ret = av_find_best_stream(input_ctx_, AVMEDIA_TYPE_VIDEO, -1, -1, &decoder_, 0)) < 0) { LOGGER_WARN(Log::GetLog(), "fail to find a video stream from input, err[{}]", ret); return -1; } video_stream_idx_ = ret; if (!(decoder_ctx_ = avcodec_alloc_context3(decoder_))) { LOGGER_WARN(Log::GetLog(), "fail to alloc avcodec context"); return -1; } video_stream_ = input_ctx_->streams[video_stream_idx_]; if ((ret = avcodec_parameters_to_context(decoder_ctx_, video_stream_->codecpar)) < 0) { LOGGER_WARN(Log::GetLog(), "fail to convert parameters to context, err [{}]", ret); return -1; } if ((ret = avcodec_open2(decoder_ctx_, decoder_, NULL)) < 0) { LOGGER_WARN(Log::GetLog(), "fail to open decodec, err[{}]", ret); return -1; } return 0;
} void VideoParseFFmpeg::GetFrames(std::vector&frames) { while (1) { ... decode_write(decoder_ctx_, &packet_, &buffer, frames); ... }
//flush
...
} cv::Mat VideoParseFFmpeg::avFrame2Mat(AVFrame *pAvFrame, AVCodecContext *pCodecCtx, AVPixelFormat src_fmt) { AVFrame *pFrameBGR = av_frame_alloc(); // 存储解码后转换的BGR数据 int w = pAvFrame->width; int h = pAvFrame->height; auto size = av_image_get_buffer_size(AV_PIX_FMT_BGR24, w, h, 1); cv::Mat out(h, w, CV_8UC3); int ret = av_image_fill_arrays(pFrameBGR->data, pFrameBGR->linesize, out.data, AV_PIX_FMT_BGR24, w, h, 1); img_convert_ctx_ = sws_getCachedContext(img_convert_ctx_, w, h, ConvertDeprecatedFormat(src_fmt), w, h, AV_PIX_FMT_BGR24, SWS_BICUBIC, NULL, NULL, NULL); sws_scale(img_convert_ctx_, (const uint8_t *const *) pAvFrame->data, pAvFrame->linesize, 0, pCodecCtx->height, pFrameBGR->data, pFrameBGR->linesize); av_free(pFrameBGR); return out;
} int VideoParseFFmpeg::decode_write(AVCodecContext *avctx, AVPacket *packet, uint8_t **buffer, std::vector&p_mat_out) { AVFrame *frame = NULL, *sw_frame = NULL; AVFrame *tmp_frame = NULL; int ret = 0; ret = avcodec_send_packet(avctx, packet); ... while (1) { auto clear = [&frame, &sw_frame, this] { if (frame != NULL) av_frame_free(&frame); if (sw_frame != NULL) av_frame_free(&sw_frame); av_packet_unref(&packet_); }; ... ret = avcodec_receive_frame(avctx, frame); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { clear(); return 0; } else if (ret < 0) { LOGGER_WARN(Log::GetLog(), "error while decoding, err[{}]", AVERROR(ret)); clear(); return ret; } tmp_frame = frame; p_mat_out.push_back(avFrame2Mat(tmp_frame, avctx, (AVPixelFormat) tmp_frame->format)); clear(); }
}

After replacing lib tcmalloc with a newer version, the border turns to be a black line (used to be a random line), like this.

enter image description here

-- enter image description here, enter image description here

Can I extract an audio clip (a single word) from the video and insert at different points/timeline of same video using FFMPEG/libvlcsharp?

$
0
0

I want to load a video that has a soundtrack, and I want it to take an audio clip of a single spoken word and I want the clip inserted at different points in the video. The output will be the new video. I also want to insert an image at certain points in the video (watermark).

Can I do this using FFMPEG or libvlcsharp?


How to build FFmpeg executable for commercial use using Windows?

$
0
0

I'm developing a commercial software and it requires ffmpeg.exe to run properly.

I'm aware of the FFmpeg legal page (https://www.ffmpeg.org/legal.html) and want to Compile FFmpeg without "--enable-gpl" and without "--enable-nonfree". However the compilation guide (https://trac.ffmpeg.org/wiki/CompilationGuide) seems neglected because some links lead to 404 pages, and some required programs didn't install properly on my PC, crashed in fact.

I tried all the ways to compile but could not succeed. I use Windows 8.1 and I'm not comfortable with minGW, MSYS, MSVC.

How can I compile FFmpeg executable for commercial use, or better, how can I download ffmpeg.exe (compiled for commercial use) without hassle?

-- https://www.ffmpeg.org/legal.html, https://trac.ffmpeg.org/wiki/CompilationGuide

How do I use ffmpeg to merge all audio streams (in a video file) into one audio channel?

$
0
0

I am attempting to use ffmpeg for a number of files. The actual number of audio streams (there is usually one channel per stream) per file isn't known until I'm using ffmpeg. The desired outcome is to somehow have ffmpeg get the count of audio channel, use the number in the command line to amerge those into one single audio channel. The goal is to create a preview version of the original video file for use in a simple HTML5 page. Is this possible in just one call to ffmpeg? (Also, apologies as some parts of this problem I'm still learning about)

Edit: Dumas stackoverflow asker here. Yes, I've been trying multiple combinations of ffmpeg args. To answer the other question, we have video files that have multiple streams, usually with single channels. I'll post some cmdline examples shortly.

This cmdline example kind of does what I want; there are 8 streams, and I'm able to combine all audio into one. THe issue is having to know the number before running ffmpeg:

ffmpeg -i EXAMPLE.MOV -filter_complex "[0:v]scale=-2:720,format=yuv420p[v];[0:a]amerge=inputs=8[a]" -map "[v]" -map "[a]" -c:v libx264 -crf 23 -preset medium -c:a libmp3lame -ar 44100 -ac 2 OUTPUT.mov

How to read realtime microphone audio volume in python and ffmpeg or similar

$
0
0

I'm trying to read, in near-realtime, the volume coming from the audio of a USB microphone in Python.

I have the pieces, but can't figure out how to put it together.

If I already have a .wav file, I can pretty simply read it using wavefile:

from wavefile import WaveReader with WaveReader("/Users/rmartin/audio.wav") as r: for data in r.read_iter(size=512): left_channel = data[0] volume = np.linalg.norm(left_channel) print volume

This works great, but I want to process the audio from the microphone in real-time, not from a file.

So my thought was to use something like ffmpeg to PIPE the real-time output into WaveReader, but my Byte knowledge is somewhat lacking.

import subprocess
import numpy as np command = ["/usr/local/bin/ffmpeg", '-f', 'avfoundation', '-i', ':2', '-t', '5', '-ar', '11025', '-ac', '1', '-acodec','aac', '-'] pipe = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=10**8)
stdout_data = pipe.stdout.read()
audio_array = np.fromstring(stdout_data, dtype="int16") print audio_array

That looks pretty, but it doesn't do much. It fails with a [NULL @ 0x7ff640016600] Unable to find a suitable output format for 'pipe:' error.

I assume this is a fairly simple thing to do given that I only need to check the audio for volume levels.

Anyone know how to accomplish this simply? FFMPEG isn't a requirement, but it does need to work on OSX & Linux.

Convert raw RGB32 file to JPEG or PNG using FFmpeg

$
0
0

Context

I used a C++ program to write raw bytes to a file (image.raw) in RGB32 format:

R G B A R G B A R G B A ...

and I want to be able to view it in some way. I have the dimensions of the image.

My tools are limited to command line commands (e.g. ffmpeg). I have visited the ffmpegwebsite for instructions, but it deals more with converting videos to images.


Questions

Is it possible to turn this file into a viewable file type (e.g. .jpeg, .png) using ffmpeg. If so, how would I do it?

If it's not possible, is there a way I can use another command?

It that's still not viable, is there any way I can manipulate the RGB32 bytes inside a C++ program to make it more suitable without the use of external libraries? I also don't want to encode .jpeg myself like this.

-- website

How to import FFmpeg files to Android project

lavu/log: Also print the log level for level trace.

$
0
0
lavu/log: Also print the log level for level trace.
  • [DH] libavutil/log.c

lavc/allcodecs: Add mpeg4 omx encoder, missed in 0e387232

$
0
0
lavc/allcodecs: Add mpeg4 omx encoder, missed in 0e387232
  • [DH] libavcodec/allcodecs.c

FFmpeg.AutoGen for converting MP3 already in memory to Wav

$
0
0

We are implementing a Web service, and the goal is to convert short (a few seconds) mp3 audios to WAV on the fly. The input mp3 content is a binary payload to the service. The speed of our web service is critical, so, saving and reading mp3 and wav from files (even with memory disk) are not an option.

It seems that all the functions provided in ffmpeg.autogen require either the filepath or url. Any suggestions that we could do the conversion for the mp3 content, which is already in memory?

BTW, we are aware of this post: How to convert wav file to mp3 in memory?, which uses NAudio, but we would like to try ffmpeg, for comparing the speed and some other purposes. Many thanks indeed.

Empty stream when cutting a video using ffmpeg

$
0
0

When I try cutting a video, it outputs an empty stream (262 byte video with 0s duration). Would appreciate any insight, thanks.

Command used: ffmpeg -i /path/to/long/video.mp4 -ss 37.69 -t 4.96 -c copy /path/to/short/video.mp4

However, when I the following (more inaccurate) command, it outputs a video. This video also has some problems, as the last frame is repeated several times, making the video one second longer (with a frozen image for one second).

ffmpeg -ss 37.69 -i /path/to/long/video.mp4 -t 4.96 -c copy /path/to/short/video.mp4

ffmpeg version: ffmpeg version 3.4.6-0ubuntu0.18.04.1

The outputs for the two commands are:

First command:

 built with gcc 7 (Ubuntu 7.3.0-16ubuntu3) configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared libavutil 55. 78.100 / 55. 78.100 libavcodec 57.107.100 / 57.107.100 libavformat 57. 83.100 / 57. 83.100 libavdevice 57. 10.100 / 57. 10.100 libavfilter 6.107.100 / 6.107.100 libavresample 3. 7. 0 / 3. 7. 0 libswscale 4. 8.100 / 4. 8.100 libswresample 2. 9.100 / 2. 9.100 libpostproc 54. 7.100 / 54. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/proj/vondrick/datasets/HowTo100M/video/Cars_&_Other_Vehicles/Motorcycles/52907/video_nVbIUDjzWY4.mp4': Metadata: major_brand : dash minor_version : 0 compatible_brands: iso6avc1mp41 creation_time : 2015-06-26T00:39:04.000000Z Duration: 00:07:14.40, start: 0.000000, bitrate: 244 kb/s Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 426x240 [SAR 1:1 DAR 71:40], 2 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default) Metadata: creation_time : 2015-06-26T00:39:04.000000Z handler_name : VideoHandler
Output #0, mp4, to '/proj/vondrick/datasets/HowTo100M/cropped_video/Cars_&_Other_Vehicles/Motorcycles/52907/nVbIUDjzWY4/video_000000_p.mp4': Metadata: major_brand : dash minor_version : 0 compatible_brands: iso6avc1mp41 encoder : Lavf57.83.100 Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 426x240 [SAR 1:1 DAR 71:40], q=2-31, 2 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc (default) Metadata: creation_time : 2015-06-26T00:39:04.000000Z handler_name : VideoHandler
Stream mapping: Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 0 fps=0.0 q=-1.0 Lsize= 0kB time=00:00:00.00 bitrate=N/A speed= 0x video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Second command:

ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 7 (Ubuntu 7.3.0-16ubuntu3) configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared libavutil 55. 78.100 / 55. 78.100 libavcodec 57.107.100 / 57.107.100 libavformat 57. 83.100 / 57. 83.100 libavdevice 57. 10.100 / 57. 10.100 libavfilter 6.107.100 / 6.107.100 libavresample 3. 7. 0 / 3. 7. 0 libswscale 4. 8.100 / 4. 8.100 libswresample 2. 9.100 / 2. 9.100 libpostproc 54. 7.100 / 54. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/proj/vondrick/datasets/HowTo100M/video/Cars_&_Other_Vehicles/Motorcycles/52907/video_nVbIUDjzWY4.mp4': Metadata: major_brand : dash minor_version : 0 compatible_brands: iso6avc1mp41 creation_time : 2015-06-26T00:39:04.000000Z Duration: 00:07:14.40, start: 0.000000, bitrate: 244 kb/s Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 426x240 [SAR 1:1 DAR 71:40], 2 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default) Metadata: creation_time : 2015-06-26T00:39:04.000000Z handler_name : VideoHandler
Output #0, mp4, to '/proj/vondrick/datasets/HowTo100M/cropped_video/Cars_&_Other_Vehicles/Motorcycles/52907/nVbIUDjzWY4/video_000000_3.mp4': Metadata: major_brand : dash minor_version : 0 compatible_brands: iso6avc1mp41 encoder : Lavf57.83.100 Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 426x240 [SAR 1:1 DAR 71:40], q=2-31, 2 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc (default) Metadata: creation_time : 2015-06-26T00:39:04.000000Z handler_name : VideoHandler
Stream mapping: Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 159 fps=0.0 q=-1.0 Lsize= 159kB time=00:00:04.95 bitrate= 263.0kbits/s speed=1.89e+03x video:158kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.909119%

Adding a border to ffmpeg video [ffmpeg-python]

$
0
0

I am making a xmas card and I need to embed the video inside a card on the right (inside the border) and have some text displayed on the left.

For simplicity, let's assume I have a box with a hole which is transparent. I would like to display the video inside that hole.

I am using ffmpeg-python and it would be great to see examples of how it can be achieved. It's also fine to post a native ffmpeg solution, although there are some example of that I believe already.

From what I understand, I need to always start with a master node e.g. the biggest node, and place the video inside the hole.

However, when I try something like:

import ffmpeg in_file = ffmpeg.input('video.mp4')
border_box = ffmpeg.input('box.png') ( ffmpeg.overlay( border_box, in_file, x=50, y=50 ) .output('out.mp4') .run()
)

It doesn't work. But vice versa, e.g. putting a border box inside the video doesn't work as it overlays borders of the video.

What I think needs to be done

  1. Create an infinite video from a static box.png
  2. Overlay, while scaling both streams appropriately
  3. Create output

Here is what I'm trying to achieve: enter image description here

The reason for transparency is because it's not actually a rectangle. I could place a video inside a heart shape etc.

-- enter image description here

node.js - Error: ENOENT: no such file or directory, unlink

$
0
0

I have the function below to convert a .wav file to .mp3. As you can see, before using the ffmpeg module to convert the audio file, I already check if the file exists or not, then upon conversion, I only keep the new file and delete the old one. But occasionally the console throws me the error Error: ENOENT: no such file or directory, unlink, which means that I unlink (delete) a non-existing file. I cannot understand why, because I already have an existence check even before the conversion, so it is supposed to have existed to be unlinked.

module.exports.convertAndMoveElastic = async (calllog) => { let { start, sip_uri, direction, source, destination } = calllog; const VNtimezoneOffset = 7 + new Date().getTimezoneOffset() / 60; const startTime = new Date(start + VNtimezoneOffset * 3600000 - 60000); const date = startTime.getDate() < 10 ? `0${startTime.getDate().toString()}` : startTime.getDate().toString(); const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; const month = months[startTime.getMonth()]; const year = startTime.getFullYear().toString(); sip_uri = sip_uri || (direction === 'outgoing' ? source : destination); const [extension, domain_name] = sip_uri.split("@"); return new Promise(async (resolve, reject) => { const links = await getLinkWithElastic(calllog); if (!links) { return reject(); } let file_id, filepath; for (let link of links) { const { callid, sipCallid, uuid, record_path } = link._source; if (record_path) { let recordPathArr = record_path.split('/'); file_id = recordPathArr[recordPathArr.length - 1].split('.')[0]; filepath = path.resolve(base_directory, domain_name, 'archive', year, month, date, `${file_id}.wav`); } if (!file_id || !fs.existsSync(filepath)) { file_id = callid; filepath = path.resolve(base_directory, domain_name, 'archive', year, month, date, `${file_id}.wav`); } if (!file_id || !fs.existsSync(filepath)) { file_id = uuid; filepath = path.resolve(base_directory, domain_name, 'archive', year, month, date, `${file_id}.wav`); } if (fs.existsSync(filepath)) { break; } } if (!fs.existsSync(filepath)) { return reject(); } ffmpeg(filepath) .audioCodec('libmp3lame') .on('error', function (error) { reject(error); }) .on('end', function () { resolve({ recordUrl: `${host}/record/download/${file_id}.mp3` }); fs.unlinkSync(filepath); }) .toFormat('mp3') .saveToFile(path.resolve(dest_directory, file_id + ".mp3")); });
};

Revision 119082: perf : éviter les js en squelette lorsque pas nécessaire (note en ...

$
0
0
perf : éviter les js en squelette lorsque pas nécessaire (note en passant : faudra aussi voir à supprimer ces tests sur affichage_final, c'est bien bouffeur -- Log
Viewing all 117718 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>