
Recherche avancée
Autres articles (37)
-
Les autorisations surchargées par les plugins
27 avril 2010, parMediaspip core
autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs -
MediaSPIP Player : problèmes potentiels
22 février 2011, parLe lecteur ne fonctionne pas sur Internet Explorer
Sur Internet Explorer (8 et 7 au moins), le plugin utilise le lecteur Flash flowplayer pour lire vidéos et son. Si le lecteur ne semble pas fonctionner, cela peut venir de la configuration du mod_deflate d’Apache.
Si dans la configuration de ce module Apache vous avez une ligne qui ressemble à la suivante, essayez de la supprimer ou de la commenter pour voir si le lecteur fonctionne correctement : /** * GeSHi (C) 2004 - 2007 Nigel McNie, (...) -
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 (...)
Sur d’autres sites (7257)
-
FFmpeg : unspecified pixel format when opening video with custom context
14 février 2021, par PedroI am trying to decode a video with a custom context. The purpose is that I want to decode the video directly from memory. In the following code, I am reading from file in the
read
function passed toavio_alloc_context
- but this is just for testing purposes.


I think I've read any post there is on Stackoverflow or on any other website related to this topic. At least I definitely tried my best to do so. While there is much in common, the details differ : people set different flags, some say
av_probe_input_format
is required, some say it isn't, etc. And for some reason nothing works for me.


My problem is that the pixel format is unspecified (see output below), which is why I run into problems later when calling
sws_getContext
. I checkedpFormatContext->streams[videoStreamIndex]->codec->pix_fmt
, and it is -1.


Please note my comments
// things I tried
and// seems not to help
in the code. I think, the answer might be hidden somehwere there. I tried many combinations of hints that I've read so far, but I am missing a detail I guess.


The problem is not the video file, because when I go the standard way and just call
avformat_open_input(&pFormatContext, pFilePath, NULL, NULL)
without a custom context, everything runs fine.


The code compiles and runs as is.



#include <libavformat></libavformat>avformat.h>
#include 
#include 

FILE *f;

static int read(void *opaque, uint8_t *buf, int buf_size) {
 if (feof(f)) return -1;
 return fread(buf, 1, buf_size, f);
}

int openVideo(const char *pFilePath) {
 const int bufferSize = 32768;
 int ret;

 av_register_all();

 f = fopen(pFilePath, "rb");
 uint8_t *pBuffer = (uint8_t *) av_malloc(bufferSize + AVPROBE_PADDING_SIZE);
 AVIOContext *pAVIOContext = avio_alloc_context(pBuffer, bufferSize, 0, NULL,
 &read, NULL, NULL);

 if (!f || !pBuffer || !pAVIOContext) {
 printf("error: open / alloc failed\n");
 // cleanup...
 return 1;
 }

 AVFormatContext *pFormatContext = avformat_alloc_context();
 pFormatContext->pb = pAVIOContext;

 const int readBytes = read(NULL, pBuffer, bufferSize);

 printf("readBytes = %i\n", readBytes);

 if (readBytes <= 0) {
 printf("error: read failed\n");
 // cleanup...
 return 2;
 }

 if (fseek(f, 0, SEEK_SET) != 0) {
 printf("error: fseek failed\n");
 // cleanup...
 return 3;
 }

 // required for av_probe_input_format
 memset(pBuffer + readBytes, 0, AVPROBE_PADDING_SIZE);

 AVProbeData probeData;
 probeData.buf = pBuffer;
 probeData.buf_size = readBytes;
 probeData.filename = "";
 probeData.mime_type = NULL;

 pFormatContext->iformat = av_probe_input_format(&probeData, 1);

 // things I tried:
 //pFormatContext->flags = AVFMT_FLAG_CUSTOM_IO;
 //pFormatContext->iformat->flags |= AVFMT_NOFILE;
 //pFormatContext->iformat->read_header = NULL;

 // seems not to help (therefore commented out here):
 AVDictionary *pDictionary = NULL;
 //av_dict_set(&pDictionary, "analyzeduration", "8000000", 0);
 //av_dict_set(&pDictionary, "probesize", "8000000", 0);

 if ((ret = avformat_open_input(&pFormatContext, "", NULL, &pDictionary)) < 0) {
 char buffer[4096];
 av_strerror(ret, buffer, sizeof(buffer));
 printf("error: avformat_open_input failed: %s\n", buffer);
 // cleanup...
 return 4;
 }

 printf("retrieving stream information...\n");

 if ((ret = avformat_find_stream_info(pFormatContext, NULL)) < 0) {
 char buffer[4096];
 av_strerror(ret, buffer, sizeof(buffer));
 printf("error: avformat_find_stream_info failed: %s\n", buffer);
 // cleanup...
 return 5;
 }

 printf("nb_streams = %i\n", pFormatContext->nb_streams);

 // further code...

 // cleanup...
 return 0;
}

int main() {
 openVideo("video.mp4");
 return 0;
}




This is the output that I get :

readBytes = 32768

retrieving stream information...

[mov,mp4,m4a,3gp,3g2,mj2 @ 0xdf8d20] stream 0, offset 0x30 : partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0xdf8d20] Could not find codec parameters for stream 0 (Video : h264 (avc1 / 0x31637661), none, 640x360, 351 kb/s) : unspecified pixel format

Consider increasing the value for the 'analyzeduration' and 'probesize' options

nb_streams = 2


UPDATE :

Thanks to WLGfx, here is the solution : The only thing that was missing was the seek function. Apparently, implementing it is mandatory for decoding. It is important to return the new offset - and not 0 in case of success (some solutions found in the web just return the return value of fseek, and that is wrong). Here is the minimal solution that made it work :


static int64_t seek(void *opaque, int64_t offset, int whence) {
 if (whence == SEEK_SET && fseek(f, offset, SEEK_SET) == 0) {
 return offset;
 }
 // handling AVSEEK_SIZE doesn't seem mandatory
 return -1;
}




Of course, the call to
avio_alloc_context
needs to be adapted accordingly :


AVIOContext *pAVIOContext = avio_alloc_context(pBuffer, bufferSize, 0, NULL,
 &read, NULL, &seek);



-
Rust Win32 FFI : User-mode data execution prevention (DEP) violation
28 avril 2022, par TheElixI'm trying to pass a ID3D11Device instance from Rust to a C FFI Library (FFMPEG).


I made this sample code :


pub fn create_d3d11_device(&mut self, device: &mut Box, context: &mut Box) {
 let av_device : Box<avbufferref> = self.alloc(HwDeviceType::D3d11va);
 unsafe {
 let device_context = Box::from_raw(av_device.data as *mut AVHWDeviceContext);
 let mut d3d11_device_context = Box::from_raw(device_context.hwctx as *mut AVD3D11VADeviceContext);
 d3d11_device_context.device = device.as_mut() as *mut _;
 d3d11_device_context.device_context = context.as_mut() as *mut _;
 let avp = Box::into_raw(av_device);
 av_hwdevice_ctx_init(avp);
 self.av_hwdevice = Some(Box::from_raw(avp));
 }
 }
</avbufferref>


On the Rust side the Device does work, but on the C side, when FFMEPG calls
ID3D11DeviceContext_QueryInterface
the app crashes with the following error :Exception 0xc0000005 encountered at address 0x7ff9fb99ad38: User-mode data execution prevention (DEP) violation at location 0x7ff9fb99ad38


The address is actually the pointer for the lpVtbl of QueryInterface, like seen here :


The disassembly of the address also looks correct (this is done on an another debugging session) :


(lldb) disassemble --start-address 0x00007ffffdf3ad38
 0x7ffffdf3ad38: addb %ah, 0x7ffffd(%rdi,%riz,8)
 0x7ffffdf3ad3f: addb %al, (%rax)
 0x7ffffdf3ad41: movabsl -0x591fffff80000219, %eax
 0x7ffffdf3ad4a: outl %eax, $0xfd



Do you have any pointer to debug this further ?


EDIT : I made a Minimal Reproducion Sample. Interestingly this does not causes a DEP Violation, but simply a Segfault.


On the C side :


int test_ffi(ID3D11Device *device){
 ID3D11DeviceContext *context;
 device->lpVtbl->GetImmediateContext(device, &context);
 if (!context) return 1;
 return 0;
}



On the Rust side :


unsafe fn main_rust(){
 let mut device = None;
 let mut device_context = None;
 let _ = match windows::Win32::Graphics::Direct3D11::D3D11CreateDevice(None, D3D_DRIVER_TYPE_HARDWARE, OtherHinstance::default(), D3D11_CREATE_DEVICE_DEBUG, &[], D3D11_SDK_VERSION, &mut device, std::ptr::null_mut(), &mut device_context) {
 Ok(e) => e,
 Err(e) => panic!("Creation Failed: {}", e)
 };
 let mut device = match device {
 Some(e) => e,
 None => panic!("Creation Failed2")
 };
 let mut f2 : ID3D11Device = transmute_copy(&device); //Transmuting the WinAPI into a bindgen ID3D11Device
 test_ffi(&mut f2);
}



The bindgen build.rs :


extern crate bindgen;

use std::env;
use std::path::PathBuf;

fn main() {
 // Tell cargo to tell rustc to link the system bzip2
 // shared library.
 println!("cargo:rustc-link-lib=ffi_demoLIB");
 println!("cargo:rustc-link-lib=d3d11");

 // Tell cargo to invalidate the built crate whenever the wrapper changes
 println!("cargo:rerun-if-changed=library.h");

 // The bindgen::Builder is the main entry point
 // to bindgen, and lets you build up options for
 // the resulting bindings.
 let bindings = bindgen::Builder::default()
 // The input header we would like to generate
 // bindings for.
 .header("library.h")
 // Tell cargo to invalidate the built crate whenever any of the
 // included header files changed.
 .parse_callbacks(Box::new(bindgen::CargoCallbacks))
 .blacklist_type("_IMAGE_TLS_DIRECTORY64")
 .blacklist_type("IMAGE_TLS_DIRECTORY64")
 .blacklist_type("PIMAGE_TLS_DIRECTORY64")
 .blacklist_type("IMAGE_TLS_DIRECTORY")
 .blacklist_type("PIMAGE_TLS_DIRECTORY")
 // Finish the builder and generate the bindings.
 .generate()
 // Unwrap the Result and panic on failure.
 .expect("Unable to generate bindings");

 // Write the bindings to the $OUT_DIR/bindings.rs file.
 let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
 bindings
 .write_to_file(out_path.join("bindings.rs"))
 .expect("Couldn't write bindings!");
}



The Complete Repo can be found over here : https://github.com/TheElixZammuto/demo-ffi


-
Streaming without Content-Length in response
29 août 2011, par kainI'm using Node.js, Express (and connect), and fluent-ffmpeg.
We want to stream audio files that are stored on Amazon S3 through http.
We have all working, except that we would like to add a feature, the on-the-fly conversion of the stream through ffmpeg.
This is working well, the problem is that some browsers checks in advance before actually getting the file.
Incoming requests containing the Range header, for which we reply with a 206 with all the info from S3, have a fundamental problem : we need to know in advance the content-length of the file.
We don't know that since it is going through ffmpeg.
One solution might be to write out the resulting content-length directly on S3 when storing the file (in a special header), but this means we have to go through the pain of having queues to encode after upload just to know the size for future requests.
It also means that if we change compressor or preset we have to go through all this over again, so it is not a viable solution.We also noticed big differencies in the way Chrome and Safari request the audio tag src, but this may be discussion for another topic.
Fact is that without a proper content-length header in response everything seems to break or browsers goes in an infinite loop or restart the stream at pleasure.
Ideas ?