/// <summary>
        /// Handles the Media.PacketRead event writing the packet to the output context.
        /// </summary>
        /// <param name="sender">the media element that sent this event.</param>
        /// <param name="e">The event arguments containing the packet data.</param>
        private void OnMediaPacketRead(object sender, PacketReadEventArgs e)
        {
            lock (SyncLock)
            {
                const AVRounding RoundingMode = AVRounding.AV_ROUND_NEAR_INF | AVRounding.AV_ROUND_PASS_MINMAX;

                if (HasClosed)
                {
                    return;
                }

                if (!HasInitialized)
                {
                    Initialize(e.InputContext);
                }

                var inputStreamIndex  = e.Packet->stream_index;
                var outputStreamIndex = StreamMappings[inputStreamIndex];

                var inputTimeBase  = e.InputContext->streams[inputStreamIndex]->time_base;
                var outputTimeBase = OutputContext->streams[outputStreamIndex]->time_base;

                var packet = ffmpeg.av_packet_clone(e.Packet);
                packet->stream_index = outputStreamIndex;
                packet->pos          = -1;
                packet->pts          = ffmpeg.av_rescale_q_rnd(packet->pts, inputTimeBase, outputTimeBase, RoundingMode);
                packet->dts          = ffmpeg.av_rescale_q_rnd(packet->dts, inputTimeBase, outputTimeBase, RoundingMode);
                packet->duration     = ffmpeg.av_rescale_q(packet->duration, inputTimeBase, outputTimeBase);

                ffmpeg.av_interleaved_write_frame(OutputContext, packet);
                ffmpeg.av_packet_unref(packet);
            }
        }
Ejemplo n.º 2
0
        public unsafe Remuxing(string inputFile)
        {
            string outputFile = Path.GetFileNameWithoutExtension(inputFile) + "_remuxing" + Path.GetExtension(inputFile);

            using (MediaReader reader = new MediaReader(inputFile))
                using (MediaWriter writer = new MediaWriter(outputFile))
                {
                    // add stream with reader's codec_id
                    for (int i = 0; i < reader.Count; i++)
                    {
                        writer.AddStream(reader[i], writer.Format.Flags);
                    }
                    writer.Initialize();

                    // read and write packet
                    foreach (var packet in reader.ReadPacket())
                    {
                        int        index       = packet.StreamIndex;
                        AVRounding rounding    = AVRounding.AV_ROUND_NEAR_INF | AVRounding.AV_ROUND_PASS_MINMAX;
                        AVRational inTimeBase  = reader[index].TimeBase;
                        AVRational outTimeBase = writer[index].TimeBase;
                        packet.Pts      = ffmpeg.av_rescale_q_rnd(packet.Pts, inTimeBase, outTimeBase, rounding);
                        packet.Dts      = ffmpeg.av_rescale_q_rnd(packet.Dts, inTimeBase, outTimeBase, rounding);
                        packet.Duration = ffmpeg.av_rescale_q(packet.Duration, inTimeBase, outTimeBase);
                        packet.Pos      = -1;
                        writer.WritePacket(packet);
                    }
                    writer.FlushMuxer();
                }
        }
Ejemplo n.º 3
0
public static extern System.Int64 av_rescale_rnd(
	[MarshalAs(UnmanagedType.I8)]
	System.Int64 a, 
	[MarshalAs(UnmanagedType.I8)]
	System.Int64 b, 
	[MarshalAs(UnmanagedType.I8)]
	System.Int64 c, 
	AVRounding  __arg3);
Ejemplo n.º 4
0
 public static extern System.Int64 av_rescale_rnd(
     [MarshalAs(UnmanagedType.I8)]
     System.Int64 a,
     [MarshalAs(UnmanagedType.I8)]
     System.Int64 b,
     [MarshalAs(UnmanagedType.I8)]
     System.Int64 c,
     AVRounding __arg3);
Ejemplo n.º 5
0
 public static extern long av_rescale_rnd(long a, long b, long c, AVRounding rnd);
Ejemplo n.º 6
0
 public static extern long av_rescale_q_rnd(long a, AVRational bq, AVRational cq, AVRounding p3);
Ejemplo n.º 7
0
 public static extern long av_rescale_rnd(long a, long b, long c, AVRounding rnd);
Ejemplo n.º 8
0
 public static extern long av_rescale_q_rnd(long a, AVRational bq, AVRational cq, AVRounding rnd);
Ejemplo n.º 9
0
public static extern System.Int64 av_rescale_q_rnd(
	[MarshalAs(UnmanagedType.I8)]
	System.Int64 a, 
	AVRational bq, 
	AVRational cq, 
	AVRounding  __arg3);
Ejemplo n.º 10
0
 public static extern System.Int64 av_rescale_q_rnd(
     [MarshalAs(UnmanagedType.I8)]
     System.Int64 a,
     AVRational bq,
     AVRational cq,
     AVRounding __arg3);