Recherche avancée

Médias (0)

Mot : - Tags -/longitude

Aucun média correspondant à vos critères n’est disponible sur le site.

Sur d’autres sites (1419)

  • Code runs when in a main method but not when in another method

    8 août 2018, par Zubair Ahmed

    I created the setArtwork method to set the artwork of an aac file in an .m4a container and it does exactly what I want it to when I run the main method

    public static void setArtwork(File art, File m4a) throws Exception{
       Mp4TagReader reader = new Mp4TagReader();
       Mp4TagWriter writer = new Mp4TagWriter();
       RandomAccessFile song = new RandomAccessFile(m4a.toString(),"rw");
       Mp4Tag mp4tag = reader.read(song);

       Artwork artwork = ArtworkFactory.createArtworkFromFile(art);
       mp4tag.addField(artwork);
       mp4tag.setField(artwork);

       RandomAccessFile temp = new RandomAccessFile(m4a,"rw");
       writer.write(mp4tag,song,temp);
    }
    public static void main(String[] args) throws Exception{
       File art = new File("C:\\Users\\Zubair\\Documents\\music\\coverArt.jpeg");
       File m4a = new File("C:\\Users\\Zubair\\Documents\\music\\song.m4a");
       setArtwork(art,m4a);
    }

    BUT, when I try to use the setArtwork method in a different method in a different class it doesn’t actually save the mp4 tag to the File. I did some debugging to see if the picture was even being added to the artwork tag and it all looks good, but it seems that the tag doesn’t get written to the file.

    public static void mp3Tom4a(File mp3File, File m4aFolder, File coverArt) throws Exception {
       String input = mp3File.toString();
       String name = mp3File.getName();

       String output = name.substring(0,name.indexOf(MP3)) + M4A;
       output = m4aFolder.toString() + "\\" + output;

       //cd ffmpeg\bin && ffmpeg -y -i input.mp3 -an -vcodec copy cover.jpg && ffmpeg -y -i input.mp3 -c:a aac -b:a 192k -vn output.m4a
       ProcessBuilder builder = new ProcessBuilder(
               "cmd.exe","/c","cd ffmpeg\\bin && ffmpeg -y -i "
               + input +" -an -vcodec copy "+coverArt+
               " && ffmpeg -y -i " + input + " -c:a aac -b:a 128k -vn " + output);
       builder.redirectErrorStream(true);
       builder.start();
       JAudioData.setArtwork(coverArt,new File(output));
    }
    public static void main(String[] args) throws Exception {
       mp3Tom4a(new File("C:\\Users\\Zubair\\Documents\\music\\song.mp3"),
               new File("C:\\Users\\Zubair\\Documents\\music"),
               new File("C:\\Users\\Zubair\\Documents\\music\\coverArt.jpeg"));
    }

    it doesn’t make sense that setArtwork only works when it’s in the main method of its own class, especially because the objects I am using for the parameters are identical to eachother, so there should be no difference in the result. I think it might have something to do with the RandomAccessFile object being updated but the physical storage not getting updated

    Edit- If I comment out builder.start() then it can successfully write the mp4tag to the m4a file. But I don’t see why having builder.start() would prevent that from happenning. My best guess is that because builder.start() is what creates song.m4a it is still being "edited" by that and can’t be edited by any other processes.

  • ffmpeg live stream transcoding. A/V sync issues on fast camera movement

    21 août 2020, par Kelsnare
      

    1. I create a webrtc peer connection with my server(only stun)
    2. 


    3. Using pion webrtc for the server
    4. 


    5. I write the received RTP packets as VP8 and opus streams, as described here, to two pipes (the writers ; created with os.Pipe() in golang)
    6. 


    7. The read ends of these two pipes are received by ffmpeg as inputs (via exec.Command.ExtraFiles) for transcoding using libx264 and aac into a single stream. The command :
    8. 


    


    ffmpeg -re -i pipe:3 -re -r pipe:4 -c:a aac -af aresample=48000 -c:v libx264 -x264-params keyint=48:min-keyint=24 -profile:v main -preset ultrafast -tune zerolatency -crf 20 -fflags genpts -avoid_negative_ts make_zero -vsync vfr -map 0:0,0:0 -map 1:0,0:0 -f matroska -strict -2 pipe:5


    


      

    1. The above command outputs to a pipe(:5) the read end of which is being taken as input by the following :
    2. 


    


    ffmpeg -hide_banner -y -re -i pipe:3 -sn -vf scale=-1:'min(ih,360)' -c:v libx264 -pix_fmt yuv420p -ca aac -b:a 128k -b:v 1400k -maxrate 1498k -bufsize 2100k -hls_time 1 -hls_playlist_type event -hls_base_url /workdir/streamID/360p -hls_segment_filename /workdir/streamID/360p/360_%%03d.ts -f hls /workdir/streamID/360p.m3u8


    


      

    1. This works fine as long as there are no movements of my webcam. The moment that happens the video speed suddenly increases for a split second and audio delay gets introduced. This delay keeps increasing each time I shake my webcam.
    2. 


    


    The first command in point 4 above - if written to a file separately will be absolutely fine, in terms of a/v sync, even with vigorous camera shaking. The weird audio delay is only when transcoding for hls output irrespective of whether I'm actually viewing it live or playing it back later.

    


    This is my first time working with ffmpeg/hls/webrtc - would be really helpful if I could be pointed in the correct direction at least to be able to debug this or even know why this happens. Any and all help is greatly appreciated

    


  • How can I create a write stream for res for a child_process.spawn method as it says cp.spawn().pipe(res) is not a method

    11 juin 2022, par niishaaant
    const express = require('express');
const router = express.Router();
const ytdl = require('ytdl-core');
const cp = require('child_process');
const ffmpeg = require('ffmpeg-static');

router.get('/', async (req, res) => {
    const { v, f, q } = req.query;
    if (!ytdl.validateID(v) && !ytdl.validateURL(v)) {
        return res
            .status(400)
            .json({ success: false, error: 'No valid YouTube Id!' });
    }
    try {
        let info = await ytdl.getInfo(v);

        //set format and title
        // const title = info.videoDetails.title;
        // res.setHeader('Content-disposition', contentDisposition(`${title}${f}`));

        //define audio and video stream seperately and download them
        const audio = ytdl(v, { quality: 'highestaudio' }).on(
            'progress',
            (_, downloaded, total) => {
                console.log({ downloaded, total });
            }
        );
        let format = ytdl.chooseFormat(info.formats, { quality: q });
        const video = ytdl(v, { format }).on('progress', (_, downloaded, total) => {
            console.log({ downloaded, total });
        });

        const ffmpegProcess = cp
            .spawn(
                ffmpeg,
                [
                    // Remove ffmpeg's console spamming
                    '-loglevel',
                    '8',
                    '-hide_banner',
                    // Redirect/Enable progress messages
                    '-progress',
                    'pipe:3',
                    // Set inputs
                    '-i',
                    'pipe:4',
                    '-i',
                    'pipe:5',
                    // Map audio & video from streams
                    '-map',
                    '0:a',
                    '-map',
                    '1:v',
                    // Keep encoding
                    '-c:v',
                    'copy',
                    // Define output file
                    `out.${f}`,
                ],
                {
                    windowsHide: true,
                    stdio: [
                        /* Standard: stdin, stdout, stderr */
                        'inherit',
                        'inherit',
                        'inherit',
                        /* Custom: pipe:3, pipe:4, pipe:5 */
                        'pipe',
                        'pipe',
                        'pipe',
                    ],
                }
            )
            .on('close', () => {
                console.log('done');
            });

        // Link streams
        // FFmpeg creates the transformer streams and we just have to insert / read data
        ffmpegProcess.stdio[3].on('data', (chunk) => {
            // Parse the param=value list returned by ffmpeg
            const lines = chunk.toString().trim().split('\n');
            const args = {};
            for (const l of lines) {
                const [key, value] = l.split('=');
                args[key.trim()] = value.trim();
            }
        });
        audio.pipe(ffmpegProcess.stdio[4]);
        video.pipe(ffmpegProcess.stdio[5]);
    } catch (error) {
        res.status(400);
        console.log('error ', error);
    }
});

module.exports = router;


    


    


    I am trying to create a youtube downloader app and this is the code for downloading a video using the ytdl and ffmpeg packages in an express route but i don't know how i can download the result (out.mp4) for the client. when I try to pipe it to res error occurs saying cp.spawn().pipe() is not a method.