How do I implement a DShow filter for reading specialized AVI file - filter

I'm trying to write DirectShow filter which will read file containts some xml-data at the beginning and avi video after it. I'm going open a file in the filter, skip the xml-data and begin the playback. I found in the Windows SDK the example which played BMP-file (Microsoft SDKs\Windows\v7.1\Samples\multimedia\directshow\filters\pushsource). Where can I spy out how do I read avi frames, convert ones and push it in an output pin?
Sorry for my English.

You can find AVI file specs here. But there is an easier solution: use standard AVI Splitter filter which is part of DirectShow. Just take another sample filter from SDK - Async and make it read your XML data and then act as a regular file source but reading data from your file with some shifted offset. This way all the parsing work will be done by AVI Splitter and all your filter needs to do is reading parts of file that Splitter requests.

Related

Concatenating Smooth Streaming output to a single MP4 file - problems with A/V sync. What is CodecPrivateData?

I have a video in fragmented form which is an output of an Azure Media Services Live Event (Smooth Streaming).
I'm trying to concatenate the segments to get a single MP4 file, however I've run into a A/V sync problem - no matter what I do (time-shifting/speeding up/slowing down/using FFmpeg filters), the audio delay is always floating. To get the output MP4 file, I tried concatenating the segments for video and audio streams (both at OS file level and with FFmpeg) and then muxing with FFmpeg.
I've tried everything I found on the web and I'm always ending up with exactly the same result. What's important, when I play the source from the manifest file, it's all good. That made me skim through the manifest once again, and I realized there's CodecPrivateData value which I'm not using anywhere in the process. What is it? Could it somehow help solving my problem?
Mystery solved: the manifest file contains the list of stream discontinuities, which need to be taken into account when concatenating the streams.

Is it possible to extract the dialogue in a video track using the subtitles track with ffmpeg?

I want to take a video file as an input and generate an output consisting of an audio track which would be a shorter version of the original audio track of the video where only the dialogue is output. I have the subtitles of the video in a separate file which I can use to extract the dialogue. Is this possible to do with ffmpeg?
It is possible, but not trivial. This assumes that the subtitles are timed perfectly with the dialog (unfortunately that is probably not true). This is a very broad question with few details given so I can only provide the general steps:
Get the timestamps from the subtitles. For example, use awk to process it into a usable form.
Use the retrieved timestamps to segment the audio. There are many methods you could use, but they may depend on the (currently unknown) format of your input streams. For example, you could use the timestamps in the atrim or aselect filters and join with the concat filter. Or use the inpoint/outpoint directives of the concat demuxer.

Save Live Video Stream To Local Storage

Problem:
I have to save live video streams data which come as an RTP packets from RTSP Server.
The data come in two formats : MPEG4 and h264.
I do not want to encode/decode input stream.
Just write to a file which is playable with proper codecs.
Any advice?
Best Wishes
History:
My Solutions and their problems:
Firt attempt: FFmpeg
I use FFmpeg libary to get audio and video rtp packets.
But in order to write packets i have to use av_write_frame :
which seems that decode /encode takes place.
Also, when i give output format as mp4 ( av_guess_format("mp4", NULL, NULL)
the output file is unplayable.
[ any way ffmpeg has bad doc. hard to find what is wrong]
Second attempth: DirectShow
Then i decide to use DirectShow. I found a RTSP Source Filter.
Then a Mux and File Writer.
Cretae Single graph:
RTSP Source --> MPEG MUX ---> File Writer
It worked but the problem is that the output file is not playable
if graph is not stoped. If something happens, graph crashed for example
the output file is not playable
Also i can able to write H264 data, but the video is completely unplayable.
The MP4 file format has an index that is required for correct playback, and the index can only be created once you've finished recording. So any solution using MP4 container files (and other indexed files) is going to suffer from the same problem. You need to stop the recording to finalise the file, or it will not be playable.
One solution that might help is to break the graph up into two parts, so that you can keep recording to a new file while stopping the current one. There's an example of this at www.gdcl.co.uk/gmfbridge.
If you try the GDCL MP4 multiplexor, and you are having problems with H264 streams, see the related question GDCL Mpeg-4 Multiplexor Problem

Convert to DV AVI Type-1 video

I'm working on a project that requires converting mpg,avi,wmv formats. A vendor requires the format to be in DV AVI Type 1. This is a format that Windows Movie Maker offers during capture off your camcorder.
I need this format for some vendor tools that assume that the user is capturing the data off the device, or that the import of an existing file is in this format.
I know of these 2 tools that do it, but I'm looking to incorporate a stand-alone library / command line interface so that I can wrap the encoding process in my own application.
http://paul.glagla.free.fr/dvdate_en.htm
http://www.stoik.com/products/video/STOIK-Video-Converter/
Last time I checked FFMPEG does NOT support this conversion... just the reverse from DV AVI1 to DV AVI2.
I've read through this resource, but don't know how this could be incorporated into ffmpeg
http://msdn.microsoft.com/en-us/library/dd388641(v=VS.85).aspx
Has anyone tried to convert from format X to DV AVI Type 1 ?
I'm a little unsure of the exact problem you're trying to solve. It sounds like you want to encode mpg,avi,wmv files into DV AVI type 1 and you want to use ffmpeg as part of the solution.
There are Microsoft DV Video Encoder and DV muxer DirectShow filters that will combine video and audio into the single video+audio DV stream needed for type 1 DV AVI.
http://msdn.microsoft.com/en-us/library/dd388645(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/dd388642(v=vs.85).aspx
I'm not very familiar with ffmpeg but I'm not sure why you need it for your particular problem. DirectShow can handle a wide variety of input formats. It seems from the FAQ that ffmpeg can get input from a DirectShow filter but not write data to a DirectShow filter.
It would be simplest to do the conversion with DirectShow alone without ffmpeg:
Create a DirectShow graph (CoCreateInstance getting IGraphBuilder).
Create a source filter from your input file (IGraphBuilder::AddSourceFilter)
Create a DV encoder filter (CoCreateInstance)
Add the DV encoder filter to the graph (IFilterGraph::AddFilter)
Connect the video source pin to the dv encoder (IGraphBuilder::Connect)
Then similarly:
Connect a new dv muxer to the output
of the dv video encoder and the audio
ouput from the source filter (you may
need an intermediate filter to
compress the audio into the right
format).
Connect the output of the dv
muxer to a new avi mux filter.
Connect the output of the avi mux to
a new file writer filter set up with
your destination file.
Run the graph using IMediaControl and IMediaEvents to convert your input file to your output file.
If I've misunderstood your question then you should be able to construct a different graph that will convert to or from DV AVI type 1 or 2. For writing type 2 you wouldn't need to use the dv muxer.
All of this can be easily tested in advance using GraphEdit or similar tools before writing any code. GraphEdit is available with the Windows SDK. GraphStudio is one open source alternative but there are others too. For development purposes you could also construct a graph in GraphEdit or similar and then load it and run it in your own test application (see http://msdn.microsoft.com/en-us/library/dd390649(v=vs.85).aspx)
For some basic getting started information see:
- The Wikipedia page on DirectShow
- How can I learn a DirectShow programming?
- Where can I find a thorough DirectShow tutorial?

File writer filter creating a bigger AVI file then original

I am using the SampleGrabber filter to get the frames of an AVI file and alter them before writing them to another (new) AVI file using the File writer filter.
The problem that I am facing is that the new AVI file size is greater then the original file. I removed the SampleGrabber filter thinking that it might be my code causing the problem, but still the new file size is greater then the original file. I tested it with graphedit.
The filters used were File reader->AVI Splitter->AVI Mux->File writer.
I really want to preserve the file size. Is there any other filter or property that I have to set. At the moment I am only adding the Filters in GraphBuilder and rendering the file.
I am using DirectShowLib.Net.
I just did a quick test using
File source (async) -> AVI splitter -> AVI mux -> file writer
in graphedit and the output file always seems to come out the same size as the input for me. The only thing I can think of is that your input file might be compressed. It might be worth inspecting the input file with an app like gspot to determine that. As I understand it DirectShow will sometimes insert appropriate filters in order to make a connection, so if you're trying to connect your file source to an AVI splitter it may insert a decompressor if needed. Hope that's of some use

Resources